首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >旋转OpenGL-ES对象

旋转OpenGL-ES对象
EN

Stack Overflow用户
提问于 2012-01-23 09:10:54
回答 1查看 413关注 0票数 0

经过几个小时的努力,我终于能够画出一个物体,但当它旋转时就卡住了。我正在尝试绕y轴旋转,但我似乎无法以任何方式使旋转平滑。它几乎是跳来跳去的。中间可能有一些不必要的东西,因此我使用了一个模板。

代码语言:javascript
复制
- (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;
}

以及我的触摸行为:

代码语言:javascript
复制
- (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
{

}

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-01-23 15:15:49

通过下面的苹果图书馆链接,可以解决你的问题[http://developer.apple.com/library/ios/#samplecode/GLSprite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007325

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8966255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档