Results 1 to 4 of 4

Thread: Change zoom from dolly to "real" zoom

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2013

    Change zoom from dolly to "real" zoom

    I'm trying to change the zoom effect in my application to be based on a change of FoV instead of just a z-translation which is called dolly. User input should be the basis so my current code looks as follows:

    Code :
    void setupMatrices()
    	// Set ProjectionMatrix
    	projectionMatrix = glm::perspective(90.0f, (GLfloat)width / (GLfloat) height, 0.1f, 1000.f);
    	glBindBuffer(GL_UNIFORM_BUFFER, globalMatricesUBO);
    	glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), glm::value_ptr(projectionMatrix));
    	glBindBuffer(GL_UNIFORM_BUFFER, 0);
    	// Set ModelViewMatrix
    	glm::mat4 identity        = glm::mat4(1.0); // Start with the identity as the transformation matrix
    	glm::mat4 pointTranslateZ = glm::translate(identity, glm::vec3(0.0f, 0.0f, -translate_z)); // Zoom in or out by translating in z-direction based on user input 
    	glm::mat4 viewRotateX     = glm::rotate(pointTranslateZ, rotate_x, glm::vec3(1.0f, 0.0f, 0.0f)); // Rotate the whole szene in x-direction based on user input
    	glm::mat4 viewRotateY     = glm::rotate(viewRotateX,  rotate_y, glm::vec3(0.0f, 1.0f, 0.0f)); // Rotate the whole szene in y-direction based on user input
    	glm::mat4 pointRotateX    = glm::rotate(viewRotateY, -90.0f, glm::vec3(1.0f, 0.0f, 0.0f)); // Rotate the camera by 90 degrees in negative x-direction to get a frontal look on the szene
    	glm::mat4 viewTranslate   = glm::translate(pointRotateX, glm::vec3(-dimensionX/2.0f, -dimensionY/2.0f, -dimensionZ/2.0f)); // Translate the origin to be the center of the cube
    	modelViewMatrix = viewTranslate;
    	glBindBuffer(GL_UNIFORM_BUFFER, globalMatricesUBO);
    	glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4), sizeof(glm::mat4), glm::value_ptr(modelViewMatrix));
    	glBindBuffer(GL_UNIFORM_BUFFER, 0);

    I've tried a lot of things now but couldn't find out which of the code I need to change in order to achieve real zooming. I followed the instructions of a number of tutorials and looked at different example code snippets, but it just didn't worked out. Since I just started learning OpenGL, I hope that someone can tell me which instructions I need to change and how.
    rotate_x, rotate_y and translate_z all come from mouse input

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Why don't you just change FOV parameter in a projection?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2013
    Yeah, that's what I tried, but I couldn't figure out how. Additionally, I probably have to change the modelview matrix as well, since the z translation doesn't make sense anymore. Could you give me a hint or even some sample code on how to change those things exactly? I do understand that I'll need glm::lookat / perspective, but I'm not sure about the parameters if user input is involved.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Have a read of this

    in particular
    e = focal length = 1 / tan(FOV / 2)
    As I understand with a telephoto lens what you are changing is the focal length.

Similar Threads

  1. how to change a "mesh" in a MapGrid
    By Kleinstein in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-29-2017, 05:47 AM
  2. How to change the "camera" position in OpenGL - Mac OSX
    By openglbeginner123 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-02-2014, 07:19 PM
  3. Replies: 1
    Last Post: 10-26-2012, 02:19 AM
  4. Real-time "Free Hand" shader edge effect?
    By Stuart McDonald in forum OpenGL: GLSL
    Replies: 4
    Last Post: 01-20-2011, 03:09 AM
  5. Getting "real world" coordinates from screen
    By StuckInBorland in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 05-11-2010, 04:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean