簡體   English   中英

如何在Android(java)和OpenGL ES 2.0上旋轉

[英]How to rotate on Android (java) and OpenGL ES 2.0

實際上,我是在我的渲染器類的draw方法中執行此操作的:

    Matrix.setIdentityM(mMMatrix, 0);
//      Rotate view

long time = SystemClock.uptimeMillis()*4000L;
float angle = .09F*(int)time;
Matrix.setRotateM(mMMatrix, 0, angle, 1, 0, 0);
Matrix.rotateM(mMMatrix, 0, -2f, 1, 0, 0);
//Matrix.scaleM(mMMatrix, 0, 0.01f, 0.01f, 0.01f);

// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0);

// Draw Shapes      
obj.draw(mMVPMatrix);

但這是行不通的...我嘗試了其他方法但沒有運氣,對象保持不變,沒有旋轉。

更新:我將代碼更改為此,沒有運氣。

        // Clear Screen
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);


        Matrix.setIdentityM(mMMatrix, 0);

        // Rotate view
        Matrix.setRotateM(mMMatrix, 0, angle, 1, 0, 0);
        //Matrix.scaleM(mMMatrix, 0, 0.01f, 0.01f, 0.01f);

        // Calculate the projection and view transformation
        Matrix.multiplyMM(mMVMatrix, 0, mVMatrix, 0, mMMatrix, 0);
        Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVMatrix, 0);

        // Draw Shapes      
        obj.draw(mMVPMatrix);

為什么在Matrix.setRotateM之后使用Matrix.rotateM? 第二個禁用第一個。

這是我在引擎中使用的偽代碼:

Matrix.setIdentityM(_model_matrix, 0);

Matrix.setRotateM(_rotation_x_matrix, 0, _angles.getX(), 1, 0, 0);
Matrix.setRotateM(_rotation_y_matrix, 0, _angles.getY(), 0, 1, 0);
Matrix.setRotateM(_rotation_z_matrix, 0, _angles.getZ(), 0, 0, 1);
Matrix.multiplyMM(_model_matrix, 0, _rotation_x_matrix, 0, _model_matrix, 0);
Matrix.multiplyMM(_model_matrix, 0, _rotation_y_matrix, 0, _model_matrix, 0);
Matrix.multiplyMM(_model_matrix, 0, _rotation_z_matrix, 0, _model_matrix, 0);

Matrix.multiplyMM(_modelview_matrix, 0, _view_matrix, 0, _model_matrix, 0);
Matrix.multiplyMM(_modelviewprojection_matrix, 0, _projection_matrix, 0, _modelview_matrix, 0);

希望能幫助到你 ;-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM