简体   繁体   English

OpenGL JOGL摄像头透视

[英]OpenGL JOGL camera perspective

i have drawn three boxes each same size but having different distance from camera. 我画了三个相同尺寸但与相机距离不同的盒子。 these boxes ought to be perceived as decreasing in size as they are moving away from the camera. 当这些盒子远离相机时,它们的大小应该会减小。 how do i acheive this illusion of distance. 我如何实现这种距离的幻觉。

//these are the three planes for boxes //这些是盒子的三个平面

  // 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);

//and this is eye at up code. //这是关注代码。

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

You need to use perspective projection, instead of orthographic projection. 您需要使用透视投影,而不是正投影。

Instead of calling 而不是打电话

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

You should be able to replace that line with 您应该可以用该替换该行

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

The arguments I provided might not be correct for your program, so you might need to adjust them. 我提供的参数可能不适合您的程序,因此您可能需要调整它们。

The arguments, in order, are: fovy, aspect, zNear and zFar. 根据顺序,参数是:fovy,aspect,zNear和zFar。

From the manpage : 联机帮助页

fovy: Specifies the field of view angle, in degrees, in the y direction. fovy:指定y方向的视角范围(以度为单位)。

aspect: Specifies the aspect ratio that determines the field of view in the x direction. aspect:指定确定x方向视图的宽高比。 The aspect ratio is the ratio of x (width) to y (height). 纵横比是x(宽度)与y(高度)的比率。

zNear: Specifies the distance from the viewer to the near clipping plane (always positive). zNear:指定从查看器到近剪裁平面的距离(始终为正)。

zFar: Specifies the distance from the viewer to the far clipping plane (always positive). zFar:指定从查看器到远剪裁平面的距离(始终为正)。

The GLU class is located here GLU课程位于此处

import javax.media.opengl.glu.GLU

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM