-2

I want to translate the torus left side of the window, but I don't figure out what is causing that it does not do anything. Here is a code:

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();
}

If I add translate method torus disappears, if not I can't translate it to left side. Please any advice how I can solve it?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Lion
  • 15
  • 1
  • 3

1 Answers1

0

I suspect you want to modify the modelview instead of the projection matrix if you're attempting to move your torus around. Load a larger orthographic projection matrix with glOrtho supplying larger values for the sides so you can see your torus better. Then make sure to switch to the modelview to manipulate it:

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
Ron Warholic
  • 9,994
  • 31
  • 47