2017-07-10 9 views
0

私はOpenGL ES 2.0で開発された、Android用のランダムな生成アプリを持っています.FPSのようなカメラを実装しようとしています。主な問題は、カメラrotation.Thisに応じたビューを翻訳することである私が回転する方法で、ビューを翻訳:OpenGL ES 2.0 Android - 回転に合わせてカメラを翻訳する

Matrix.setIdentityM(mCurrentRotation, 0); 
    Matrix.rotateM(mCurrentRotation, 0, mAngleX, 0.0f,1.0f, 0.0f); 
    Matrix.setIdentityM(mCurrentTranslation, 0); 
    Matrix.translateM(mCurrentTranslation,0,xrot,-7.0f,yrot); 
    mAngleX = 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); 
    Matrix.multiplyMM(mMVPMatrix, 0, mCurrentTranslation, 0, mMVPMatrix, 0); 
    Matrix.multiplyMM(mMVPMatrix, 0, mTemporaryMatrix, 0, mMVPMatrix, 0); 
    // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix 
    // (which now contains model * view * projection). 
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0); 

古い回転とmAngleXに基づいて、指定されたフレーム上のカメラのmTemporaryMatrix店舗回転それはタッチ入力です。 mCurrentTranslationxrotyrotと同じです。ですから、回転後に動き回ると、動きは世界の座標に従い続けます。マイxrot,yrot更新式は次のとおりです。

void setXYrot(float x, float y){ 
     Matrix.transposeM(temp,0,mTemporaryMatrix,0); 
     Matrix.invertM(temp,0,temp,0); 
     xrot-=(x*Math.sin(Math.acos(temp[5]))); 
     yrot+=(y*Math.cos(Math.acos(temp[5]))); 
    } 

私は問題がそれらに依存しているかなり確信しています。私は回転行列を転置して逆転させ、次にY軸上の回転でなければならない行列の6番目の要素を逆行列にします。誰かが更新機能のどこかでバグを見ていますか?しかし、ほとんどの場合、それを行うための標準的な方法がありますか?

答えて

0

バグを発見しました。まず第一に、私は単に私が角度と呼ばれるフロート変数に回転mAngleXの累積量を維持し、かつ:

void setXYrot(float x, float y){ 

    xrot-=(y*Math.sin((angle*Math.PI)/180f))+(x*Math.cos((angle*Math.PI)/180f)); 
    yrot+=(y*Math.cos((a*Math.PI)/180f))-(x*Math.sin((angle*Math.PI)/180f)); 
} 

ワークスシャルムよう

関連する問題