Hello all,
I have a big problem. I need to get the rotation part from a matrix. But in the .NET version is no method or Property Rotation in the Matrix4 class. Can someone explain why there is no method and how to read the rotation part out of the matrix.
Thanks a lot.
Vince
Get rotation from Matrix4
Ok, I added the GetRotationDegrees() method to the Irrlicht.NET code and it works correctly.
Here is the code you have to add to the Matrix4.h file in Irrlicht.NET:
Ok thats all, I have stolen it from the Irrlicht originally source code.
Have fun.
regards
Vince
Here is the code you have to add to the Matrix4.h file in Irrlicht.NET:
Code: Select all
Vector3D GetRotationDegrees()
{
Matrix4 &mat = *this;
double Y = -asin(mat.get_M(2,0));
double D = Y;
double C = cos(Y);
Y *= GRAD_PI; // <- this was "180.000f/PI" before
// (not part of the bug)
double rotx, roty, X, Z;
if (fabs(C)>0.0005f) // <- C not Y
{
rotx = mat.get_M(2,2) / C;
roty = mat.get_M(2,1) / C;
X = atan2( roty, rotx ) * GRAD_PI;
rotx = mat.get_M(0,0) / C;
roty = mat.get_M(1,0) / C;
Z = atan2( roty, rotx ) * GRAD_PI;
}
else
{
X = 0.0f;
rotx = mat.get_M(1,1); // <- no minus here
roty = -mat.get_M(0,1); // <- but here, and not (1,0)
Z = atan2( roty, rotx ) * GRAD_PI;
}
// fix values that get below zero
// before it would set (!) values to 360
// that where above 360:
if (X < 0.00) X += 360.00;
if (Y < 0.00) Y += 360.00;
if (Z < 0.00) Z += 360.00;
return Vector3D((float)X,(float)Y,(float)Z);
}
Have fun.
regards
Vince