2017-07-05 18 views
0

OpenGL ESでアンドロイドに地形生成アプリケーションを開発していますが、カメラ自体を回転させるのに問題があります。 私がやっていることはMatrix.setLookAtMでビューを移動させることで、その後origin.Thisにそれを翻訳した後、ビューを回転すると、コードの抜粋です:OpenGL ES Android - カメラ自体を回転させる

xrotyrotmAngleX+mAngleYがタッチスクリーンから入力された
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); 

。 このコードは原点でのみ動作しますが、移動すると、カメラの世界ではなく、世界のy軸を中心に回転します。私はそれを正しくやっていないと思うが、どこでも働く方法を見つけられなかった。

答えて

0

私はそれを行う方法を見つけました:

mTemporaryMatrix, mCurrentRotation,mAccumulatedRotation,は、それぞれ、総回転を計算するフレーム回転を維持し、カメラの全体の回転を格納するための行列である
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); 

。この解決策は回転のために機能しますが、カメラが指示している方向に移動することはありません。