ortho to perspective view switching

Hi, I’m fairly new to this game so bear with me.

I have a 3D CAD system which I’m developing and am switching between orhto and perspective views. The switch works but the zoom is wrong and doesn’t zoom (in and out) at the ssame rate as in ortho.

I’ve included the basic code below (where x and y are width and height)

glMatrixMode ( GL_PROJECTION );
gluPerspective ( 45.0, x / y, 0.00001, 100 * graphics.maxDim );
glMatrixMode ( GL_MODELVIEW );

Is there anything else that I need to do to get the switch to work properly??

Any help much appreacited


How are you zooming in and out in ortho? Are you using glTranslate with a value in the z parameter? If you are, this doesn’t work in glOrtho, as it is 2D. What you’ll have to do in Ortho mode is simply use glScale and scale everything to simulate zooming. Does anybody know if I’m wrong about this? But this is what I’ve always done.

The zoom in the ortho works fine, I’m doing it by using “glScalef”, its the switch to perspective that doesn’t work properly. When I switch it zooms in to the object and then the zoom in and out (using “glTranslatef”) is very small (I use the mouse button and actions to zoom).

Because of perspective, there is no direct link between scaling (zooming) and travelling back and forth the camera.

In 3dsmax for ex, they do the conversion dynamically based on the scene size, and sometimes it does exhibit the same annoying behavior as yours (very small zomm in/out in perspective).

(side note : when movie directors started to actually move forward the camera instead of zomming optically, it was a really great step in the history of cinema)

PS: you can try to take in account the distance to the object beeing viewed, divide that distance by your zoom factor, and place the camera at this new distance.

[This message has been edited by ZbuffeR (edited 01-14-2004).]