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 5 of 5

Thread: rotate, zoom and panning

  1. #1
    Intern Newbie
    Join Date
    Feb 2002
    Posts
    31

    rotate, zoom and panning

    Hi, I am new.

    I am developing a CView MFC class and I need control rotating, zooming and panning by using 3 buttom mouse. I need that the movement of the camera must be very accurate.

    any suggestion ??

    sorry my english !
    Thank you a lot

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,070

    Re: rotate, zoom and panning

    Use ether the GLUT mouse function or windows mouse function to get mouse button state.

    Then used the mouse movement plus mouse button state to ether rotate, zoom or pan your scene.
    The how accurate the program is depends on how you code it. Can you explain what you mean by accurate camera movement?
    What type of program are you writing?

    But the commands you will use are glRotate, glScale, glTranslate, or gluLookat.

    Originally posted by ahuarte:
    Hi, I am new.

    I am developing a CView MFC class and I need control rotating, zooming and panning by using 3 buttom mouse. I need that the movement of the camera must be very accurate.

    any suggestion ??

    sorry my english !
    Thank you a lot

  3. #3
    Intern Newbie
    Join Date
    Feb 2002
    Posts
    31

    Re: rotate, zoom and panning

    I am writing a single terrain viewer.

    I use LookAt() for set the camera state.

    When te mouse is clicked I save the current position of the mouse in CWnd coordinates.

    Then, at the MouseMove event, I must move/rotate the camera position but I want do it in ogl values:

    By Example...

    class CMyWnd : public CWnd
    {
    ...
    private:
    // Last position of Mouse.
    CPoint m_pntPrevPos;
    // Mouse Operation.
    int m_shrPrevOperation;
    }

    void MyWnd::OnLButtonDown(UINT nFlags, CPoint point)
    {
    m_pntPrevPos = point;
    m_shrPrevOperation = 1;
    CWnd::OnLButtonDown(nFlags, point);
    }
    void MyWnd::OnMButtonDown(UINT nFlags, CPoint point)
    {
    m_pntPrevPos = point;
    m_shrPrevOperation = 2;
    CWnd::OnLButtonDown(nFlags, point);
    }
    void MyWnd::OnRButtonDown(UINT nFlags, CPoint point)
    {
    m_pntPrevPos = point;
    m_shrPrevOperation = 3;
    CWnd::OnLButtonDown(nFlags, point);
    }

    void MyWnd::OnMouseMove(UINT nFlags, CPoint point)
    {
    switch (m_shrPrevOperation)
    {
    case 1: // ZOOM.
    // ### move camera in ogl steps -> (point - m_pntPrevPos);
    break;
    case 2: // PANNING.
    // ### pan camera in ogl steps -> (point - m_pntPrevPos);
    break;
    case 3: // ROTATE.
    // ### rotate camera, or world ?, in ogl steps -> (point - m_pntPrevPos);
    break;
    }

    // Save prev position and PAINT.
    if (m_shrPrevOperation)
    {
    m_pntPrevPos = point;
    InvalidateRect(NULL, FALSE);
    }

    CWnd::OnMouseMove(nFlags, point);
    }

    void MyWnd::OnPaint()
    {
    /*
    glClear();
    glLoadIndentity();
    ...

    glPerspective();
    glLookAt();
    ...

    Paint OGL ELEMS...
    */
    }


    very thanks in avance

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,070

    Re: rotate, zoom and panning

    Here is my suggestion.

    You first take the button down to get the current mouse coordinate. Then use the dirrence between the current and the button down coordinates.

    example:
    worldview.x += right_mouse_down.x - mouse_current.x;
    worldview.y += right_mouse_down.y - mouse_current.y;

    worldview holds the openGL movement value, you may want to use a temp varible so the only on the mouse release does the change become permanent. Also if you need to scale the value of the movement it can be done here also.

    Originally posted by ahuarte:
    I am writing a single terrain viewer.

    I use LookAt() for set the camera state.

    When te mouse is clicked I save the current position of the mouse in CWnd coordinates.

    Then, at the MouseMove event, I must move/rotate the camera position but I want do it in ogl values:

    By Example...

    class CMyWnd : public CWnd
    {
    ...
    private:
    // Last position of Mouse.
    CPoint m_pntPrevPos;
    // Mouse Operation.
    int m_shrPrevOperation;
    }

    void MyWnd::OnLButtonDown(UINT nFlags, CPoint point)
    {
    m_pntPrevPos = point;
    m_shrPrevOperation = 1;
    CWnd::OnLButtonDown(nFlags, point);
    }
    void MyWnd::OnMButtonDown(UINT nFlags, CPoint point)
    {
    m_pntPrevPos = point;
    m_shrPrevOperation = 2;
    CWnd::OnLButtonDown(nFlags, point);
    }
    void MyWnd::OnRButtonDown(UINT nFlags, CPoint point)
    {
    m_pntPrevPos = point;
    m_shrPrevOperation = 3;
    CWnd::OnLButtonDown(nFlags, point);
    }

    void MyWnd::OnMouseMove(UINT nFlags, CPoint point)
    {
    switch (m_shrPrevOperation)
    {
    case 1: // ZOOM.
    // ### move camera in ogl steps -> (point - m_pntPrevPos);
    break;
    case 2: // PANNING.
    // ### pan camera in ogl steps -> (point - m_pntPrevPos);
    break;
    case 3: // ROTATE.
    // ### rotate camera, or world ?, in ogl steps -> (point - m_pntPrevPos);
    break;
    }

    // Save prev position and PAINT.
    if (m_shrPrevOperation)
    {
    m_pntPrevPos = point;
    InvalidateRect(NULL, FALSE);
    }

    CWnd::OnMouseMove(nFlags, point);
    }

    void MyWnd::OnPaint()
    {
    /*
    glClear();
    glLoadIndentity();
    ...

    glPerspective();
    glLookAt();
    ...

    Paint OGL ELEMS...
    */
    }


    very thanks in avance

  5. #5
    Intern Newbie
    Join Date
    Feb 2002
    Posts
    31

    Re: rotate, zoom and panning

    But "worldview" CPoint holds movement in CWnd values, no?

    How translate this movement to ogl values for move the camera whith "glLookAt".
    I do not kwnow if I must use "glUnProject" funtion.

    I am lost!!!
    thanks

    Originally posted by nexusone:
    Here is my suggestion.

    You first take the button down to get the current mouse coordinate. Then use the dirrence between the current and the button down coordinates.

    example:
    worldview.x += right_mouse_down.x - mouse_current.x;
    worldview.y += right_mouse_down.y - mouse_current.y;

    worldview holds the openGL movement value, you may want to use a temp varible so the only on the mouse release does the change become permanent. Also if you need to scale the value of the movement it can be done here also.


Posting Permissions

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