Results 1 to 5 of 5

Thread: Pan on a scene

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2006
    Posts
    16

    Pan on a scene

    I have a terrain surface and i wanna make pan on it.
    I want to click in the terrain and move it,
    but i want to keep this point always under the pointer of the mouse.
    I have tried to calculate it using the projection and modelview matrix. What i tried was
    to get the point where i click (the point of the
    mesh) and then try to calculate what translation i needed to make the projection of this point in the position of the pixel of the mouse pointer. But i didn't be able to do it.

    Any help would be appreciated, thanks in advance.

    (Sorry for my horrible english)

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: Pan on a scene

    assuming you want to pan in the x-y-plane. use gluProject to compute the screen coordinates of the following points:

    O = (0, 0, 0) -> Screen_O = (Ox, Oy, Oz)
    X = (1, 0, 0) -> Screen_X = (Xx, Xy, Xz)
    Y = (0, 1, 0) -> Screen_Y = (Yx, Yy, Yz)

    this gives you information about how the global x and y axis unit vectors are mapped on the screen:

    X = [Xx-Ox, Xy-Oy]
    Y = [Yx-Ox, Yy-Oy]

    now, if you move the mouse pointer by

    delta_mouse = [dx, dy]

    you can calculate how to split delta_mouse into the directions of X and Y:

    delta_mouse = [dx, dy] = a*X + b*y

    you have 2 equations for the coefficients a, b and can calculate them.

    finally, translate your scene by

    glTranslate(a, b, 0);

    hope that helps

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2006
    Posts
    16

    Re: Pan on a scene

    A lot of thanks! Now i'll be able to make a correct pan.

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: Pan on a scene

    did you already make it work, or are you just optimistic

    two more remarks: first, i used this with an ortho view. it may not work with perspective views. a vector (1, 0, 0) drawn in the middle of the screen will look different from a vector (1, 0, 0) drawn at the top left corner of the screen.

    second, for accuracy reasons it may be better to map the points X=(10, 0, 0) and y=(0, 10, 0) instead of the ones with unit length. in that case, the translation would be glTranslatef(a/10., b/10., 0.)

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2006
    Posts
    16

    Re: Pan on a scene

    Well, i think i have a solution
    I know what are you saying. But my idea is make it for each pixel i have to move. The problem is that the size of a unit depends on the distance from de camera (10 units at 50 units of distance will not take the same pixels that 10 units a 100 units of distance).
    But i think i can use the idea whit a little difference. I'll try to calculate each time the
    units i have to translate for move 1 pixel (i think i can calculate it).
    Then i'll do it recursively for each pixel i have to move for all delta distance.
    Find the distance as i only wanna move for 1 pixel, and do it for n pixels.

    Do you think that it works?

Similar Threads

  1. What is a scene graph?
    By juggernaut in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-21-2012, 02:54 AM
  2. move scene
    By joker40 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-24-2011, 05:23 AM
  3. 3d scene
    By joker40 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-19-2011, 07:02 AM
  4. how to display 2d scene on top of 3d scene???
    By immy in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 03-26-2002, 04:13 AM
  5. set up a Scene
    By McZ in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-06-2002, 05:53 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