1

为了应用旋转变换矩阵,我是否只需将旋转矩阵乘以单位矩阵并将该矩阵传递回着色器?我希望能够将我的对象沿 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;
}
4

0 回答 0