I am writing an application for space exploration. I decided that light years are units and accurately simulate the distances between stars. After messing around and a lot of hard work (mainly studying the ropes), I have a camera that works correctly from the point of view of a spaceship passing through space.
At first, I did not pay attention to the zNear gluPerspective () parameter until I worked on planetary objects. Since my scale is in light year units, I soon realized that due to zNear being 1.0f, I would not be able to see such objects. After the experiment, I came to these numbers:
#define POV 45 #define zNear 0.0000001f #define zFar 100000000.0f gluPerspective (POV, WinWidth/WinHeight, zNear ,zFar);
This works exceptionally well because I was able to cruise my solar system (position 0,0,0) and move up close to planets that look superbly lit and textured. However, other systems (not in the 0, 0, 0 position) were much more difficult to travel because the objects suddenly moved away from the camera.
I noticed, however, that strange visual glitches began to occur when traveling through the universe. The objects behind me will โturn aroundโ and appear in front, if I swing 180 degrees in the Y direction, they will also appear in their original place. Therefore, when there is a skew in space, most stars correctly parallax, but some appear and move in the opposite direction (which, at least, causes concern).
Changing zNear to 0.1f immediately fixes ALL of these glitches (but will also not allow objects in the solar system). So I'm stuck. I also tried working with glFrustum and it gives exactly the same results.
To view the world, I use the following:
glTranslatef(pos_x, pos_y, pos_z);
With the appropriate camera code for orientation as needed. Even disabling camera functionality does not change anything. I even tried gluLookAt () and again it gives the same results.
Are there gluPerspective () restrictions when using extreme zNear / zFar values? I tried to reduce the range, but to no avail. I even changed my world units from light years to kilometers, scaling everything and using the larger zNear value - nothing. HELP!