rotation problem after a few local rotation

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
scriptr
Posts: 16
Joined: Wed Aug 12, 2009 12:14 pm

rotation problem after a few local rotation

Post by scriptr »

Hi,

Adding a rotation value to any axis of a scenenode is simple. I do that by the following way;

Code: Select all

irr::core::matrix4 m;
m.setRotationDegrees(node->getRotation());
irr::core::matrix4 n;
n.setRotationDegrees(rotation);
m *= n;
node->setRotation( m.getRotationDegrees() );
But, how I can set a nodes rotation to a specific angle. For example i want the scene node rotate to this values: vector3df(15,30,0)

I can just use node->setRotation() method, but i think, it doesn't work as it is supposed to do. Because, the local and world space get mixed after a few rotation call. So node rotates to another angle than i want.

How do you do that?
scriptr
Posts: 16
Joined: Wed Aug 12, 2009 12:14 pm

Post by scriptr »

Hi again,

I have found that, i needed to use quaternions. I can now rotate one axis like i wanted but i can not keep the current rotation. I read that i need to create a quaternion with current rotations, and multiply with the newly created rotation quaternion, but that doesn't work.

What could be wrong?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Maybe your understanding of the angles is wrong, you should note that Irrlicht uses Euler angles, applied in order z,y,x. Multiplication of quaternions should also work, but only if you have to correct quaternions. Also make sure that you understand the application of the rotation vector. It's called relative rotation, but it's not relative with respect to the previous rotation, but ot the parent's rotation.
scriptr
Posts: 16
Joined: Wed Aug 12, 2009 12:14 pm

Post by scriptr »

thanks hybrid,

I've managed to make multiplying work. Now, i am trying to rotating the axis vectors, which i use for method fromAngleAxis(), to make the node rotate in its local space. I will paste the code here when finished.
scriptr
Posts: 16
Joined: Wed Aug 12, 2009 12:14 pm

Post by scriptr »

unfortunately problem still exists. :shock:

i rotate the node around Y-AXIS 45 degrees. Everything is ok. And then i want to rotate the node around Z-AXIS 45 degrees. Now when i calculate the z unit vector; i get (1,0,1). (I don't use (0,0,1) vector because i want to rotate the node in its local space)

Then when i want to locally rotate the node around z-axis again, i calculate my z-unit vector and it is not (1,0,1) this time. Because the Y rotation (node->getRotation().Y) is not 45 any more.

Does the iscenenode holds these variables or is there any other method to correctly calculate the local z-unit vector?
Serg88
Posts: 30
Joined: Mon Oct 19, 2009 5:52 pm
Location: Moscow/Russia

Post by Serg88 »

scriptr wrote:unfortunately problem still exists. :shock:

i rotate the node around Y-AXIS 45 degrees. Everything is ok. And then i want to rotate the node around Z-AXIS 45 degrees. Now when i calculate the z unit vector; i get (1,0,1). (I don't use (0,0,1) vector because i want to rotate the node in its local space)

Then when i want to locally rotate the node around z-axis again, i calculate my z-unit vector and it is not (1,0,1) this time. Because the Y rotation (node->getRotation().Y) is not 45 any more.

Does the iscenenode holds these variables or is there any other method to correctly calculate the local z-unit vector?
can you show executable application?
are you use keys?

try to use
core::vector3df Rotation = obj->getRotation();
Rotation.Y += 45;
Rotation.Z +=45;
obj->setRotation(Rotation);
from Russia with love :))))
scriptr
Posts: 16
Joined: Wed Aug 12, 2009 12:14 pm

Post by scriptr »

thanks Serg88 but, that code doesn't rotate the node in its local space. What i am trying to do is far more different than that.
scriptr
Posts: 16
Joined: Wed Aug 12, 2009 12:14 pm

Post by scriptr »

come on guys, help please :|
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

Crazy guess, you aren't experiencing gimbal lock right?
Post Reply