PDA

View Full Version : OpenGL Panning Problem



rathan001
04-08-2013, 03:30 AM
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



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;
}

tonyo_au
04-08-2013, 07:41 AM
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

rathan001
04-08-2013, 04:15 PM
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