Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Nonlinear zoom

  1. #1
    Intern Contributor
    Join Date
    Jun 2001
    Posts
    76

    Nonlinear zoom

    Any ideas for a nonlinear zoom using the mouse?

    So, zoom out is slow when zoom factor is very small and zoom out
    is fast when zoom factor is very large.

    Linear zoom makes zoom in very slow, and zoom out very fast.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: Nonlinear zoom

    Code :
    if (zoom_in) zoom_factor*=1.1f;
    else
    if (zoom_out) zoom_factor*=(1.0f/1.1f);
    //clamp zoom_factor to min/max values here
    As most non-linear animation stuff, this is hard to get right if you want to make it fps-independant.

    It's better to use the fov angle of the projection matrix setup for zooming. This will also work nicely with linear adjustments.

  3. #3
    Intern Contributor
    Join Date
    Jun 2001
    Posts
    76

    Re: Nonlinear zoom

    Sorry, I forgot to mention that it's a windowed, 2D ortho projection
    for a basic 3D modeller I'm writing, if that helps any.

    I'm basically doing what you described, is that I have a zoom_factor,
    and based on the mouse movement delta, I multiply it with mouse_dy.

    However this zoom_factor is still linear.

    How would I get a nonlinear zoom_factor that slows down when the
    zoom_factor is less than 1?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: Nonlinear zoom

    Suggestion:
    float fudge_factor; //<- adjust this one with mouse movement
    float zoom_factor=some_mapping_function(fudge_factor);

    This way you can apply any arbitrary mapping between the mouse position and the actual zoom factor.

    You can do some stuff with an interpolated table lookup or a function with exp, log, square roots, whatever works for your application.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •