我最近查看了developers.android.com 提供的OpenGL ES 2.0 教程。我成功地完成了它(即使不是很清楚),但后来我遇到了一个问题。当我完成它后,我从未被告知如何平移或缩放对象。我尝试了目前看来合乎逻辑的不同选择,但它们不起作用。我对 Android 中的 OpenGL ES 2.0 不太有经验。
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
long time = SystemClock.uptimeMillis() % 4000L;
mAngle = 0.090f * ((int) time);
Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);
Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);
t.draw(mMVPMatrix);
所有这些矩阵都是大小为 16 的 float 组。我的问题是,如何使用 x 和 y 位置以及 sam 进行缩放(带有缩放的 float )?似乎有 setTranslateM 方法,当我尝试其他方法时,我无法使它们工作。我该怎么办?
最佳答案
要平移/缩放/旋转对象,您应该将这些操作应用于模型矩阵。
示例:
Matrix.setIdentityM(mMMatrix, 0); // reset transformations
Matrix.setRotateM(mMMatrix, 0, 0, 1.0f, 0, 0); // set rotation
Matrix.translateM(mMMatrix, 0, 10.0f, 20.0f, 0); // apply translation
Matrix.scaleM(mMMatrix, 0, 0.25f, 0.25f, 0.25f); // apply scale
请注意,Matrix
类的某些静态方法会执行内存分配,因此如果您在每个帧上进行对象转换,您可能不希望使用它们。在这里阅读更多相关信息http://groups.google.com/group/android-developers/browse_thread/thread/b30dd2a437cfb076?pli=1在我的博客文章中 http://androidworks-kea.blogspot.com/2012/05/developers-notes-about-opengl-es.html
关于java - Android 中 OpenGL ES 2.0 形状的翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14187300/