[fixed]matrix4 vs. Eulerangles

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
WWebber
Posts: 16
Joined: Sun Feb 26, 2012 11:24 am

[fixed]matrix4 vs. Eulerangles

Post 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?!
Last edited by WWebber on Thu Mar 08, 2012 3:30 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: matrix4 vs. Eulerangles

Post by CuteAlien »

I don't know what results you get. I get:
rot1 {X=180.00000 Y=-0.00000000 Z=0.00000000 }
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
WWebber
Posts: 16
Joined: Sun Feb 26, 2012 11:24 am

Re: matrix4 vs. Eulerangles

Post by WWebber »

I'm getting: { -0, -0, 0 }
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: matrix4 vs. Eulerangles

Post by CuteAlien »

Interesting. Can you please give me the exact platform on which you are testing? Compiler, OS, debug/release, 32-bit/64-bit.
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
WWebber
Posts: 16
Joined: Sun Feb 26, 2012 11:24 am

Re: matrix4 vs. Eulerangles

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

Re: matrix4 vs. Eulerangles

Post by CuteAlien »

Here atan2(0,-1) => 180. mat[10] is -1, invC is 1 and invScale.Z is 1.
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
WWebber
Posts: 16
Joined: Sun Feb 26, 2012 11:24 am

Re: matrix4 vs. Eulerangles

Post by WWebber »

so the problem is invScale.. just debugging..
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: matrix4 vs. Eulerangles

Post by CuteAlien »

Ah.. Irrlicht version. Seems there was something fixed in trunk, but it never got backported to Irrlicht 1.7.
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
WWebber
Posts: 16
Joined: Sun Feb 26, 2012 11:24 am

Re: matrix4 vs. Eulerangles

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

Re: matrix4 vs. Eulerangles

Post 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.
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
WWebber
Posts: 16
Joined: Sun Feb 26, 2012 11:24 am

Re: matrix4 vs. Eulerangles

Post by WWebber »

thank you. problem solved.
Post Reply