How do I rotate an object using OpenGL ES 2.0?

喜你入骨 提交于 2019-12-13 12:35:49

问题


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

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


回答1:


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;
}

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.

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.




回答2:


Whithout the fixed function matrix stacks you have to manage your transformation matrices yourself. Consult some introductory material on matrix and vector algebra, especially with respect to 3d transformations. Then you will understand, what glRotate and the like really do.



来源:https://stackoverflow.com/questions/3339114/how-do-i-rotate-an-object-using-opengl-es-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!