Zooming: GL_MODELVIEW or GL_PROJECTION?

Hello everybody!

I am beginning to write a very very little and simple 3D
cad application (mainly using glOrtho()).

My first target is to be sure of my viewing transformations.

I have read, from the Red Book, chapter 3, “The Camera Analogy”:

  1. Setting up your tripod and pointing the camera at the scene
    (viewing transformation).
  1. Arranging the scene to be photographed into the desired composition
    (modeling transformation).
  1. Choosing a camera lens or adjusting the zoom
    (projection transformation).

  2. Determining how large you want the final photograph to be -
    for example, you might want it enlarged
    (viewport transformation).

So, after some tries, I have a piece of code where I do rotations
and translations with glMatrixMode(GL_MODELVIEW);

and, as You can read in point 3), scaling (zooming) in mode GL_PROJECTION,
changing the parameters of glOrtho().

Now the question, especially for zooming:

Is this the best way to do this things?

Will I have problems in the future with this approach?

Thanks in advance,
Rogxx

Sounds like you’re generally on the right track, but it’s unclear exactly what you’re loading on the PROJECTION matrix. glOrtho, gluOrtho2D, glFrustum, gluPerspective. Any of these (alone on top of an glLoadIdentity) is good. glScale? Now that’s not good. That’s called “Projection Abuse”.

http://www.sjbaker.org/steve/omniv/projection_abuse.html

Just to be clear, there are a few ways to “zoom” on object (i.e. make something appear bigger on the screen. One is to reduce the size of the frustum. You can do that with the Ortho or Frustum calls (on the PROJECTION stack of course) reducing right-left and/or top-bottom. Or you can do it with Frustum (again, on PROJECTION stack) by pushing near out. Or you can do it with Perspective in the obvious way of reducing fovy and/or aspect.

Another way to “zoom” (when you have a perspective transform active on the PROJECTION stack) is to just use the MODELVIEW stack to move the eyepoint closer to the object (i.e. change the VIEWING transform) or move the object closer to the eyepoint (i.e. change the MODELING transform). Then its apparent size increases in your field of view. You could do the former with gluLookAt and the latter with glTranslate on the MODELVIEW stack (at the appropriate time).

Yet another way to make an object bigger is to change it’s size via a scale transform on the MODELVIEW stack when you’re rendering your object. You could do this with glScale on the MODELVIEW stack for instance. I generally avoid this because it means you have to tell the GPU to normalize normals to get your lighting to work in your shader, not to mention that most real world objects don’t physically grow and shrink, but you can definitely do this.

Any of these are fine. Which one is better depends on your specific requirements for how things need to look in your application. For instance, how do other objects in the scene need to appear when you’re “zooming” that specific object?

Or you can do it with Frustum (again, on PROJECTION stack) by pushing near out.

That doesn’t really cause zooming though. It just cuts out more stuff in front.

Thank You very much for the replies.

Dark Photon wrote:

but it’s unclear exactly what you’re loading on the PROJECTION matrix. glOrtho, gluOrtho2D, glFrustum, gluPerspective.

I mainly prefer to use glOrtho(), to have a “parallel projection view”, like users of mechanical cad applications often prefer. I have to study better glFrustum, to add the option of a perspective view.

You can do that with the Ortho or Frustum calls (on the PROJECTION stack of course) reducing right-left and/or top-bottom.

Yes, when the user interact with the mouse to get zooming, it changes a zooming parameter that modify the right-left and top-bottom values of the call to glOrtho (and near-far too, because of clipping), with respect of the aspect ratio between height and width (glViewport).

Yet another way to make an object bigger is to change it’s size via a scale transform on the MODELVIEW stack when you’re rendering your object.


For instance, how do other objects in the scene need to appear when you’re “zooming” that specific object?

I prefer not to use this approach, because I want to manage separately the viewing transformation to render the scene (using Opengl) from the mathematical rapresentation of my objects (not using Opengl), ie if I want to scale an object I change it’s mathematical definition, it is not a viewing problem.
For zooming, my doubt was between using the glOrtho/glFrustum/GL_PROJECTION approach or the glScale/GL_MODELVIEW approach(but for the entire scene),

Regards,
rogxx

No, think about it. Where are the L,R,B,T values defined with a perspective Frustum transform? On the near clip plane. Push the near clip plane out (while leaving L,R,B,T alone), and you just reduced your FOV (which of course makes things in the center of the frustum bigger in the new FOV).

…unless I’m missing something obvious which is certainly possible.