Page 1 of 1

[fixed]matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 8:15 am
by WWebber
Why does this fail?

Code: Select all

 
float mat1f[] = {1,0,0,0,  0,-1,0,0,  0,0,-1,0,  0,0,0,0 };
core::matrix4 mat1;
for (int i=0; i<16; i++)
  mat1[i]=mat1f[i];
core::vector3df rot1 = mat1.getRotationDegrees( );
 
I would expect somewhere 180 degrees?!

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 9:48 am
by CuteAlien
I don't know what results you get. I get:
rot1 {X=180.00000 Y=-0.00000000 Z=0.00000000 }

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 12:26 pm
by WWebber
I'm getting: { -0, -0, 0 }

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 1:39 pm
by CuteAlien
Interesting. Can you please give me the exact platform on which you are testing? Compiler, OS, debug/release, 32-bit/64-bit.

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 1:57 pm
by WWebber
RAD Studio 2010, Win7x64, debug, 32bit, no fast math
Stepping through the code of inline core::vector3d<T> CMatrix4<T>::getRotationDegrees() const

Code: Select all

 
                if (!core::iszero(C))
                {
                        const f64 invC = core::reciprocal(C);
                        rotx = mat[10] * invC * invScale.Z;
                        roty = mat[6] * invC * invScale.Y;
                        X = atan2( roty, rotx ) * RADTODEG64;
 
does atan2(0,1) and therefore the x-angle is 0

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 2:17 pm
by CuteAlien
Here atan2(0,-1) => 180. mat[10] is -1, invC is 1 and invScale.Z is 1.

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 2:56 pm
by WWebber
so the problem is invScale.. just debugging..

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 3:02 pm
by CuteAlien
Ah.. Irrlicht version. Seems there was something fixed in trunk, but it never got backported to Irrlicht 1.7.

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 3:03 pm
by WWebber
hmm. when a matrix holds
1 0 0
0 -1 0
0 0 -1
then I expect scale to be {1,-1,-1}
invScale is then the same and invScale.Z is then -1 and not +1..

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 3:05 pm
by CuteAlien
Yeah, it got fixed, just not in 1.7.3 - don't know why.

edit: This was when it was found last time: http://irrlicht.sourceforge.net/forum/v ... =7&t=39722
Not sure if there's anything that speaks against backporting that bugfix, I guess it wasn't done last time because it would mess up existing projects out there expecting wrong results for this already.
So only solution right now - either switch to svn trunk or modify local header by adding the following after getScale():

Code: Select all

 
                // we need to check for negative scale on to axes, which would bring up wrong results
                if (scale.Y<0 && scale.Z<0)
                {
                        scale.Y =-scale.Y;
                        scale.Z =-scale.Z;
                }
                else if (scale.X<0 && scale.Z<0)
                {
                        scale.X =-scale.X;
                        scale.Z =-scale.Z;
                }
                else if (scale.X<0 && scale.Y<0)
                {
                        scale.X =-scale.X;
                        scale.Y =-scale.Y;
                }
 
edit2: The change got added to svn trunk in revision 3400.

Re: matrix4 vs. Eulerangles

Posted: Thu Mar 08, 2012 3:29 pm
by WWebber
thank you. problem solved.