Game Development Community

MatrixF::toEuler Bug (and fix)

by William Todd Scott · in Torque Game Engine Advanced · 12/28/2006 (1:12 pm) · 1 replies

Hi,

I believe that the following bug is caused by floating point errors.

Basically, in the MatrixF::toEuler() function it is possible for the following line to return a NaN if the value of idx(2,1) is greater than 1.0 or less than -1.0. This was happening quite frequently where I was getting values like 1.00001.

r.x = mAsin(mat[MatrixF::idx(2,1)])


The fix is to simply clamp the value to the -1.0 to 1.0 range:

r.x = mAsin(mClampF(mat[MatrixF::idx(2,1)], -1.0f, 1.0f));  //fix


Todd

#1
12/29/2006 (3:25 pm)
Issue #2487. I'm a little wary of the clamp here, as it might be hiding deeper issues, but at the same time you raise a good point & the fix is by no means a bad one!

Thanks for writing this up, much appreciated.