【发布时间】:2013-11-28 05:40:10
【问题描述】:
我想在 OpenGL 中围绕对象旋转相机。不太会发生。这是我的代码:
对象是标准立方体。
- (void)update {
float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
float radius = 10.0f;
float startAngle = -3 * M_PI/4.0;
float newX = 0.0f + radius *cos(phi)*sin(theta);
float newY = 0.0f + radius *sin(phi)*sin(theta);
float newZ = 0.0f + radius *cos(theta);
GLKMatrix4 projectionMatrix = GLKMatrix4MakeLookAt(newX, 0.0, newZ
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
self.effect.transform.projectionMatrix = projectionMatrix;
GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 0.0f);
self.effect.transform.modelviewMatrix = modelViewMatrix;
}
-(void) viewPanned:(UIPanGestureRecognizer *) sender
{
CGPoint curTouch = [sender locationInView:self.view];
if ([sender state] == UIGestureRecognizerStateBegan){
oldX = curTouch.x;
oldY = curTouch.y;
}
theta += (curTouch.x-oldX)*0.001f;
phi += (curTouch.y-oldY)*0.001f;
oldX = curTouch.x;
oldY = curTouch.y;
}
【问题讨论】:
-
我没有看到从(由
theta/phi旋转)眼睛坐标转换为剪辑坐标的投影矩阵。这可能是您问题的一部分……除此之外,它可能有助于澄清“没有发生”。 -
GLKMatrix4 projectionMatrix = GLKMatrix4MakeLookAt(newX, 0.0, newZ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);这是一个投影矩阵?还是我错过了什么?在这种情况下也没有完全发生意味着白屏,那里什么也没有。
标签: ios opengl-es opengl-3 glkit