作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
实际上,我在渲染器类的绘制方法中执行此操作:
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);
希望有帮助;-)
关于java - 如何在 Android (java) 和 OpenGL ES 2.0 上旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11769566/
我是一名优秀的程序员,十分优秀!