Page 1 of 1

[fixed]Matrix Changes in irrlicht 1.7

Posted: Mon Jan 17, 2011 8:39 am
by pippy3
I've been using the Free Flight (space flight) functions functions to calculate rotation in my game.

I ported my game to irrlicht 1.7.2 and it broke. I was wondering what changes would cause this code to fail:

Code: Select all

// this returns the incorrect result
irr::core::matrix4 m;
m.setRotationDegrees(core::vector3df (270.000000, 0.000000, 0.000000));
irr::core::matrix4 n;
n.setRotationDegrees(core::vector3df (-90.000000 0.000000 0.00000));
m *= n;
return m.getRotationDegrees();
// returns 360.000000 -0.000000 0.000000
// (should return 180, 0, 0)


// returns almost the correct result. 
irr::core::matrix4 m;
m.setRotationDegrees(core::vector3df (270.000000, 0.000000, 0.000000));
irr::core::matrix4 n;
n.setRotationDegrees(core::vector3df (-89.910004 0.000000 0.000000));
m *= n;
return m.getRotationDegrees();
// returns 180.089996 -0.000000 0.000000
Why does it get to -90 it snaps to 360 degrees? I've tried rotating the -90 to 270 and it does the same thing.

I don't really know an alternative to using matrices to rotate directions so I'm kinda stuck on this problem at the moment.

Posted: Mon Jan 17, 2011 9:39 am
by hybrid
Hmm, maybe there's a sign problem somewhere. I'll add a test case for this situation and tell about the results.

Posted: Mon Jan 17, 2011 9:45 am
by pippy3
Swapping the floats with doubles seems to fix it. It may be an issue with matrix4, or a casting issue:

Code: Select all

irr::core::CMatrix4<f64> m, n;
m.setRotationDegrees(core::vector3d<f64> (rot.X, rot.Y,rot.Z));
n.setRotationDegrees(core::vector3d<f64> (mrot.X, mrot.Y,mrot.Z));
m *= n;
return core::vector3df ((f32)m.getRotationDegrees().X,
							  (f32)m.getRotationDegrees().Y,
							  (f32)m.getRotationDegrees().Z);

Posted: Mon Jan 17, 2011 10:30 am
by hybrid
Just added a test case to SVN/trunk. There's no issue with this code in that version. I cannot test it here under Irrlicht 1.7, though. Maybe it's one of the fixed errors with the getRotations clamping issues.

Posted: Thu Jan 20, 2011 2:27 pm
by drewbacca
This sounds just like the bug I noted at
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=39722

The fix was only applied to trunk at revision 3400. Copying the changes from that revision will probably solve your problem.