Sign in to follow this  

zooming and scaling the camera

This topic is 3861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, hope to have choosed the right type of forum to post this topic. I have some problem with the zoom and scale functions for my camera. I have an object (vertex+normals+texture) and i have to zoom in/out and scale it: when i scale it, the camera should scale on y,z value too, so the object is shown on camera with about the same size; while zoom in/out should let the z value of the camera decrease/increase so the object will be shown bigger/shorter. Some code: const float piover180 = 0.0174532925f; // convert radiant into grades Methods for zoom: // zoom out void Camera::zoomOut() { zorig += (float)cos(piover180) * 0.1f; zpos = zorig; } // zoom in void Camera::zoomIn() { zorig -= (float)cos(piover180) * 0.1f; zpos = zorig; } Method for scale: // scale camera void Camera::scaleCamera(float scale) { zpos = zorig * scale; ypos = yorig * scale; } Method that set the camera position every frame refresh: // set camera position void Camera::setPosition() { glTranslatef(0.0f, -ypos, -zpos); ... } If i run it, if i zoom in/out and then scale, there are no problems, since the camera start to scale from the z value where the camera zoomed in/out; while if i zoom in/out after the scale, camera jump to an unexpected z value. What am i missing? Thanks in advance for any help

Share this post


Link to post
Share on other sites
Couple of things. Scale is an operation that should affect the objects in your scene, not the camera. And zooming is a function of the field of view of the camera, it has nothing to do with the position of the camera. Think about the zoom feature on a real camera. When you zoom in, you are not moving the camera closer to the objects, you are simply changing the field of view of the lens. You can scale your objects using glScale, and you can set the field of view of the camera using gluPerspective. Hope that helps.

Share this post


Link to post
Share on other sites
can you post any code example? i'm starting from nehe framework, but honestly i don't know how i could change the gluPerspective every time a key is pushed, and which parameters to give to it..
Thanks in advance

Share this post


Link to post
Share on other sites

This topic is 3861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this