Get rotation from Matrix4

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
Vincent22
Posts: 2
Joined: Thu Aug 11, 2005 11:36 pm

Get rotation from Matrix4

Post by Vincent22 »

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
Vincent22
Posts: 2
Joined: Thu Aug 11, 2005 11:36 pm

Post by Vincent22 »

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:

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);
			}
Ok thats all, I have stolen it from the Irrlicht originally source code.

Have fun.

regards
Vince
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Vincent22 wrote:Ok thats all, I have stolen it from the Irrlicht originally source code.
Hehe :)
Yes, sorry, I did not translate all of the methods yet. We'Ve got so much of them ;)
Locked