Local system rotation

AFAIK either using Euler angles rotations or quaternions you still end up doing rotations using the regular world coordinate system.

But, for example, when a plane makes a roll or a pitch it’s around its own axis. So that rotations are always relative to its own local system.

I haven’t tested yet but it seems to me that the following would lead to the right result:

vector3 XAxis = (1, 0, 0);
vector3 YAxis = (0, 1, 0);
vector3 ZAxis = (0, 0, 1);

vector3 LocalXAxis = XAxis;

matrix4 PitchMatrix = Rotate(Pitch, LocalXAxis);

vector3 LocalYAxis = PitchMatrix * YAxis;

matrix4 RollMatrix = Rotate(Roll, LocalYAxis);

vector3 LocalZAxis = PitchMatrix * RollMatrix * ZAxis;

matrix4 YawnMatrix = Rotate(Yawn, LocalZAxis);

So it would give LocalRotation(Pitch, Roll, Yawn) = PitchMatrix * RollMatrix * YawnMatrix.

Does this seems correct?
If it is, isn’t their any other (and preferably more efficient) way of doing this?

The usual way of doing rotations around and arbitary point is this:

glTranslate( “Move model so center is at roration point”);
glRotate( “Do reqired rotation” );
glTranslate( " Move back to origional position");

Of course OpenGL has reverse order matrices so you have to do the above in the reverse order. ( ie negative translation, rotation, positive translation)

Things are also much easier if your model is made with it’s center already at the required position. (ie. no need to translate)

Hmm, thanks, but it’s not really what I meant.
In my post above I was already assuming that the model was centered.

The problem is that if I do :

glRotate(Pitch, 1, 0, 0);
glRotate(Yawn, 0, 1, 0);
glRotate(Roll, 0, 0, 1);

The plane (to keep the same example) will not rotate correctly 'cause these rotations are based on world axises and not on the plane axises.
To be correct it seems to me that the rotations have to be based on the plane axises and follow each previous rotation.

Thus the idea I would like to verify (and optimize) is to rotate the plane Y and Z axises when doing the first rotation around X and then to use these transformed axis to do the second and then the third rotation.
(note: Z axis being transformed once more after the rotation around the transformed Y axis).

Another way to say it would be:

  • Rotate the plane around X axis
  • Rotate Y and Z around X, resulting axises are Y’ and Z’
  • Rotate the plane around Y’ axis
  • Rotate Z’ around Y’, resulting axis is Z’’
  • Rotate the plane around Z’’ axis