Get Euler Angles From Rotation.


photo

Recommended Posts

currently node.GetRotation() returns the rotation in type quat, i want to make changes to the rotation is there any way i can get the rotation in euler angles like Quaternion.Euler from unity? 

Link to post

Dear @WarDuck,

Answer to your questions are hidden here

https://developer.unigine.com/en/docs/2.13/api/library/math/math.matrix?rlang=cpp#decomposeRotationXYZ_const_mat3_ref_vec3

For your case you use the following.

mat3 mat3Rotation = m_quatRotation.getMat3();
vec3 vec3RotationEulerAngles = decomposeRotationXYZ(mat3Rotation);

Hope this helps.

Should Also work in C#.

Rohit

Edited by rohit.gonsalves
Added C# tagging
  • Thanks 1
Link to post

Hi, @rohit.gonsalves

Thank you its exactly what i was looking for, but I am not getting the desired result.

		mat3 currentRotation = node.GetRotation().Mat3;
		vec3 eulerAngles = MathLib.DecomposeRotationXYZ(currentRotation);
		Log.MessageLine(eulerAngles);

This is my Function I am just printing out the current rotation like the one we see in the editor Parameters window.

In the Parameters Window

The Result In Console.

Link to post

Dear @WarDuck,

For angles you start from 0. Go clock wise 300 degrees. And then start from 0 and go anti clockwise 60 degrees (-60). Though the magnitude are different. Directions make the point same. You will end up at same point. This is perfect. Probably the function after decomposing the Euler angles returns in range of -180 to 180 or -360 to 360. Remap to range 0 to 360.

if angle < 0 

360 + angle

Again. If editor shows -90 and the result is 270. Both are same.

Rohit

  • Like 1
Link to post