switching between Perspective and Orthographic

Hello,

I am doing a little gl viewer and i would like to be able to switch from Perspective to Orthographic projections and vice-versa.

I having difficulties to tune the calls to glFrustum and glOrtho to have a nice change.

I am just using a factor on frustums extents like :

double f = 1000;
if (mPerspective)
glFrustum( -fW, fW, -fH, fH, zNear, zFar );
else
glOrtho(f*-fW, ffW, f-fH, f*fH, zNear, zFar );

I dont really like this approach as the factor is tuned ‘by hand’

I guess there is a better way to do it.
Any suggestions ?
Thx

Precalculate the bounding box of the object you are viewing and then set the projection matrices such that the viewing frustum fits the bounding box.

Nico

Well the problem is that i am not viewing a particular object so i cant say : “frustum must fit bounding box”…

When i change the projection type, i want to keep my (eyePos, lookAt, upDir). I thought that calling glOrtho / glFrustum with the same args would do the job. It does not. :frowning:

Any more suggestions or pointers ?
Thx

For some strange reason I get this feeling you aren’t switching to the projection matrix before setting your ortho/perspective modes. Remember to change back to the modelview once you are done. You should be able to keep your eyepos and whatnot because that is in the ModelView matrix. If you enter ortho or projection matricies in the modelview matrix, your lighting calculations will not come out right (I don’t know if you are using them or not). Hope I have helped some.

Well I am currently setting the matrix correctly.

It’s now working not bad, still not perfect…

By the way I checked 3dsmax : the switch from perspective to ortho is nice most of the time but in some cases, you “loose” the view…

Here is how i go now :
height = tan(fov/2) * (far+near)/4;
glOrtho(-heightaspect, heightaspect, -height, height, near, far);

One should get better result with lower far value.