I have a dataset which contains nodes, edges, faces & volumes. I calculate the maximum & minimum x,y,z values of the data & get the radius of the bounding sphere.
I use the radius & the camera distance from 0,0,0 to calculate the near & far clipping values like this:
double cameraDist = distance from camera to origin(0,0,0)
farClip = ( cameraDist + radius );
if ( cameraDist > radius )
nearClip = ( ( cameraDist - radius ) );
else
nearClip = ( ( cameraDist / radius ) );
::glMatrixMode( GL_PROJECTION );
::glLoadIdentity();
gluPerspective( fieldOfView, aspectRatio, nearClip, farClip );
::glMatrixMode( GL_MODELVIEW );
::glLoadIdentity();
For the most part, this works fine as I zoom in & out. However, for a couple of datasets, the first few times the nearclip is calculated in the else statement, some far polygons are being clipped. As I keep zooming in, they come back & it looks ok.
If I calculate the nearclip as
nearClip = farClip / 1.0e3;
this problem goes away, but I can’t zoom in as close.
Any ideas on how else to calculate the near clipping plane?