0

The OpenGL program I am writing uses a port of glULookat to control the camera

To rotate I have the following code

case ActionTurnLeft: 
center[0] = eye[0] + cos(-SPEED_TURN)*v[0] - sin(-SPEED_TURN)*v[2]; 
center[2] = eye[2] + sin(-SPEED_TURN)*v[0] + cos(-SPEED_TURN)*v[2]; 


break;

case ActionTurnRight: center[0] = eye[0] + cos(SPEED_TURN)*v[0] - sin(SPEED_TURN)*v[2]; center[2] = eye[2] + sin(SPEED_TURN)*v[0] + cos(SPEED_TURN)*v[2];

My question is how do I get the rotation angle in degrees?

Updated : Tried this and it gave me -572 ish to 572

float rotAngleDegs;
float PI = 3.1415926535897;
rotAngleDegs = (cos(-SPEED_TURN)*v[0] - sin(-SPEED_TURN)*v[2]) * 180 / PI;
NSLog(@"%f", rotAngleDegs);
genpfault
  • 51,148
  • 11
  • 85
  • 139
Burf2000
  • 5,001
  • 14
  • 58
  • 117

3 Answers3

1

To get an angle in degrees just multiply the angle in radians by 180 / PI where PI = 3.1415926535897. In this case, the rotation angle in radians is the entire piece of code after eye[] part.

rotAngleDegs = (cos(-SPEED_TURN)*v[0] - sin(-SPEED_TURN)*v[2]) * 180 / PI

Alain
  • 26,663
  • 20
  • 114
  • 184
1

It looks like you are using a rotation matrix. Wikipedia Rotation Matrix entry

-SPEED_TURN is the angle of rotation in radians which can be converted to degrees by multiplying the factor 180 / PI.

Doug Ferguson
  • 2,538
  • 2
  • 16
  • 23
  • Speed_turn is a fixed value e.g #define SPEED_TURN 0.05 – Burf2000 Dec 08 '10 at 14:02
  • Each time ActionTurnLeft is applied then the rotation will change by 0.05 * 180 / PI. Which rotation angle are you trying to find? – Doug Ferguson Dec 08 '10 at 15:53
  • Hi Doug I want the rotation angle of the camera rotation which goes from 0 to 360 degrees. Quite new to the whole OpenGL stuff. Actually going to use this to work out which item I clicked on as no one seems to know how to work that out for me. See last 2 posts – Burf2000 Dec 08 '10 at 17:15
  • So would you say that an update to your question is that you want to know the heading angle the the eye is looking. You could calculate the vector from the eye coordinate to the center coordinate and then determine the angle from there. – Doug Ferguson Dec 08 '10 at 18:15
  • Sorry, no code samples. Try searching for "vector angle", "dot product" and "cross product" – Doug Ferguson Dec 08 '10 at 20:08
0

Incrementing a float by rotation +=2.865; seemed to actually work lol

Burf2000
  • 5,001
  • 14
  • 58
  • 117