0

I have cube which has different color to each side-lock -

public void display(GLAutoDrawable drawable) {

        final GL gl = drawable.getGL();
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);




        ///// SET CAMERA  /////  
        setCamera(gl, glu, 100);




        // /////// Cube - start ///////////

        // cube

        // ----- Render the Color Cube -----
        gl.glLoadIdentity(); // reset the current model-view matrix
        gl.glTranslatef(0f, 0.0f, -7.0f); // translate right and into the
                                                // screen
        gl.glRotatef(angleCube, 1.0f, 1.0f, 1.0f); // rotate about the x, y and
                                                    // z-axes

        gl.glBegin(GL.GL_QUADS); // of the color cube

        // Top-face
        gl.glColor3f(0.0f, 1.0f, 0.0f); // green
        gl.glVertex3f(1.0f, 1.0f, -1.0f);
        gl.glVertex3f(-1.0f, 1.0f, -1.0f);
        gl.glVertex3f(-1.0f, 1.0f, 1.0f);
        gl.glVertex3f(1.0f, 1.0f, 1.0f);

        // Bottom-face
        gl.glColor3f(1.0f, 0.5f, 0.0f); // orange
        gl.glVertex3f(1.0f, -1.0f, 1.0f);
        gl.glVertex3f(-1.0f, -1.0f, 1.0f);
        gl.glVertex3f(-1.0f, -1.0f, -1.0f);
        gl.glVertex3f(1.0f, -1.0f, -1.0f);

        // Front-face
        gl.glColor3f(1.0f, 0.0f, 0.0f); // red
        gl.glVertex3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(-1.0f, 1.0f, 1.0f);
        gl.glVertex3f(-1.0f, -1.0f, 1.0f);
        gl.glVertex3f(1.0f, -1.0f, 1.0f);

        // Back-face
        gl.glColor3f(1.0f, 1.0f, 0.0f); // yellow
        gl.glVertex3f(1.0f, -1.0f, -1.0f);
        gl.glVertex3f(-1.0f, -1.0f, -1.0f);
        gl.glVertex3f(-1.0f, 1.0f, -1.0f);
        gl.glVertex3f(1.0f, 1.0f, -1.0f);

        // Left-face
        gl.glColor3f(0.0f, 0.0f, 1.0f); // blue
        gl.glVertex3f(-1.0f, 1.0f, 1.0f);
        gl.glVertex3f(-1.0f, 1.0f, -1.0f);
        gl.glVertex3f(-1.0f, -1.0f, -1.0f);
        gl.glVertex3f(-1.0f, -1.0f, 1.0f);

        // Right-face
        gl.glColor3f(1.0f, 0.0f, 1.0f); // violet
        gl.glVertex3f(1.0f, 1.0f, -1.0f);
        gl.glVertex3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(1.0f, -1.0f, 1.0f);
        gl.glVertex3f(1.0f, -1.0f, -1.0f);

        gl.glEnd(); // of the color cube

        // /////// Cube - end //////////



    }

private void setCamera(GL gl, GLU glu, float distance) {
        // Change to projection matrix.
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();

        // Perspective.
        float widthHeightRatio = (float) getWidth() / (float) getHeight();
        glu.gluPerspective(1, widthHeightRatio, 1, 1000);
        glu.gluLookAt(0,0, 150, 0, 0, 0, 0, 1, 0);

        // Change back to model view matrix.
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

At this state - the figure I get is -

enter image description here

Means the camera located in front of the cube .

Since I trying to set the camera within the cube , I change the z-axis value in glu.gluLookAt to - glu.gluLookAt(0,0, 50, 0, 0, 0, 0, 1, 0); and know what I get is -

enter image description here

And if I change to - glu.gluLookAt(0,0, 0, 0, 0, 0, 0, 1, 0); I get whole screen black .

So , what I have to change in order to set the camera within the cube - means the excepted figure would be different color in right , left up and down .

URL87
  • 10,667
  • 35
  • 107
  • 174

1 Answers1

5

glu.gluLookAt(0, 0, 0, 0, 0, 0, 0, 1, 0) doesn't seem valid. Try setting it to glu.gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0)

EDIT:

  1. Remove glTranslatef

  2. 
    glu.gluPerspective(100, widthHeightRatio, 0.5, 1000);
    glu.gluLookAt(0, 0, 0.0, 0.0, 0, -1.0, 0, 1, 0);
    
Sergey Zyuzin
  • 3,754
  • 1
  • 24
  • 17