タッチを使用して iOS で OpenGL オブジェクトを回転させようとしていますが、問題が発生しています。ここでユーザーのタッチを取得しています:
- (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)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 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -3.5f);
modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, -1, startPoint.x, startPoint.y, 0.0f);
dx = dy =0;
self.effect.transform.modelviewMatrix = modelViewMatrix;
}