Opengl es OpenGL ES 2.0中对象的旋转变换
对于应用旋转变换矩阵,我是否将旋转矩阵与单位矩阵相乘,然后将该矩阵传递回着色器?我希望能够将对象沿X轴旋转90度。我知道PVR工具已经有一个功能可以做到这一点,但我只是想确认我是否将我的旋转矩阵乘以下面的mMVP矩阵。谢谢Opengl es OpenGL ES 2.0中对象的旋转变换,opengl-es,opengl-es-2.0,Opengl Es,Opengl Es 2.0,对于应用旋转变换矩阵,我是否将旋转矩阵与单位矩阵相乘,然后将该矩阵传递回着色器?我希望能够将对象沿X轴旋转90度。我知道PVR工具已经有一个功能可以做到这一点,但我只是想确认我是否将我的旋转矩阵乘以下面的mMVP矩阵。谢谢 bool OGLESIntroducingPVRTools::RenderScene() { // Clears the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFF
bool OGLESIntroducingPVRTools::RenderScene()
{
// Clears the color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Binds the loaded texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_uiTexture[0]);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_uiTexture[1]);
// Use the loaded shader program
glUseProgram(m_ShaderProgram.uiId);
/*
Creates the Model View Projection (MVP) matrix using the PVRTMat4 class from the tools.
The tools contain a complete set of functions to operate on 4x4 matrices.
*/
PVRTMat4 mMVP = PVRTMat4::Identity();
if(PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen)) // If the screen is rotated
mMVP = PVRTMat4::RotationZ(-1.57f);
/*
Pass this matrix to the shader.
The .m field of a PVRTMat4 contains the array of float used to
communicate with OpenGL ES.
*/
glUniformMatrix4fv(m_ShaderProgram.auiLoc[eMVPMatrix], 1, GL_FALSE, mMVP.ptr());
/*
Draw a triangle.
Please refer to the training course IntroducingPVRShell for a detailed explanation.
*/
// Bind the VBO
glBindBuffer(GL_ARRAY_BUFFER, m_ui32Vbo);
// Pass the vertex data
glEnableVertexAttribArray(VERTEX_ARRAY);
glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, m_ui32VertexStride, 0);
// Pass the texture coordinates data
glEnableVertexAttribArray(TEXCOORD_ARRAY);
glVertexAttribPointer(TEXCOORD_ARRAY, 2, GL_FLOAT, GL_FALSE, m_ui32VertexStride, (void*) (sizeof(GLfloat) * 3) /* Uvs start after the position */);
// Draws a non-indexed triangle array
glDrawArrays(GL_TRIANGLES, 0, 6);
return true;
}
最好分离模型、视图和投影矩阵,并将旋转应用于模型矩阵。看见