flagrant2

05-21-2015, 10:55 PM

Hello. I'm attempting to use glRotate to draw a rigid body with known roll and pitch vectors (here I am using an aeronautical analogy, the roll vector points toward the front of a plane and the pitch points to its left wing). My issue is that I can compute the angle and rotation axis to bring the roll axis to e.g. the z-axis (by atan2 and cross product respectively) but then my pitch vector generally isn't where I want it e.g. the y axis. Here's pseudocode for what I've attempted to do:

alpha = angle between roll vector and z axis

axis1 = cross product of roll and unit vector in z direction

wrong pitch = (vector you get when you rotate pitch vector around axis1 by alpha)

beta = angle between wrong-pitch and y

glRotate( alpha, axis1[0], axis2[1], axis3[2]);

glRotate( beta, 0, 0, 1)

draw stuff

This "kind of" works... I get the expected behavior as my plane turns, but then all of a sudden it spins 180 degrees and is flying backwards. I'm not sure what's wonky about my solution, but I'd think there is a better way.

I'm aware of Euler's rotation theorem, which implies I ought to be able to do this with just one call to glRotate. However, I have scoured the web and haven't found a way to compute the needed angle and Euler axis, just lots of proofs of stuff about matrices. It may be a shot in the dark, but I suppose this is a common thing people want to do with opengl. Any help is greatly appreciated!

John

alpha = angle between roll vector and z axis

axis1 = cross product of roll and unit vector in z direction

wrong pitch = (vector you get when you rotate pitch vector around axis1 by alpha)

beta = angle between wrong-pitch and y

glRotate( alpha, axis1[0], axis2[1], axis3[2]);

glRotate( beta, 0, 0, 1)

draw stuff

This "kind of" works... I get the expected behavior as my plane turns, but then all of a sudden it spins 180 degrees and is flying backwards. I'm not sure what's wonky about my solution, but I'd think there is a better way.

I'm aware of Euler's rotation theorem, which implies I ought to be able to do this with just one call to glRotate. However, I have scoured the web and haven't found a way to compute the needed angle and Euler axis, just lots of proofs of stuff about matrices. It may be a shot in the dark, but I suppose this is a common thing people want to do with opengl. Any help is greatly appreciated!

John