2013-04-07 35 views
0

我不确定如何旋转我的对象。目前我有一个四边形,我希望能够以45度角度观看它,我已经建立了我的模型视图投影矩阵。我知道我应该在着色器中而不是在实际的代码中做这件事,稍后我会改变它,但这里有一些代码。不确定如何在opengl中旋转对象2

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)的函数;

回答

0

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