2

我有一个init()方法,我正在尝试创建一个Perspective渲染。下面是我到目前为止的代码,但我传递给的数字gluPerspective(fovy, aspect, zNear, zFar)是错误的。我认为fovy是视野(60度),并且是纵横比(宽度/高度) ,aspect但我不知道是什么。zNearzFar

public void init(GLAutoDrawable gld) {
    //We will  use the default ViewPort

    GL gl = gld.getGL();
    glu = new GLU();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);


    glu.gluLookAt(
            25, 15, 0, // eye
            25, 15, 30, // at
            0, 1, 0 // up
            );



    // Set up camera for Orthographic projection:
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(60, 500/300, 0.0, 60.0);

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glLoadIdentity();

}
4

2 回答 2

2

Near and far values specify the range in which objects are visible (they define the near and far clipping planes). Indeed objects more far than 60.0 will not be visible using that perspective.

As Tim as already commented, it's bettere to explicitly write floating point values (i.e. 500.0f/300.0f).

But worse, you setup the look-at matrix before setting it to identity (assuming that at the beginning of the method the matrix mode is GL.GL_MODELVIEW). Probably it is better the following sequence:

gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(...);

Maybe you need to investigate more about the camera abstraction.

于 2012-03-15T18:20:34.427 回答
0

就像卢卡已经说过的,近和远定义了可见物体的范围。但最重要的是,永远不要将值 <= 0 用于近值或远值(您当前使用的值),因为这将导致奇异投影矩阵(会产生任何奇怪的渲染结果)。

为近裁剪平面使用一些合理的小值,但不要太小,因为这会导致深度缓冲区精度不佳。使用合理的东西,例如在模拟一个普通的现实世界时,10cm 的近距离通常是一个不错的选择(无论这在实际应用中意味着多少通用单位),因为你不会让你的眼睛更靠近任何物体. 但这取决于您的应用程序,例如远值。

当然,就像蒂姆说的那样,目前你的纵横比是 1.0,因为你做整数除法。

于 2012-03-15T20:51:46.693 回答