OpenGL ES 2.0对象的旋转变换

时间:2013-03-28 22:51:10

标签: 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_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;
}

0 个答案:

没有答案