How do I set the order axis are rotated in a matrix?

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
n00bc0de
Posts: 38
Joined: Tue Oct 04, 2022 1:21 am

How do I set the order axis are rotated in a matrix?

Post by n00bc0de »

I have been working on a loader for anim8or and I am having issues getting the vertices to transform correctly. I have joints set up for a skinned mesh and all the vertices are set correctly if I only rotate 1 axis. The issue happens if I rotate more than 1 axis on the bones on my model, the transformation is way off.

I wanted to know if there is a way to construct a matrix where I can set the rotation for each axis to happen in Z,X,Y order ( I manually tested this rotation order and it does match the results animator gets).
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How do I set the order axis are rotated in a matrix?

Post by CuteAlien »

You can construct 3 matrices - one per axis - and then multiply them to get your final matrix. The order of multiplication you use there is then the order of operations.

Otherwise you probably have to write your own tool function. Unless setInverseRotationDegrees works? I never tried what that one does exactly... but sounds a bit like it? Or maybe that one in combination with passing negative rotation values? Worth a shot before writing your own tool function :-)
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
n00bc0de
Posts: 38
Joined: Tue Oct 04, 2022 1:21 am

Re: How do I set the order axis are rotated in a matrix?

Post by n00bc0de »

I tried creating multiple matrices but I must be doing something wrong.

Here is a basic example with 1 vertex.

Lets say I have the vertex (-6.92924, 4.15756, 18.672) and a rotation vector(-45,22,-42).

The result anim8or produces is (-5.08, 18.66, 6.29).


Here is a matrix setup which produces the wrong result:

Code: Select all

core::vector3df v(-6.92924, 4.15756, 18.672);
core::matrix4 m;
m.setRotationDegrees(core::vector3df(-45,22,-42));
m.transformVect(v)

This code produces the correct result:

Code: Select all

core::vector3df v(-6.92924, 4.15756, 18.672);
v.rotateXYBy(-42.085);
v.rotateYZBy(-45);
v.rotateXZBy(22);

I can't seem to get the matrix on my joints to produce the same results.
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How do I set the order axis are rotated in a matrix?

Post by CuteAlien »

There is some confusion in Irrlicht which I found and documented just very recently: rotateXZBy is using a right-handed rotation unlike all other rotate By functions which are left handed :-(
So that one needs a minus.
So to get the same with matrices you would have to use -22, like:

Code: Select all

        core::vector3df v2(-6.92924, 4.15756, 18.672);
	core::matrix4 m1, m2, m3;
	m1.setRotationDegrees(core::vector3df(0, 0, -42.085));
	m2.setRotationDegrees(core::vector3df(-45, 0, 0));
	m3.setRotationDegrees(core::vector3df(0,-22,0));
	core::matrix4 m;
	m = m3*m2*m1;
	m.transformVect(v2);
Note that anim8or uses a right-handed coordinate system unlike Irrlicht which is left-handed. This doesn't matter for rotations, but for vectors you have to consider how to handle those (I think anim8or has y up like Irrlicht, so easiest is to switch z of vectors to -z).
For rotations it matters if rotation is left or right handed (doesn't have to be same as coordinate system). I couldn't find out on a quick view what anim8or is using (maybe try in the program). Aside from the mentioned evil rotateXZBy function Irrlicht uses left-handed rotations throughout the code. So if anim8or is right-handed you'll have to use the negative value for all rotations. And lastly obviously axis order matters, but you should only start on that if it's not working yet after those 2 things.
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
n00bc0de
Posts: 38
Joined: Tue Oct 04, 2022 1:21 am

Re: How do I set the order axis are rotated in a matrix?

Post by n00bc0de »

Thanks for the answer. It was so close to working and I spent a few days trying to solve that simple issue. I know most people are using blender for animated meshes but I will still post my anim8or loader for those interested in using anim8or with irrlicht.
Post Reply