我有立方体,每个侧锁具有不同的颜色 -
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();
}
在这种状态下 - 我得到的数字是 -
表示相机位于立方体前方。
由于我尝试将相机设置在多维数据集中,我将glu.gluLookAt
中的z轴值更改为 - glu.gluLookAt(0,0, 50, 0, 0, 0, 0, 1, 0);
并知道我得到的是 -
如果我换到 - glu.gluLookAt(0,0, 0, 0, 0, 0, 0, 1, 0);
,我会全屏变黑。
所以,为了将相机设置在立方体内,我必须改变 - 意味着例外的数字在右上,左上和下都是不同的颜色。
答案 0 :(得分:5)
glu.gluLookAt(0, 0, 0, 0, 0, 0, 0, 1, 0)
似乎无效。尝试将其设置为
glu.gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0)
编辑:
删除glTranslatef
glu.gluPerspective(100, widthHeightRatio, 0.5, 1000);
glu.gluLookAt(0, 0, 0.0, 0.0, 0, -1.0, 0, 1, 0);