1

我的 GLKView 中有一个在该touchesMoved方法期间旋转的对象。然而,在旋转时,矩阵也会缩放,这有点奇怪。有人可以检测到问题吗?

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {


    self.opaque = NO;
    self.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);

    glClear(GL_COLOR_BUFFER_BIT);

    [self.effect prepareToDraw];

    glBindVertexArrayOES(vertexArray);
    glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);


}



-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{



    UITouch * touch = [touches anyObject];
    CGPoint location = [touch locationInView:[touch view]];
    CGPoint lastLoc = [touch previousLocationInView:[touch view]];
    CGPoint diff = CGPointMake(lastLoc.x - location.x, lastLoc.y - location.y);

    float rotX = -1 * GLKMathDegreesToRadians(diff.y / 2.0);

    GLKVector3 xAxis = GLKVector3Make(1, 0, 0);
    rotMatrix = GLKMatrix4Rotate(rotMatrix, rotX, xAxis.x, xAxis.y, xAxis.z);

    float aspect = fabsf(self.bounds.size.width / self.bounds.size.height);
    GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 4.0f, 10.0f);
    self.effect.transform.projectionMatrix = projectionMatrix;

    GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -6.0f);
    modelViewMatrix = GLKMatrix4Multiply(modelViewMatrix, rotMatrix);
    self.effect.transform.modelviewMatrix = modelViewMatrix;

    [self display];

}
4

1 回答 1

1

将 GLKMathDegreesToRadians 的值减小到较小的值会缩放您的立方体大小。

将小于 65.0f 的值赋予 GLKMathDegreesToRadians,例如

GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(35.0f), aspect, 4.0f, 10.0f); 
于 2013-06-07T12:17:09.847 回答