Relative vs. Absolute rotation of a 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
hardgeus
Posts: 28
Joined: Tue May 23, 2006 12:55 am
Contact:

Relative vs. Absolute rotation of a node

Post by hardgeus »

I know this is a really basic question, and I have searched around assuming that it has been asked a million times, but I cannot find an answer to my specific problem. I simply want to rotate a node, but I do not want its rotation to be relative. My first attempt was:

Code: Select all

        vector3df obRotation = m_pNode->getRotation();
        obRotation.X = obRotation.X + x;
        obRotation.Y = obRotation.Y + y;
        obRotation.Z = obRotation.Z + z;
        m_pNode->setRotation( obRotation );
The problem with this is that all rotations were relative to the node's current rotation, and they were "cumulative" so to speak. I am using the keyboard to control rotation of the node (and it is not necessarily at the origin), and I want a particular key to rotate the node along an absolute axis. After digging through a few posts I tried this:

Code: Select all

        core::matrix4 m;
        m.makeIdentity();

        core::matrix4 r1;
        r1.setRotationDegrees(core::vector3df(0, m_roty, 0));
        core::matrix4 r2;
        r2.setRotationDegrees(core::vector3df(m_rotx, 0, 0));
        core::matrix4 r3;
        r3.setRotationDegrees(core::vector3df(0, 0, m_rotz));

        m *= r1;
        m *= r2;
        m *= r3;

        m_pNode->setRotation( m.getRotationDegrees() );
But this did the same thing as the earlier code.

From what I understand, the solution is to translate the node's orientation to the origin, rotate it around the origin, and then translate it back to the node's current position. I am not quite sure how I would go about this using the functions I see. I am certain that this is a no-brainer, but I just haven't been able to figure out the proper calls to make.
hardgeus
Posts: 28
Joined: Tue May 23, 2006 12:55 am
Contact:

Post by hardgeus »

To clarify, here is a picture describing the problem:

Image

The first rotation is along the Z axis by 90 degrees. This first rotation occurs as I would expect it. The second rotation is along the X axis by 90 degrees. What I *want* to happen is shown in the top right image. I want to to rotate 90 degrees along the world X axis, not along the node's local X axis, which is what's happening in Irrlicht and pictured at the bottom right.

(Ignore the blender axis display in the picture, I just did the example graphic in Blender to show a visual of what is happening)
Post Reply