[英]Opengl ES Android - Rotate camera around itself
我正在使用Opengl ES在android上开发地形生成应用程序,但在围绕自身旋转相机时遇到了问题(FPS效果很清楚)。 我正在做的是使用Matrix.setLookAtM
移动视图,然后将其转换为Matrix.setLookAtM
后旋转视图。这是代码片段:
Matrix.setLookAtM(mViewMatrix, 0, xrot, eyeY, yrot, xrot, lookY, yrot,0.0f, 1.0f, 0.0f);
Matrix.translateM(mViewMatrix,0,-xrot,0f,-yrot);
Matrix.rotateM(mViewMatrix, 0, mAngleX+mAngleY, 0.0f, 1.0f,0.0f);
Matrix.translateM(mViewMatrix,0,xrot,0f,yrot);
其中xrot
, yrot
, mAngleX+mAngleY
是从触摸屏输入的。 该代码仅在原点起作用,但是在移动时它绕世界的y轴旋转而不是摄像机的y轴旋转。 我想我做的不对,但是我没有找到一种可以在任何地方工作的方法。
我找到了一种方法:
Matrix.setIdentityM(mCurrentRotation, 0);
Matrix.rotateM(mCurrentRotation, 0, mAngleY+mAngleX, 0.0f,1.0f, 0.0f);
Matrix.rotateM(mCurrentRotation, 0, mAngleX, 0.0f,0.0f, 1.0f);
mAngleX = 0.0f;
mAngleY = 0.0f;
Matrix.multiplyMM(mTemporaryMatrix, 0, mCurrentRotation, 0, mAccumulatedRotation, 0);
System.arraycopy(mTemporaryMatrix, 0, mAccumulatedRotation, 0, 16);
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
// multiply the rotation just for model*view
Matrix.multiplyMM(mMVPMatrix, 0, mTemporaryMatrix, 0, mMVPMatrix, 0);
//than add projection as usual
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
其中mTemporaryMatrix, mCurrentRotation,mAccumulatedRotation,
是分别计算总旋转,保持帧旋转和存储摄像机整体旋转的矩阵。 此解决方案可旋转,但不会使相机朝其指向的方向移动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.