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

Thread: OpenGL Panning Problem

  1. #1
    Newbie Newbie
    Join Date
    Apr 2013
    Posts
    3

    OpenGL Panning Problem

    I have a small issue. Please check the mouse move method. When I do the panning (translation). I need a continuity. But after mouse up, the panning always start from origin(0,0)

    What I need it, If I pan the object to (5,5) next time it should start from (5,5). Could you please tell me what is wrong with my code?


    Best Regards,
    MPR

    Code cpp:
    private void canvasOpenGlControl_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (!mousepressed)
                    {
                        mousepressed = true;
                        mouseDown = e.Location;
                    }
                }
            }
     
     private void canvasOpenGlControl_MouseMove(object sender, MouseEventArgs e)
            {
     
                if (e.Button == MouseButtons.Left)
                {
                    mousePosNow = e.Location;
                    double deltaX = (mousePosNow.X - mouseDown.X) / Geometry.drawingScale;   // the distance the mouse moved since mouse was pressed
                    double deltaY = (mousePosNow.Y - mouseDown.Y) / Geometry.drawingScale;
                    Gl.glViewport(0, 0, canvasOpenGlControl.Width, canvasOpenGlControl.Height);                
                    Gl.glLoadIdentity();
                    Gl.glPushMatrix();
                    Gl.glOrtho(0, canvasOpenGlControl.Width, 0, canvasOpenGlControl.Height, 0,0);
                    Gl.glTranslated(deltaX, -deltaY, 0);
                    updateCanvas(); //Draw the data
     
                }
            }
     
            private void canvasOpenGlControl_MouseUp(object sender, MouseEventArgs e)
            {
                mousepressed = false;
            }
    Last edited by Khronos_webmaster; 04-16-2013 at 10:16 AM. Reason: added CODE tags

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    If you want your updates to be permanent either don't use push/pop matrix -not recommended - or don't translate via a delta but keep the total change from the origin for the translate

  3. #3
    Newbie Newbie
    Join Date
    Apr 2013
    Posts
    3
    Quote Originally Posted by tonyo_au View Post
    If you want your updates to be permanent either don't use push/pop matrix -not recommended - or don't translate via a delta but keep the total change from the origin for the translate


    I understood. I removed pushmatrix. It worked.

    Thanks for your help.


    Regards,
    Pahee

Posting Permissions

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