Page 1 of 2

Rotating engine nacelles with pitch

Posted: Thu Jun 19, 2014 10:05 pm
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

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 2:50 am
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.

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 5:49 am
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...

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 7:55 am
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

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 8:41 am
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!

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 9:31 am
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

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 9:39 am
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.

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 9:56 am
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.

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 9:56 am
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.

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 10:17 am
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.

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 11:25 am
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

}

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 12:10 pm
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.

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 2:51 pm
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!

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 7:07 pm
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).

Re: Rotating engine nacelles with pitch

Posted: Fri Jun 20, 2014 7:10 pm
by Cody
Thargoid wrote:
... if you survive the battle with the quaternions without your brain turning to evil juice.
<sniggers> Doctor, my brain hurts!