0

Possible Duplicate:
How to convert Euler angles to directional vector?

I'm using OpenGL to rotate a brick. The brick simulates a phone that has an accelerometer. The initial vector I'm using is (0.0, 0.0,-1.0)

glRotatef(angle.x, 1.0, 0.0, 0.0);
glRotatef(angle.y, 0.0, 1.0, 0.0);
glRotatef(angle.z, 0.0, 0.0, 1.0);

How do I get the accelerometer's vector from the angles above?

Community
  • 1
  • 1
Jon White
  • 67
  • 4
  • I need yaw pitch and roll. The first formula does not have roll. Also the code below it is in a matrix. I need a vector. – Jon White Jun 16 '12 at 21:13

1 Answers1

0

Wouldn't you have to multiply your initial vector by the 3 matrices you mention ? Just replicating the way OpenGL does it.

This wouldn't be the most efficient, but this would give the resulting vector. Am I missing something ?

rotoglup
  • 5,223
  • 25
  • 37
  • Okay I got it working. I tried using the rotation matrices in my OpenGL Red book but it did not work. I tried the matrix code mentioned above and it worked. I just multiplied the vector by the matrix's third column of the XYZ rotation formula. One interesting thing is that I had to use -M_PI instead of -1.0 for the starting vector. I then normalized it so that it's minimum is -1.0 and maximum is 1.0 for any axis. – Jon White Jun 17 '12 at 20:52