Burf2000
Burf2000

Reputation: 5203

Iphone OpenGL : gluLookAt X,Z to rotation (360) : Heading angle

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);

Upvotes: 0

Views: 1125

Answers (3)

Burf2000
Burf2000

Reputation: 5203

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

Upvotes: 0

Doug Ferguson
Doug Ferguson

Reputation: 2618

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.

Upvotes: 1

Alain
Alain

Reputation: 27250

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

Upvotes: 1

Related Questions