# zooming and scaling the camera

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

## 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 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 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..

##### Share on other sites
You can find those functions and how to use them here:

http://fly.cc.fer.hr/~unreal/theredbook/

-me

##### Share on other sites
i use gluPerspective in the ReshapeGL function already but it gets a fixed value (45). I can't get it to work getting a dynamic value based on current zoom in/out

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633269
• Total Posts
3011152
• ### Who's Online (See full list)

There are no registered users currently online

×