我有一个简单的OpenGl es cube,在Android上运行。我已经设置了一个简单的旋转,但现在我想缩放对象。我认为添加一个比例矩阵并将其与我对其他矩阵相乘,会产生预期的结果。 无论如何,它没有。这是班级
public class Render implements Renderer {
//fields
private Triang tri;
private Quad qua;
private Cube cu;
private float [] mIden = new float[16];
private float [] mPro = new float [16];
private float [] mCamera = new float [16];
private float [] mResult = new float [16];
private float [] mResult2 = new float [16];
private float [] mResult3 = new float [16];
private float [] mRot = new float [16];
private float [] mScale = new float [16];
private float an;
//methods
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
tri = new Triang();
qua = new Quad();
cu = new Cube();
}
//I think the problem is in this Ondraw frame method
public void onDrawFrame(GL10 unused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
Matrix.setLookAtM(mCamera, 0, i, 0f, -3f, 0f, 0f, 0f, 0f, 1f, 0f);
long tempo = SystemClock.uptimeMillis() % 4000L;
float an = 0.090f * ((int)tempo);
public void onDrawFrame(GL10 unused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
Matrix.setIdentityM(mIden, 0);
Matrix.setLookAtM(mCamera, 0, i, 0f, -3f, 0f, 0f, 0f, left, up, z);
long tempo = SystemClock.uptimeMillis() % 4000L;
float an = 0.090f * ((int)tempo);
Matrix.multiplyMM(mResult, 0, mPro, 0, mCamera, 0);
Matrix.scaleM(mScale, 0, 10.1f, 1f, 1f);
Matrix.multiplyMM(mResult2, 0, mScale, 0, mResult, 0);
Matrix.setRotateM(mRot, 0, an, 0f, 1f, 0);
Matrix.multiplyMM(mResult3, 0, mRot, 0, mResult, 0);
//qua.draw(mResult2);
//tri.draw(mResult2);
cu.draw(mResult3);
//qua.draw(mResult2);
//tri.draw(mResult2);
cu.draw(mResult3);
}
public void onSurfaceChanged(GL10 unused, int width, int height) {
GLES20.glViewport(0, 0, width, height);
float ratio = (float) width/height;
Matrix.frustumM(mPro, 0, ratio, -ratio, -1, 1, 1, 10);
}
public static int loadShader (int tipo, String code) {
int shader = GLES20.glCreateShader(tipo);
GLES20.glShaderSource(shader, code);
GLES20.glCompileShader(shader);
return shader;
}
}
我尝试更改mScale和mResult2的顺序,在上一次编辑中,我还设置了模型标识,但多维数据集的大小没有变化。