Rotating engine nacelles with pitch

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

daveangel
Average
Average
Posts: 15
Joined: Thu Jun 19, 2014 9:52 pm

Rotating engine nacelles with pitch

Post by daveangel »

Hello

My first post on here, i've been playing with my first OXP, which is a ship thats supposed to be a fast frigate/blockade runner etc.

With a nod to the 'starbridge' (and also the neolite fer-de-lance for looks) I wanted to rotate the engines, which i have made as separate sub entities as the ship pitches and yaws, which would account for a very manoeuvrable able ship despite its size.

Image

Any idea how i could rotate the sub entities as the ship yaws and pitches, is this even possible in oolite? I've included the wings files in the oxp should anybody else want to play, i've yet to texture the ship and the stats are waaayy to uber at the moment as i'm still building.

http://www.filedropper.com/dawnshipoxp

Thanks,

Dave
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6311
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Re: Rotating engine nacelles with pitch

Post by Diziet Sma »

G'day, and welcome aboard, daveangel! 8)

That's quite an intro, for your first post.. you've been well and truly bitten by the Darkside, eh? :lol:

Interesting idea you have for the engines, and a nice looking ship, too..

I'm afraid I can't help with your rotation question, but I'd imagine it's just a question of applying the correct math to it.. hopefully some of our clever boffins will be along soon to help out.
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Rotating engine nacelles with pitch

Post by cim »

How comfortable are you with quaternions? (If the answer is not very, don't worry, no-one else understands them either)

At a high level, what you need to do is:
- set a (Javascript) ship script on the ship
- have that script, when the ship is spawned, start a frame callback (a short piece of code which runs every frame)
- the frame callback then reads the 'roll', 'pitch' and 'yaw' parameters of the ship to get its current turn rates, and writes appropriate values to the 'orientation' parameter of each engine subentity.

The Quaternion rotate function is the easiest way to get a quaternion for a rotation around an arbitrary vector. For subentities, the identity quaternion [1,0,0,0] aligns the subentity to the ship's standard XYZ axes. So, to do the pitch up and down in your right-hand screenshot, you'd want to rotate their orientation quaternion around their X axis.

In this case, probably easiest is to have the frame callback reset the orientation to [1,0,0,0] at the start of its run, and then apply the correct series of rotations for the turn rate as it goes, rather than trying to incrementally adjust the orientation a frame at a time.

Good luck...
daveangel
Average
Average
Posts: 15
Joined: Thu Jun 19, 2014 9:52 pm

Re: Rotating engine nacelles with pitch

Post by daveangel »

Thanks Cim.

Do you know of any other ships that use addFrameCallBack so i can find an example?

Then i just need to work out how to reference the subentity.

Kind regards,

Dave
milinks
Deadly
Deadly
Posts: 164
Joined: Sun Jun 27, 2004 9:19 pm

Re: Rotating engine nacelles with pitch

Post by milinks »

That looks soo cool :) reminds me a bit of the ship from phantom menace, the silver sleek machine.... or maybe not, possibly :) Years ago maybe 8 or 9 years ago i made a station a sirf station (cant remember what the initials stand for now) where the subentities revolved within and around the static structure, but obviously that obviously didnt involve frame callacks etc, (as i'm way to thick) but the engine concept is an amazing idea, and hope to see it flying soon!
daveangel
Average
Average
Posts: 15
Joined: Thu Jun 19, 2014 9:52 pm

Re: Rotating engine nacelles with pitch

Post by daveangel »

I seam to have hit a hurdle almost immediately, can anyone tell my what illegal character i have at line 1 as the java console tells me, or is this a red herring and there is another problem

Code: Select all

this.name        = “Dawn”; 
this.author      = “Dave Adcock”; 
this.copyright   = "� 2014 Dave Adcock.”; 
this.description = “Rotate nacelles with pitch for vectored thrust.”; 
this.version     = “1.0”; 

this.shipLaunchedFromStation = function(station)
{
	// Initialise frame callback
	this.callbackID = addFrameCallback(this.moveEngines.bind(this));
	this.QPort = new Quaternion([1,0,0,0]);
	this.QStarboard = new Quaternion([0,0,0,1]);
}

this.shipSpawned = function ()
{
    // Add launcher for AI
}

this.shipDied = function ()
{
    // release callback
}

this.moveEngines = function()
{
	
	//Set Nacelles
	//Port 
	this.ship.subEntities[0].orientation = this.QPort;
	//Starboard
	this.ship.subEntities[1].orientation = this.QStarboard;
}

this.shipDockedWithStation = function(station)
{
     // remove callback
}

Thanks,

Dave
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6671
Joined: Wed Feb 28, 2007 7:54 am

Re: Rotating engine nacelles with pitch

Post by another_commander »

Probably it is a file encoding issue. Is the file UTF-8, ANSI encoded or other? I think most files in Oolite are UTF-8 without Byte Order Mark encoded.

Also, if you are on Windows and are using Notepad, you should switch to another text editor. Notepad is known to cause problems with the Oolite text files.
User avatar
Disembodied
Jedi Spam Assassin
Jedi Spam Assassin
Posts: 6885
Joined: Thu Jul 12, 2007 10:54 pm
Location: Carter's Snort

Re: Rotating engine nacelles with pitch

Post by Disembodied »

daveangel wrote:

Code: Select all

this.copyright   = "� 2014 Dave Adcock.”;
Copyright symbol looks like it's not displaying properly ... whether this is the problem or just a symptom, I don't know.
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6311
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Re: Rotating engine nacelles with pitch

Post by Diziet Sma »

another_commander wrote:
Probably it is a file encoding issue. Is the file UTF-8, ANSI encoded or other? I think most files in Oolite are UTF-8 without Byte Order Mark encoded.

Also, if you are on Windows and are using Notepad, you should switch to another text editor. Notepad is known to cause problems with the Oolite text files.
Notepad++ is what we usually recommend for Windows users.
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
daveangel
Average
Average
Posts: 15
Joined: Thu Jun 19, 2014 9:52 pm

Re: Rotating engine nacelles with pitch

Post by daveangel »

OK, it defiantly was an encoding problem, really weird though because i had to completely start again in text wrangler - no copy and pasting - i must of had a character hidden somewhere!

Thanks for the help.
daveangel
Average
Average
Posts: 15
Joined: Thu Jun 19, 2014 9:52 pm

Re: Rotating engine nacelles with pitch

Post by daveangel »

OK, really making progress now.

Just need to change the location on where the engines rotate on and then move the exhaust plume

Code: Select all

this.name 			= "Dawn";
this.author 		= "Dave Angel";
this.copyright 		= "2014 Dave Angel"
this.description	= "rotate engine nacelles with pitch for vectored thrust";
this.version		= 1.0;

this.shipLaunchedFromStation = function(station)
{
	//initialise frame callback
	this.callbackID = addFrameCallback(this.moveEngines.bind(this));
	this.QPort = new Quaternion([1,0,0,0]);
	this.QStarboard = new Quaternion([1,0,0,0]);
	this.percentPitch = 0.0;
	this.percentRoll = 0.0;
	this.rotationPort = 0.0;
	this.rotationStarboard = 0.0;
}

this.shipSpawned = function()
{
	//Place holder for AI initialisation
}

this.moveEngines = function()
{
	//Get Pitch and Roll
	this.percentPitch = (player.ship.pitch/player.ship.maxPitch);
	this.percentRoll = (player.ship.roll/player.ship.maxRoll);
	
	if (this.percentPitch != 0)
	{
		this.rotationPort = (this.percentPitch);
		this.rotationStarboard = (this.percentPitch);
	}

	if (this.percentRoll!= 0)
	{
		this.rotationPort = (this.percentRoll*-1);
		this.rotationStarboard = (this.percentRoll);
	}

	//Set nacelles
	//Port
	this.ship.subEntities[0].orientation = this.QPort.rotateX(this.rotationPort);
	//Starboard
	this.ship.subEntities[1].orientation = this.QStarboard.rotateX(this.rotationStarboard);
}

this.shipDockedWithStation = function(station)
{
	//Place holder to remove callback

}
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Rotating engine nacelles with pitch

Post by Norby »

Hi daveangel and welcome here!
Very promising first posts. :)

I suggest to play with Quaternion calculator to see the logic behind the numbers (thanks to the author, I found it in a signature in this forum).

I am using rotations in [wiki]ReverseControl[/wiki] OXP, maybe the code will be useful.
User avatar
ClymAngus
---- E L I T E ----
---- E L I T E ----
Posts: 2514
Joined: Tue Jul 08, 2008 12:31 am
Location: London England
Contact:

Re: Rotating engine nacelles with pitch

Post by ClymAngus »

Ah! The Starbridge! Yes I kind of ripped that off to to make the kirin...

Image

I like where your going with this however!
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Rotating engine nacelles with pitch

Post by Thargoid »

Just also be aware that the exhaust plumes aren't visible to JS in 1.77.1, but if I understand things correctly they will be available as special sub-entities in 1.80 when it's released.

So you may need to hang on a little while until it's fully released for a general release of the ship for people who aren't working with trunk. But aside from that it's looking good, you seem to have things in hand (if you survive the battle with the quaternions without your brain turning to evil juice).
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Rotating engine nacelles with pitch

Post by Cody »

Thargoid wrote:
... if you survive the battle with the quaternions without your brain turning to evil juice.
<sniggers> Doctor, my brain hurts!
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
Post Reply