我想绘制一个立方体并进行翻译,但模型视图矩阵的转换似乎不起作用。他们有0效果。
gl.glClearColor(0, 0, 0, 0);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
gl.glFrustum(-10, 10, -10, 10, 0.01, 20);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslated(0.8, 0, 0); //no effect
gl.glRotated(30, 1, 0, 0); //no effect
drawCube(gl);
public void drawCube(GL gl) {
gl.glMatrixMode(GL.GL_MODELVIEW);
//spate
gl.glLoadIdentity();
drawSquare(gl);
//fata
gl.glLoadIdentity();
gl.glTranslated(0, 0, WIDTH);
drawSquare(gl);
//st
gl.glLoadIdentity();
gl.glRotated(-90, 0, 1, 0);
drawSquare(gl);
//dr
gl.glLoadIdentity();
gl.glRotated(-90, 0, 1, 0);
gl.glTranslated(0, 0, -WIDTH);
drawSquare(gl);
//sus
gl.glLoadIdentity();
gl.glRotated(90, 1, 0, 0);
drawSquare(gl);
//jos
gl.glLoadIdentity();
gl.glRotated(90, 1, 0, 0);
gl.glTranslated(0, 0, -WIDTH);
drawSquare(gl);
}
public void drawSquare(GL gl) {
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
gl.glBegin(GL.GL_POLYGON);
gl.glTexCoord2d(0, 0);
gl.glVertex3d(0, 0,0);
gl.glTexCoord2d(0, 1);
gl.glVertex3d(0, WIDTH,0);
gl.glTexCoord2d(1, 1);
gl.glVertex3d(WIDTH, WIDTH,0);
gl.glTexCoord2d(1, 0);
gl.glVertex3d(WIDTH, 0,0);
gl.glEnd();
}
答案 0 :(得分:3)
在drawCube()
内,您正在重置模型视图矩阵:
gl.glMatrixMode(GL.GL_MODELVIEW);
//spate
gl.glLoadIdentity();
我怀疑你想在这里使用glPushMatrix()
和glPopMatrix()
。
作为旁注:自OpenGL 3.1以来,这些操作已被弃用。