I'm trying to rotate the model based on my mouse click position. Each time I click the mouse, the rotate point is recalculated, but after I rotate the model and choose another rotate point, the model shifts. I don't know what is wrong with my implement. If I need to provide more information to receive helps, just tell me.
This is the render function:
private void Render()
{
glControl1.MakeCurrent();
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();
GL.Translate(transX, transY, 0);
GL.Translate(rotatePoint.point);
GL.Rotate(angleX, 0, 1, 0);
GL.Rotate(-angleY, 1, 0, 0);
GL.Translate(-rotatePoint.point);
SetupViewport();
pco.Render();
GL.PopMatrix();
}
SetupViewport function:
private void SetupViewport()
{
int w = glControl1.ClientSize.Width;
int h = glControl1.ClientSize.Height;
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
float aspect = w / (float)h;
float n = scaling;
float left = -n * 0.5f, right = n * 0.5f, down = -n * 0.5f / aspect, up = n * 0.5f / aspect;
if (w <= h)
{
GL.Ortho(-1, 1, -aspect, aspect, -1, 1);
}
else
{
GL.Ortho(left, right, down, up, -10.0f, 10.0f);
}
GL.Viewport(0, 0, w, h);
}
This is when I rotate around the original state:
The model shifted after rotate but when I rotate the model back to the original state, it stops shifting:

