2011-07-21 48 views
0

我正在使用glLookAt来控制我的相机视图。Iphone:OpenGL glLookAt:获取旋转角度

我使用下面的代码来旋转。

SPEED_TURN是0.16(速度我们把在)

GLfloat v[] = {[self centerAtIndex:0] - [self eyeAtIndex:0], 
    [self centerAtIndex:1] - [self eyeAtIndex:1], 
[self centerAtIndex:2] - [self eyeAtIndex:2]}; 

[self setCenter:[self eyeAtIndex:0] + cos(SPEED_TURN/2)*v[0] - sin(SPEED_TURN/2)*v[2] atIndex:0]; 
[self setCenter:[self eyeAtIndex:2] + sin(SPEED_TURN/2)*v[0] + cos(SPEED_TURN/2)*v[2] atIndex:2]; 

我的问题是,如何我得到相机度角一个const?

我想这

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

然而,要620

回答

1

我不认为你正在尝试正确的功能给你的角度。函数“cos()”和“sin()”都取你的角度并将其映射到[-1,1]。如果SPEED_TURN是以弧度表示的角度,那么您只需使用:

float angleInDegrees = (SPEED_TURN * 180)/M_PI; 
+0

Speed_turn是一个常量吗?请帮助:) – Burf2000

+0

你说得对!但它是self.rotation - =(SPEED_TURN/2 * 180)/ M_PI; – Burf2000

+0

然后你可以设置:self.rotation = angleInDegrees; – msgambel

1

给出的数字从-620拿你想要的辈分和PI分På180。然后你得到的弧度进入繁殖它们:

Radians = Degrees * (pi/180) 

从弧度获得学位:

Degrees = Radians * (180/pi)