如何使用OpenGL ES 2.0旋转对象? [英] How do I rotate an object using OpenGL ES 2.0?

查看:193
本文介绍了如何使用OpenGL ES 2.0旋转对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OpenGL ES 1.1中,可以使用glRotatef()旋转模型,但是该功能在OpenGL ES 2.0中不存在.

In OpenGL ES 1.1, you can use glRotatef() to rotate a model, but that function doesn't exist in OpenGL ES 2.0.

因此,如何在OpenGL ES 2.0中执行旋转?

Therefore, how do you perform rotation in OpenGL ES 2.0?

推荐答案

要遵循克里斯蒂安所说的话,您需要自己跟踪模型视图矩阵并进行操作以执行所需的旋转.然后,您将矩阵作为制服传递给着色器,并执行以下操作:

To follow on what Christian's said, you'll need to keep track of the model view matrix yourself and manipulate that to perform the rotations you need. You'll then pass in the matrix as a uniform to your shader, and do something like the following:

attribute vec4 position;

uniform mat4 modelViewProjMatrix;

void main()
{
    gl_Position = modelViewProjMatrix * position;
}

我发现核心动画CATransform3D辅助函数可以很好地执行所需的正确矩阵操作.您可以旋转,缩放和平移CATransform3D,然后读出其4x4矩阵元素以创建所需的模型视图矩阵.

I've found that the Core Animation CATransform3D helper functions work very well for performing the right kind of matrix manipulations needed for this. You can rotate, scale, and translate a CATransform3D, then read out its 4x4 matrix elements to create the model view matrix you need.

如果您希望实际使用此功能,请此示例iPhone应用程序我创建的示例展示了如何同时使用OpenGL ES 1.1和2.0来执行多维数据集的旋转.

If you want to see this in action, this sample iPhone application I created shows how to perform rotation of a cube using both OpenGL ES 1.1 and 2.0.

这篇关于如何使用OpenGL ES 2.0旋转对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆