Hi,
I am trying to rotate a scene node around "the 3d model's local axis" by keystroke. So obviously that has to be converted to the Euler rotation somehow.
I searched this forum and already found something with matrices but didn't understand anything with my rather basic math skills.
So how do I convert local rotation to Euler rotation?
rotation around local axis
Re: rotation around local axis
Probably there is some better way where I don't need X matrices, but following might work for what you want:
(for explanation: I rotate around each of the 3 axes on it's own and create a matrix describing each of those 3 rotations. When local is wanted I transform the 3 axes into the local coordinate system first. Then I merge the matrices again and multiply them by the original transformation which the node had).
Code: Select all
// oldRotation: the stuff you get from node->getRotation()
// rotationAngles - in degrees
// useLocalAxes - when true rotate object around it's own axes, otherwise rotated around global axes
// return euler angles to use in node->setRotation
irr::core::vector3df rotateAxesXYZToEuler(const irr::core::vector3df& oldRotation, const irr::core::vector3df& rotationAngles, bool useLocalAxes)
{
irr::core::matrix4 transformation;
transformation.setRotationDegrees(oldRotation);
irr::core::vector3df axisX(1,0,0), axisY(0,1,0), axisZ(0,0,1);
irr::core::matrix4 matRotX, matRotY, matRotZ;
if ( useLocalAxes )
{
transformation.rotateVect(axisX);
transformation.rotateVect(axisY);
transformation.rotateVect(axisZ);
}
matRotX.setRotationAxisRadians(rotationAngles.X*irr::core::DEGTORAD, axisX);
matRotY.setRotationAxisRadians(rotationAngles.Y*irr::core::DEGTORAD, axisY);
matRotZ.setRotationAxisRadians(rotationAngles.Z*irr::core::DEGTORAD, axisZ);
irr::core::matrix4 newTransform = matRotX * matRotY * matRotZ * transformation;
return newTransform.getRotationDegrees();
}
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: rotation around local axis
Thanks for the quick reply and the solution. It works perfectly