Perspective Projection with OpenGL

后端 未结 3 873
庸人自扰
庸人自扰 2021-02-08 14:44

I am confused about perspective projection.

Here is the scenario that is confusing me. My frustrum\'s front plane is basically positioned at at positive z-axis and the b

3条回答
  •  一整个雨季
    2021-02-08 15:06

    Now, whenever I go through examples I see that the near and the far plane are all present in the -ive z axis.

    Of course. Otherwise you would get something like this

    :enter image description here

    All projection happens relative to the origin 0. near and far determine the distance of the clipping planes from the origin. left and right define the opening angle of the frustum together with the near plane. If you place a "near" and far plane in opposite directions of the origin, your projection space becomes shaped like an hourglass.

    glMatrixMode(GL_PROJECTION);    
    glLoadIdentity();
    glFrustrum(-xval,+xval,-yval,+yval,-10,+10);
    gluLookAt(); // some point lying on this axis of symmetry about the point
    glMatrixMode(GL_MODELVIEW);
    

    The projection is not meant to place the view. The projection is sort of the "lens" of your virtual camera. You can use it to tilt and shift your lens and set the "focal length". But it's not meant to "place your camera". This should happen through the modelview matrix.

    So, in the above case what is the behavior that I should expect for the glFrustum with a negative as well as positive value for z. i.e. in this case -10 to +10.

    From the far to the "near" plane, objects will become larger as they approach 0, for Z=0 they're in a singularity and blow up infinitely, and then getting closer to near they will become smaller but will be inverted, i.e. rotated by 180° around the Z axis, and depth values being turned around, i.e. depth sorting by depth testing will reject fragments closer to near than to 0.

提交回复
热议问题