[SOLVED]Rotate an already rotated node

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
MasterKira
Posts: 11
Joined: Mon Feb 07, 2011 7:40 am

[SOLVED]Rotate an already rotated node

Post by MasterKira »

I have a trouble and i hope to receive an help. Sorry if the solution is posted somewhere but it run away from my searches!

Actually I have a airplane/ship flying.

Everything (for example movement following ship's direction) works ...except rotation.
I've tried:
irr::core::vector3df rotation_init; // <- the actual rotation of node with this code:
rotation_init = node.getRotation();

//rotation.X,Y,Z are the rotation of the node at the end
rotation.Y = rotation_init.Y + diffY; // YAW AXIS
rotation.Z = rotation_init.Z + diffZ; // PITCH AXIS
rotation.X = rotation_init.X + diffX; // ROLL AXIS
Image

But not works, exactly works for the Y-axis (Yaw) around rotation, and X-axis (Roll) around rotation... but
Z Rotation (Pitching) work only if Roll Axis is parallel to Global X axis.
If Roll Axis is parallel to Global Z axis, the Z Rotation instead of Pitching, it Rolls too! And i don't understand why...

So i've tried a "solution" code (found in a thread in forum http://irrlicht.sourceforge.net/forum/v ... php?t=4680) about turn roll and pitch:
void rotate(irr::scene::ISceneNode *node, irr::core::vector3df rot) //rot = the rotation to add
{
irr::core::matrix4 m;
m.setRotationDegrees(node->getRotation());
irr::core::matrix4 n;
n.setRotationDegrees(rot);
m *= n;
node->setRotation( m.getRotationDegrees() );
}
But not works! When rotating the ship around Y axis (or around Yaw Axis), it makes strange things like rotation around other axis
So actually my code (the first one) is the better working except for that error. Like the graphic engine use global axis instead of considering rotation around object's axis.

Any idea?
-----------------
EDIT: The solution is:

Create an EmptySceneNode for each rotation, then parent them in the order you want to rotate. For example:
1-Yaw
2-Pitch
3-Roll
So the roll effect doesn't influence the other 2, and we use the first 2 like "spherical coordinates" or Elevation/Rotation.. and third, Roll, effect only himself.
Last edited by MasterKira on Mon Feb 06, 2012 12:35 pm, edited 1 time in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Rotate an already rotated node

Post by mongoose7 »

I don't understand. Z should be roll, Y yaw and X pitch.
MasterKira
Posts: 11
Joined: Mon Feb 07, 2011 7:40 am

Re: Rotate an already rotated node

Post by MasterKira »

Y- YAW AXIS
Z - PITCH AXIS
X - ROLL AXIS
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Rotate an already rotated node

Post by mongoose7 »

Maybe you don't understand. You must set the axes in the manner I described or nobody can help you.

To put it another way, you cannot use Irrlicht's Tait-Bryan angles.

To put it yet another way, you will have to use matrices or quaternions, and you will have to work them out for yourself, because nobody else uses your system.
MasterKira
Posts: 11
Joined: Mon Feb 07, 2011 7:40 am

Re: Rotate an already rotated node

Post by MasterKira »

I ve tried to change the rotation axis... nothing resolved...
trie to exchange X with Z (with all code modifications) but no solution...

i spent so many hours, and i read something about gimbal lock... maybe is this the case?

quaternions, i never used them, how to use? can you help me please?
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Rotate an already rotated node

Post by smso »

See if these snippets post by me helps:

http://irrlicht.sourceforge.net/forum/v ... =9&t=45698

Regards from smso
MasterKira
Posts: 11
Joined: Mon Feb 07, 2011 7:40 am

Re: Rotate an already rotated node

Post by MasterKira »

thanks smso, these code helps... expecially the giving new priority in rotation by making EmptySceneNodes for rotations.
After created all rotation simply parent them all and in 5-6 lines of code all is resolved.

Thank you :D
Post Reply