0

我有每个侧锁颜色不同的立方体 -

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

在这种状态下——我得到的数字是——

在此处输入图像描述

指位于立方体前面的摄像头。

由于我试图将相机设置在立方体内,因此我将 z 轴值更改glu.gluLookAt为 -glu.gluLookAt(0,0, 50, 0, 0, 0, 0, 1, 0);并且知道我得到的是 -

在此处输入图像描述

如果我改为 -glu.gluLookAt(0,0, 0, 0, 0, 0, 0, 1, 0);我会整个屏幕变黑。

因此,为了将相机设置在立方体内,我必须进行更改 - 意味着例外的图形在右、左上和下将是不同的颜色。

4

1 回答 1

5

glu.gluLookAt(0, 0, 0, 0, 0, 0, 0, 1, 0)似乎无效。尝试将其设置为 glu.gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0)

编辑:

  1. 消除glTranslatef

  2. 
    glu.gluPerspective(100, widthHeightRatio, 0.5, 1000);
    glu.gluLookAt(0, 0, 0.0, 0.0, 0, -1.0, 0, 1, 0);
    
于 2013-05-21T05:27:20.273 回答