When moving the camera / eye-point closer into the scene you get something that looks like zooming due to the perspective foreshortening. As is already mentioned, this is not a "real" zoom. E.g. you move the clipping volume together with the camera, and hence geometry near to the camera may disappear while geometry far from the camera may pop up. And that this works at all in perspective mode only is already noticed.
Because depth of field is usually neglected anyway, I don't see a reason why zooming is not to be simulated simply by scaling the scene in the horizontal and vertical dimensions of the view space. I.e. if V
denotes the view matrix computed like before (from gluLookAt or whatever), then prepending a scaling S
to yield in a new view matrix like soS
( z, z, 1 ) * V
where z denotes the zoom factor should do the trick.
The above is independent of the mode of projection. The scaling S
may, however, also be attached to the projection, because OpenGL prepends projection matrix P
to the view matrix like soP
* ( S
( z, z, 1 ) * V
and due to associativity, that can be computed as
( z, z, 1 ) ) * V
as well. However, this is a question of optimization only. If the zoom is static, than attaching it to the projection matrix is advantageous. In the more likely situation that the zoom will change frequently, attaching it to the view matrix is more efficient.
You're not actually zooming in if you're using "Translatef", which is what Lee said. Do you know what the different parameters of gluLookAt do? To zoom in, you can move the eye point closer to the look at point.
I use this for "zooming in" on my system:
int vx = mLookPoint - mPosition;
int vy = mLookPoint - mPosition;
int vz = mLookPoint - mPosition;
mPosition += vx * 0.01;
mPosition += vy * 0.01;
mPosition += vz * 0.01;
Moving the eye-point is actually a translation
. Not only that, it is further a translation at the same stage in processing as the OP already does.
And then in my rendering call I have
gluPerspective(mPosition, mPosition, mPosition, mLookPoint, mLookPoint, mLookPoint, 0, 1, 0);
This is an incorrect combination of a routine name and a set of parameters. You probably mean gluLookAt instead of gluPerspective.