围绕物体的OpenGL ES轨道相机

时间:2013-11-28 05:40:10

标签: ios opengl-es opengl-3 glkit

我想围绕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;
}

0 个答案:

没有答案