我正在尝试将我的文本模型网格定位在屏幕上。使用下面的代码,它按照代码建议绘制网格;网格的左侧位于屏幕的中心。但是,我想把它放在屏幕边缘的左边,这就是我卡住的地方。如果我取消注释 Matrix.translateM 行,我会认为该位置现在将位于屏幕的左侧,但似乎该位置正在被缩放(!?)
我尝试过的几个场景:
a.)仅 Matrix.scaleM(无 Matrix.translateM)= 网格左侧位于 0.0f(屏幕中心),具有正确的比例。
b.)仅 Matrix.TranslateM(无 Matrix.scaleM)= 网格左侧正确定位在屏幕左侧 -1.77f,但缩放不正确。
c.) Matrix.TranslateM 然后 Matrix.scaleM或Matrix.scaleM 然后 Matrix.TranslateM =比例正确,但位置不正确。似乎该位置已缩放,并且比屏幕左侧更靠近中心。
我在 Java 的 Android Studio 编程中使用 OpenGL ES 2.0。
屏幕边界(从 Matrix.orthoM 设置)左侧:-1.77,右侧:1.77(中心为 0.0),顶部:-1.0,底部:1.0(中心为 0.0)
网格高度为 1.0f,因此如果没有 Matrix.scaleM,则网格占据整个屏幕高度。
float ratio = (float) 1920.0f / 1080.0f;
float scale = 64.0f / 1080.0f; // 64px height to projection matrix
Matrix.setIdentityM(modelMatrix, 0);
Matrix.scaleM(modelMatrix, 0, scale, scale, scale); // these two lines
//Matrix.translateM(modelMatrix, 0, -ratio, 0.0f, 0.0f); // these two lines
Matrix.setIdentityM(mMVPMatrix, 0);
Matrix.orthoM(mMVPMatrix, 0, -ratio, ratio, -1.0f, 1.0f, -1.0f, 1.0f);
Matrix.multiplyMM(mMVPMatrix, 0, mMVPMatrix, 0, modelMatrix, 0);