Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: How to calculate near and far plane for glOrtho in OpenGL ?

  1. #1
    Newbie Newbie
    Join Date
    May 2017
    Posts
    1

    How to calculate near and far plane for glOrtho in OpenGL ?

    I am using orthographic projection glOrtho for my scene. I implemented a virtual trackball to rotate an object beside that I also implemented a zoom in/out on the view matrix. Say I have a cube of size 100 unit and is located at the position of (0,-40000,0) far from the origin. If the center of rotation is located at the origin once the user rotate the cube and after zoom in or out, it could be position at some where (0,0,2500000) (this position is just an assumption and it is calculated after multiplied by the view matrix). Currently I define a very big range of near(-150000) and far(150000) plane, but some time the object still lie outside either the near or far plane and the object just turn invisible, if I define a larger near and far clipping plane say -1000000 and 1000000, it will produce an ungly z artifacts. So my question is how do I correctly calculate the near and far plane when user rotate the object in real time? Thanks in advance!

    Update:
    I have implemented a bounding sphere for the cube. I use the inverse of view matrix to calculate the camera position and calculate the distance of the camera position from the center of the bounding sphere (the center of the bounding sphere is transformed by the view matrix). But I couldn't get it to work. can somebody further explain what is the relationship between the camera position and the near plane?
    Last edited by michealgoh; 05-14-2017 at 07:51 AM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,124
    It sounds like you're on the right track. Using simple bounding primitives for your objects (e.g. spheres or OBBs). Transform these bounding primitives into eye-space. Once in eye-space, determine the min/max Z used. That'll suggest what depth range your near and far planes should encompass.

    Keep in mind that dynamically changing your near and far planes every frame can cause differences in the depth values computed and thus in depth testing. So if visual quality is a big concern, you can take steps to avoid changing your depth range more than necessary.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •