[SOLVED]Quaternion rotation,Conversion back to Euler angles?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
pandoragami
Posts: 226
Joined: Wed Jan 26, 2011 5:37 pm
Contact:

[SOLVED]Quaternion rotation,Conversion back to Euler angles?

Post by pandoragami »

I have a general idea of using quaternions for rotating a polygon. Lets suppose I have a polygon with 3 vertices and I want to rotate their positions 45 degrees along all 3 axes x, y and z.

The question I want to get to the bottom of is what are the general steps for doing this.

These are the steps I think are necessary:

1. Convert Euler angles to quaternions,
2. Do the rotation with quaternions and
3. When I have the rotated quaternion would I need to convert back to Euler angles in order reposition the vertices?

If anyone could psuedocode this (or better) using the Irrlicht api please do so.
Last edited by pandoragami on Fri Jan 17, 2014 4:33 pm, edited 1 time in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Quaternion rotation, Conversion back to Euler angles?

Post by mongoose7 »

Just put the vertices in a scene node and call node->setRotation(45, 45, 45).

I hope you realise that Euler angles are ambiguous. Once you apply the rotation about one axis, that affects the rotations about the other two. It is usual to apply the rotations in the order ZXY. This fits with aerodynamics.
pandoragami
Posts: 226
Joined: Wed Jan 26, 2011 5:37 pm
Contact:

Re: Quaternion rotation, Conversion back to Euler angles?

Post by pandoragami »

mongoose7 wrote:Just put the vertices in a scene node and call node->setRotation(45, 45, 45).

I hope you realise that Euler angles are ambiguous. Once you apply the rotation about one axis, that affects the rotations about the other two. It is usual to apply the rotations in the order ZXY. This fits with aerodynamics.

So if I use

Code: Select all

node->setRotation(45, 45, 45);
I won't need to worry about gimbal lock, it's done with quaternions?
vivekSivamRP
Posts: 66
Joined: Sat Sep 29, 2012 11:58 am

Re: Quaternion rotation, Conversion back to Euler angles?

Post by vivekSivamRP »

Generally to avoid Gimbal Lock we use quaternion class in irrlicht, for ex,

Code: Select all

 
vector3df eulerAngle = vector3df(45.0,45.0,45.0);
quaternion quatAngle = quaternion(eulerAngle * DEGTORAD);
 
vector3df gimbalFreeAngle;
quatAngle.toEuler(gimbalFreeAngle);  // get the euler angle back without gimbal locks.
gimbalFreeAngle *= RADTODEG;
 
if(gimbalFreeAngle.X < 0)
    gimbalFreeAngle.X += 360;
if(gimbalFreeAngle.Y < 0)
    gimbalFreeAngle.Y += 360;
if(gimbalFreeAngle.Z < 0)
    gimbalFreeAngle.Z += 360;
 
node->setRotation(gimbalFreeAngle);
 
 
pandoragami
Posts: 226
Joined: Wed Jan 26, 2011 5:37 pm
Contact:

Re: Quaternion rotation, Conversion back to Euler angles?

Post by pandoragami »

@vivekSivamRP

Thanks, I'll mark this thread solved.
Post Reply