不确定如何在opengl中旋转对象2

时间:2013-04-07 18:12:31

标签: opengl-es opengl-es-2.0

我不确定如何旋转我的物体。目前我有一个四边形,我希望能够以45度角观察它,我已经设置了我的模型视图投影矩阵。我知道我应该在着色器中而不是在实际代码中执行此操作,稍后我会更改它,但这里有一些代码。

    bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);
p_Matrix = PVRTMat4::PerspectiveFovRH(PVRT_PI / 6, (float) PVRShellGet(prefWidth) / (float) PVRShellGet(prefHeight), 4.0f, 1000.0f, PVRTMat4::OGL, bRotate);
PVRTVec3 view_From(2, 2, 0);
v_Matrix = PVRTMat4::LookAtRH(view_From, view_At, view_Up) * PVRTMat4::RotationX(45);
cam_Pos = view_From;

PVRTMat4 modelView, world, mMVP;
world = PVRTMat4::Identity();
modelView = v_Matrix * world;
mMVP = p_Matrix * modelView;

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());

我试过旋转mMVP矩阵,但它没有效果。并且还尝试旋转modelview和v_matrix(视图矩阵)。我使用SDK给出的函数PVRTMat4 :: RotationX(45);

1 个答案:

答案 0 :(得分:0)

你可以使用PVRTMat4 :: scale(fx,fy,fz)函数得到你需要的44个旋转矩阵。设置fx = 45和fy = 0并且fz = 0。然后将返回的矩阵乘以mMVP矩阵。