PDA

View Full Version : Local and global axis



Simon Hall
09-26-2000, 02:50 AM
I've got my little space ship, in say list 1, and I have the angles that the players wants to rotate it by, but whenever I rotate it by those angles with

glRotatef(x_angle, 1, 0, 0);
glRotatef(y_angle, 0, 1, 0);
glRotatef(z_angle, 0, 0, 1);

but when the user wants to roll back, it rotates it round the global x axis rather than the local axis. So I do a nice bit of complex 3D trig to calculate the vectors to rotate around, but it still screws up as the vectors have also been rotated!

Help me please! An A level maths student who can't do trig!

Simon Hall

rts
09-26-2000, 05:43 PM
Originally posted by simonjhall:
Help me please! An A level maths student who can't do trig!



Eventually, even if you get this 'right', you will
run into the problem of "gimbal lock" (sp?)

I have also written a small spaceship flying around a
solar system OpenGL program just for kicks and
quickly ran into the sorts of problems you're having.

I now use quaternions to represent the orientation
(rotation) of my space ship and it works great.

Here are some references:

http://www.gamasutra.com/features/programming/19980703/quaternions_01.htm
http://www.cs.berkeley.edu/~laura/cs184/quat/quaternion.html

The <a href="http://plib.sourceforge.net" target="_blank">Portable Game
Library</a> also has some nice quaternion
classes ready to use.

Hope this helps

[This message has been edited by rts (edited 09-26-2000).]