我想翻译窗口左侧的圆环,但我不知道导致它什么也没做的原因。这是一个代码:
public void display(GLAutoDrawable drawable) {
GL2 gl2 = drawable.getGL().getGL2();
gl2.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl2.glMatrixMode(GL2.GL_PROJECTION);
gl2.glLoadIdentity();
gl2.glColor3f(1.0f, 0f, 0f);
gl2.glPushMatrix();
gl2.glTranslatef(-5.5f, -0f, -10f);
gl2.glRotatef(30f, 1f, 1f, 1f);
gl2.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, FloatBuffer.wrap(QA_RED));
gl2.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, FloatBuffer.wrap(QA_RED));
gl2.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, FloatBuffer.wrap(QA_WHITE));
gl2.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, FloatBuffer.wrap(new float[]{30f}));
gl2.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, FloatBuffer.wrap(QA_RED));
gl2.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, FloatBuffer.wrap(QA_RED));
gl2.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, FloatBuffer.wrap(QA_WHITE));
gl2.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, FloatBuffer.wrap(new float[]{30f}));
glut.glutSolidTorus(0.1f, 0.2f, 10, 20);
gl2.glFlush();
}
如果我添加翻译方法torus消失,如果不是,我无法将其翻译为左侧。请问我有什么建议可以解决吗?
答案 0 :(得分:0)
如果您试图移动圆环,我怀疑您想要修改模型视图而不是投影矩阵。加载一个较大的正交投影矩阵,glOrtho
为两边提供更大的值,这样您就可以更好地看到圆环。然后确保切换到模型视图来操作它:
gl2.glMatrixMode(GL2.GL_PROJECTION);
gl2.glOrtho(100.0f, 100.0f, 100.0f, 100.0f, 0.1f, 100.0f);
gl2.glMatrixMode(GL2.GL_MODELVIEW);
gl2.glLoadIdentity();
gl2.glTranslatef...etc