オブジェクトを回転するためにビュー行列を使用しないでください。この行列はすべてのシーンのカメラとして使用されます。オブジェクトを変換するには、モデル行列を使用する必要があります。
public void transform(float[] mModelMatrix) {
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0, y, 0);
Matrix.rotateM(mModelMatrix, 0, mAngle, 0.0f, 0.0f, 1.0f);
}
ドンの `tは、すべてのループ内で変換をリセットするために単位行列を使用し忘れ:自身の中心の周りに回転させる場合には、次のメソッドを使用することができます。
あなたのコードは悪いと思います。変換を適用する前に 'y'の値を更新してください。 、renderメソッド
private void updateMVP(
float[] mModelMatrix,
float[] mViewMatrix,
float[] mProjectionMatrix,
float[] mMVPMatrix) {
// combine the model with the view matrix
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
// combine the model-view with the projection matrix
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
}
そして最後のオブジェクトをペイントするシェーダーを実行します:
public void onDrawFrame(GL10 gl) {
...
y += speed;
transform(mModelMatrix);
updateMVP(mModelMatrix, mViewMatrix, mProjectionMatrix, mMVPMatrix);
renderObject(mMVPMatrix);
...
}
updateMVP方法、モデル、ビューおよび投影行列を結合します
public void renderObject(float[] mMVPMatrix) {
GLES20.glUseProgram(mProgram);
...
// Pass the MVP data into the shader
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Draw the shape
GLES20.glDrawElements (...);
}
これがあなたを助けてくれることを願っています。
[OpenGLでローカル軸を中心にオブジェクトを回転させるにはどうすればいいですか?](http://stackoverflow.com/questions/1671210/how-to-rotate-object-around-local-axis-in-opengl)これは質問(と答え)は古いGL固定関数を使うかもしれませんが、その背後にある数学はあなたがやっていることとまったく同じです。 –
私は実際には、その質問から私の問題の解決策を見つけることができません – nifuki