2011-07-21 47 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)