Page 1 of 1

Rotate around the Z axis before rotating around the Y axis

Posted: Fri Apr 21, 2017 7:55 pm
by Donald Duck
I would like to rotate a mesh first 22.5°around the Z axis and then 90° around the Y axis. I tried this code:

Code: Select all

mesh->setRotation(irr::core::vector3df(0.0f, 90.0f, 22.5f));
The problem is that this rotates first around the Y axis and then around the Z axis, which is, if I'm not wrong, the same thing as rotating first 22.5°around the X axis and then 90° around the Y axis. So I tried this code:

Code: Select all

mesh->setRotation(irr::core::vector3df(22.5f, 90.0f, 0.0f));
But this rotates first around the X axis and then around the Z axis, giving a similar effect. It seems like the setRotation method rotates the mesh first around the X axis, then the Y axis, then the Z axis. So how can I achieve what I want to do?

Re: Rotate around the Z axis before rotating around the Y ax

Posted: Sat Apr 22, 2017 9:49 am
by CuteAlien
If you really want to change the rotation order you will have to write your own scenenode which overrides getRelativeTransformation and you have to do the calculations yourself as matrix4::setRotation uses x,y,z rotation order.

One slightly simpler (but more expensive) workaround would be to do the calculations with some independent matrices. So one matrix for rotation around x and one for rotation around z. Then you multiply the 2 matrices - and that's where you can decide the multiplication order by putting matrix x or z as first operant of the multiplication. Then you use matrix.getRotation() result as values for the node->setRotation.