Help with matrix, is this a bug ?

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
Default User
Posts: 8
Joined: Wed Sep 12, 2012 7:05 pm
Location: Saquarema, Brasil

Help with matrix, is this a bug ?

Post by Default User »

Code: Select all

 
core::vector3df rot;
core::matrix4 m;
rot = m.getRotationDegrees();
cout<<"rot0:"<<rot.X<<", "<<rot.Y<<", "<<rot.Z<<endl;
m.setRotationDegrees(core::vector3df(0,180,0));
rot = m.getRotationDegrees();
cout<<"rot1:"<<rot.X<<", "<<rot.Y<<", "<<rot.Z<<endl;
core::vector3df rotY(0,90,0);
m.rotateVect(rotY);
cout<<"rot2:"<<rotY.X<<", "<<rotY.Y<<", "<<rotY.Z<<endl;
 
console:

Code: Select all

 
rot0:0, -0, 0
rot1:180, 360, 180
rot2:-0, 90, 0
 
Is this a possible bug or am I doing something wrong ?
why "rot1:180, 360, 180" and not 0,180,0?
and why not "rot2:0,270,0" ? how can I make it rotate to 270, by moving more 90º from 180º using matrix ?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Help with matrix, is this a bug ?

Post by hybrid »

The rot1 looks the same as 0,180,0, so basically the effect is the same. There are several rotations doing the same. And the vector rotated is the same again, as you have a y-up vector, and rotate around y. This will not change the vector to anything. If you want to turn your up-vector down, you have to rotate around x or z.
Default User
Posts: 8
Joined: Wed Sep 12, 2012 7:05 pm
Location: Saquarema, Brasil

Re: Help with matrix, is this a bug ?

Post by Default User »

let me understand:
Node->setRotation(core::vector3df(0,180,0));
means:
rotate the mesh 0 degrees on X axis,
then rotate the mesh 180 degrees on Y axis,
then rotate the mesh 0 degrees on Z axis
in this order, right ?
Another thing on the matrix, why the "get" doesn't give me the same vector3 that I "set"?
What I expected as output:

Code: Select all

 
rot0:0, 0, 0
rot1:0, 180, 0
rot2:0, 270, 0
 
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Help with matrix, is this a bug ?

Post by hybrid »

Yes, your interpretation of the euler vector is correct, although the order of application is z/y/x IIRC. So for the results, rot0 is obviously correct, even though it's -0. That's just a minor rounding error. rot1 is also correct, as the resulting rotation does the same as your original one. The reason for the change is that the rotation is read back from the transformation matrix. And since there are these many ways to express the same rotation, only one of those is returned. The only important thing is that the rotation performs the same operation after all. And for the third result, you still seem to misinterpret things. rot2 is a vector, not a rotation. At least when you use it in rotateVect. So it's a vector pointing straight up in Irrlicht coords. Now you want to turn this vector around the y-axis, which won't change anything. If you, instead, use 1,0,0 as vector rot2, you should get 0,0,1 as result. The vector would be turned 90° clock-wise on the x/z plane.
Post Reply