Jump to content
  • Advertisement
Sign in to follow this  
hanz0

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.

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
Advertisement
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
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!