Opengl es 打开Gl绕轴旋转矢量并滚动
在Opengl es 打开Gl绕轴旋转矢量并滚动,opengl-es,Opengl Es,在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);
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;
}
解决方案
向上旋转世界,也向上旋转凸轮
//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;
}