有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java OpenGL JOGL相机透视图

我画了三个盒子,每个盒子大小相同,但距离相机的距离不同。当这些盒子从摄像机移开时,它们的尺寸应该会减小。我该如何实现这种距离的幻觉

//这是盒子的三个平面

  // first plane
  gl.glVertex3i(0, 30, 30);
  gl.glVertex3i(10, 30, 30);
  gl.glVertex3i(10, 20, 30);
  gl.glVertex3i(0, 20, 30);

  //2nd Plane
  gl.glVertex3i(20, 20, 37);
  gl.glVertex3i(30, 20, 37);
  gl.glVertex3i(30, 10, 37);
  gl.glVertex3i(20, 10, 37);

  //3rd Plane
  gl.glVertex3i(40, 10, 45);
  gl.glVertex3i(50, 10, 45);
  gl.glVertex3i(50, 0, 45);
  gl.glVertex3i(40, 0, 45);

//这是眼看向上的代码

gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(
              35, 15,  10, 
              25, 15, 30, 
      0,  1,  0   
              );

gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(-50.0, 50.0, -30.0, 30.0, 0.0, 60.0);

共 (1) 个答案

  1. # 1 楼答案

    你需要使用透视投影,而不是正交投影

    而不是打电话

    gl.glOrtho(-50.0, 50.0, -30.0, 30.0, 0.0, 60.0);
    

    你应该可以用

    GLU glu = new GLU();
    glu.gluPerspective(60.0, 4.0/3.0, 1.0, 100.0);
    

    我提供的参数可能不适合您的程序,因此您可能需要调整它们

    这些论点依次是:fovy、aspect、zNear和zFar

    manpage开始:

    fovy: Specifies the field of view angle, in degrees, in the y direction.

    aspect: Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height).

    zNear: Specifies the distance from the viewer to the near clipping plane (always positive).

    zFar: Specifies the distance from the viewer to the far clipping plane (always positive).

    GLU课程就在这里

    import javax.media.opengl.glu.GLU