Cocoa touch 旋转OpenGL ES对象
经过几个小时的努力,我终于能够画出一个物体,但当它旋转时,我被卡住了。我试图绕y轴旋转,但我似乎无法以任何方式使旋转平滑。它几乎是在跳来跳去。中间可能有一些不必要的部分,因此我使用了一个模板Cocoa touch 旋转OpenGL ES对象,cocoa-touch,ios5,xcode4.2,opengl-es-2.0,Cocoa Touch,Ios5,Xcode4.2,Opengl Es 2.0,经过几个小时的努力,我终于能够画出一个物体,但当它旋转时,我被卡住了。我试图绕y轴旋转,但我似乎无法以任何方式使旋转平滑。它几乎是在跳来跳去。中间可能有一些不必要的部分,因此我使用了一个模板 - (void)update { float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height); GLKMatrix4 projectionMatrix = GLKMatrix4MakePer
- (void)update
{
float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f);
self.effect.transform.projectionMatrix = projectionMatrix;
GLKMatrix4 baseModelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -4.0f);
// Compute the model view matrix for the object rendered with ES2
GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 0.0f);
modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, startPoint.y, 0.0f, 1.0f, 0.0f);
dx = dy = 0;
modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix);
_normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL);
_modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix);
_rotation += self.timeSinceLastUpdate * 0.5f;
}
我的触摸行为:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
startPoint = [touch locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
dx = point.y - startPoint.y;
dy = point.x - startPoint.x;
startPoint = point;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
提前感谢。通过苹果图书馆的以下链接可以解决您的问题
[http://developer.apple.com/library/ios/#samplecode/GLSprite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007325感谢您的回复,但遗憾的是,该示例没有任何用户通过触摸方式进行交互。