Hi guys
Currently I am using glOrtho to zoom and pan around a 2D graph I am rendering.
I have setup up the viewport to the standard width and height. Then I set the glOrtho so that my frustrum makes screen coordinates match world coordinates.
////////////////////////////////////////////////////////////////////
glViewport(0, 0, window_width,window_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, window_width,window_height,0 , 100, -100);
///////////////////////////////////////////////////////////////////
When I do my zoom function in my mouse callback, I multiply the frustrum edges by a zoom factor…
glOrtho( 0 * zoomOut,
window_width * zoomOut,
window_height * zoomOut,
0 * zoomOut,
100, -100);
My question is… how do I zoom using mouse position as a centre?
I have tried this… (where mouseStoreX and mouseStoreY are the position stored at the first click)
glOrtho( (0 -mouseStoreX )* zoomOut + mouseStoreX,
(window_width - mouseStoreX) * zoomOut + mouseStoreX,
(window_height - mouseStoreY) * zoomOut + mouseStoreY,
(0 - mouseStoreY) * zoomOut + mouseStoreY,
100, -100);
It seems to work but the frustrum jumps around when I do a new click. I think somewhere I’m not taking into account the zoomOut factor when doing the mouse position storing.
Any help is much appreciated.
Thanks
Dan