0

我正在尝试编写一个可以翻译三角形的 Android 应用程序,我使用了 来自 Google 的http://developer.android.com/training/graphics/opengl/motion.html代码,但是当我替换了

Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);

Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

Matrix.translate(mMVPMatrix,0,dx,dy,0);

三角形也在 Z 轴上移动,看起来根本不像平移

我能做些什么 ?

4

2 回答 2

3

以下代码:

Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);
Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

方法:

mRotationMatrix <-- Create a rotation matrix of mAngle degrees around axis -Z
mMVPMatrix <-- The product of mRotationMatrix and mMVPMatrix

而以下:

Matrix.translate(mMVPMatrix,0,dx,dy,0);

方法:

mMVPMatrix <-- Translate mMVPMatrix of dx along X axis and dy along Y axis

我假设 mMVPMatrix 是透视投影(MVP 的 P 通常表明这一点)。通常你不会翻译已经投影的东西。请尝试以下操作:

Matrix.setIdentityM(mTranslationMatrix, 0);
Matrix.translateM(mTranslationMatrix, 0, dx, dy, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mTranslationMatrix, 0, mMVPMatrix, 0);
于 2013-07-02T14:24:09.317 回答
1

我不认为你想翻译你的 MVP 矩阵,你想创建一个单位矩阵,翻译它,然后将它与mMVPMatrix.

于 2013-07-02T14:11:34.770 回答