开发者

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 ActionTu开发者_开发知识库rnRight: 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);


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜