2012-08-02 42 views
0

其实Im做这在我的渲染器类的绘制方法:如何在Android(Java)和OpenGL ES 2.0旋转

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); 

回答

2

为什么Matrix.rotateM在Matrix.setRotateM之后?第二个禁用第一个。

在这里,我用我的引擎的伪代码:

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); 

希望它可以帮助;-)

+0

我会尽力感谢。 – Enriquillo 2012-08-02 20:07:34

+0

我做了更改,并得到了相同的结果。其他一些建议? – Enriquillo 2012-08-03 14:43:23

+0

我发现这个链接[http://www.programforandroid.com/android-programming-tutorials/opengl-es-2-0/]如何解释一个垃圾更好的android开发人员示例。我和它的作品:)。我的问题是在着色器代码形式的对象.... – Enriquillo 2012-08-04 19:44:53