Rotation around local axis

Started by Rainer, March 25, 2008, 11:59:00

Previous topic - Next topic

Rainer

I started a little project (some remote controlled plane sim) and ran into the problem, that i need to rotate the plane around it's local axis.
I can't do this with 3 calls of glRotatef, since this rotates around the global axis.
If I rotate 90° around Y, Z moves into X.
Has someone already done something like this or knows how it's done?

bobjob

cant you rotate the plane before you translate it?

wolf_m

Global vs. Local:

To act on a local matrix, do a glPushMatrix(), perform your transformation, your rotation and your draw calls and then do a glPopMatrix(). This keeps all matrix operations for your dynamic objects in separate matrices, so you effectively get local coordinate systems and after you pop, further operations apply to the matrix you worked on before pushing. Especially hierarchical structures benefit from that.

Whether you want to first translate and then rotate or do it the other way around depends. Just try to switch the order and see what happens.

If you do Euler angles rotation (as you seem to be doing), you want to pay very close attention to the order of rotations since they make a difference.

--------------

Rotation issues:

You're experiencing a gimbal lock because you seem to use the Euler angles.

You _could_ use quaternions for rotations, convert them to a rotation matrix and then apply that matrix (or use the angle-axis representation). Or you could live with the Euler angles and gimbal lock or choose a different rotation method.

Quaternions for rotations are unit-quaternions (4D vectors), which makes calculating rotations around arbitrary axes efficient, stable and flexible, although a little intransparent because it's hard to visualize the operations.

This topic is kind of math-heavy, so you might want to get your linear algebra basics straight, do a little research on quaternions, gimbal lock and the like to fully appreciate using quaternions for rotations.

Popular terms for web search engines in this field are
quaternion
rotation
euler
angle-axis
gimbal lock
slerp

For an overview, you could check this link out: http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

Also do some research on gamasutra, gamedev.net and the like.

"Geometric Tools for Computer Graphics" by Philip J Schneider and David H. Eberly was very helpful for me regarding this topic.

Rainer

much time has passed, but i still didn't found a solution.
(ok, i also hadnt much time to work on  ::) )
does somone now have an idea how to do rotations and controls for a plane?