在opengl Es2
中,我按照以下代码旋转相机(向前,向上和侧向)。
但是,此方法将滚动引入视图。如果我注释掉一个或另一个(标题或音高),则没有滚动。
theading
和tpitch
通常只有1或2度(或-1或-2)。
有关消除滚动的任何想法吗?
//rotate heading
this.rotate_XYZ(cam.right, tHeading, cam.up);
this.rotate_XYZ(cam.forward, tHeading, cam.up);
//rotate pitch
this.rotate_XYZ(cam.up, tPitch, cam.right);
this.rotate_XYZ(cam.forward, tPitch, cam.right);
public void rotate_XYZ(j3Vector sVector,float angle, j3Vector a){
Matrix.setIdentityM(this.mCameraRotateMatrix, 0);
Matrix.rotateM(this.mCameraRotateMatrix, 0, angle, a.x, a.y, a.z);
this.mRHS_Vector[0]=sVector.x;
this.mRHS_Vector[1]=sVector.y;
this.mRHS_Vector[2]=sVector.z;
Matrix.multiplyMV(this.mRESULT_Vector,0, mCameraRotateMatrix,0,this.mRHS_Vector, 0);
sVector.set(this.mRESULT_Vector[0],this.mRESULT_Vector[1],this.mRESULT_Vector[2]);
return;
}
答案 0 :(得分:0)
解决方案
向上旋转世界并向上旋转凸轮。
//rotate heading
this.rotate_XYZ(cam.right, tHeading, world.up);
this.rotate_XYZ(cam.forward, tHeading, world.up);
this.rotate_XYZ(cam.up, tHeading, world.up);
//旋转音高
this.rotate_XYZ(cam.up, tPitch, cam.right);
this.rotate_XYZ(cam.forward, tPitch, cam.right);
public void rotate_XYZ(j3Vector sVector,float angle, j3Vector a){
Matrix.setIdentityM(this.mCameraRotateMatrix, 0);
Matrix.rotateM(this.mCameraRotateMatrix, 0, angle, a.x, a.y, a.z);
this.mRHS_Vector[0]=sVector.x;
this.mRHS_Vector[1]=sVector.y;
this.mRHS_Vector[2]=sVector.z;
Matrix.multiplyMV(this.mRESULT_Vector,0, mCameraRotateMatrix,0,this.mRHS_Vector, 0);
sVector.set(this.mRESULT_Vector[0],this.mRESULT_Vector[1],this.mRESULT_Vector[2]);
return;
}