Rotate around the Z axis before rotating around the Y axis

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
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Rotate around the Z axis before rotating around the Y axis

Post 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?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post 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.
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
Post Reply