Relative vs. Absolute rotation of a node
Posted: Thu Apr 05, 2007 3:24 pm
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:
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:
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.
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 );
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() );
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.