View Full Version : rotating and object without rotating its axis

Does anyone know how to rotate an object so that it's axis does not rotate with it?

for example...

if you rotate an object 90deg on the x axis the z & y axis effectively trade places.

I tried handling the situation by(for example above) rotating the y axis as a substitute for the z axis but the conditions appear to get more and more complex as the object becomes more and more twisted.

Any thoughts?

Cheers

Scam

Andrea Rossini

11-12-2003, 06:05 AM

Here's the simplest way:

for(All Objects To Draw)

{

glPushMatrix(); // Save the matrix

glRotate(); // Rotate

Draw_Your_Object();

glPopMatrix(); // Restore matrix

}

This way will restore the axis rot after drawind operation

Sorry I should have been a little more explicit. I want to restore the "local" axis of the rotated object without restoring the previous rotation transforms. Think of it more as altering the rest rotation of an object perhaps.

Using the matrix stack will only restore the world axis (conceptually). Any previous rotation transforms will again have to be applied to the object next time it is drawn.

Thanks for your thoughts :-)

Scam

Andrea Rossini

11-12-2003, 10:42 PM

I think you want to rotate the object

around its axis, just transalte, rotate ecc... until the world axis has become your object axis. Now perform the final transate/rotation. OpenGL will still work on the world axis, but you will "conceptually" rotate around the objet axis.

Hope that's what you need.

OK I will try and explain the situation a little better. I have found a solution that will work for the application I am using but I am still interested to know if there is a solution to the main problem. so....

0 - load identity matrix for model view

1 - Rotate an object on the y axis - the effect is that the object spins like a spinning top.

if I rotate the object 90deg on the x axis the y axis rotation becomes that of a ferris wheel or clock. I want to somehow reset the axis so that y axis rotation remains the same as a spinning top even though I have rotated the object around the x axis or z axis.

I dont understand you second solution 100% but I get the feeling that I would have to inversely rotate other objects in the world if I was to align the world with the object in question.

I dont want other objects in the world to be effected by the transforms.

Thanks for your time and input though it is greatly appreciated. Have a good day :-)

Scam

chowe6685

11-13-2003, 03:38 PM

you need to use a non-euler representation for your rotations, good choices include quaternions which apparently work really well but as I don't understand the math behind them i don't use them, matrices, or an axis/angle representation.

Andrea Rossini

11-13-2003, 10:47 PM

I got a similar problem once and I solved this way.

rotate around the y axis:

glRotate(45, 0, 1, 0);

rotate around the OLD x axis:

glRotate(45, 1, 0, 1);

this example applies to 45 degrees rots and also the 1s passed to the second glRotate must be specified as sqrt(2) (I don't remember)and also the second 45 was not exactly 45 but I put it here just as an example.

Anyway you must recalculate the x,y,z parameters for any glRotate according to previous rotations, this goes over my knowledge.

Puma1140

12-13-2003, 04:14 PM

scam, did you find a solution on your problem? Can you post it?

DarthPaul

12-16-2003, 08:09 AM

I've got the same problem here.

DarthPaul

12-17-2003, 08:30 AM

Would applying the inverse of all the previous rotations, adding a new rotation, then re-applying the previous rotations work?

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.