Rotating the axis?


I’ve got a problem that I’m pretty sure I’ve solved before but I can’t work it out and I’m running out of hair to pull out. I’ve got something I want to rotate and then rotate again depending on user input. Which is fine and it works etc.

I’m storing the rotation of the object as rotx,roty,rotz.

The problem is that I want the axis to move with the object, if that makes sense. So it rotates as if its rotating from 0 each time. So that if rotx=90, rotating around y doesn’t cause it just to spin.

I really hope that makes sense. It’s driving me nuts.


And incase it matter I’m using my own rotation function instead of glRotatef because I need to keep track of the positions of things.

Any ideas??

When you create the rotation matrix just start with the
identity every time.

So (in hypothetical C++):

Matrix m;

Are you talking about having your own modelview matrix that is affected any frame while rotation?
I can provide you with working code with which you can rotate the object about it’s local axises even after a rotation.

Yup that sounds like it. I’ve got multiple objects that I want to be able to rotate around their own axis without that affect of them rotating around the “wrong” axis when they’ve already been rotated abit.

I’d be interested in seeing any code or pseudo code you think will help.