Zoom center point

Hello,

I am implementing a zoom operation with

glOrtho(leftzoomFactor, rightzoomFactor, bottomzoomFactor, topzoomFactor, zNear, zFar);

Could anyone show me how to implement the zoom with the cursor position as the zoom center point, instead of the windows center?

Thanks

glTranslatef(-cursor.x,-cursor.y,0.0f);
glOrtho(leftzoomFactor, rightzoomFactor, bottomzoomFactor, topzoomFactor, zNear, zFar);

cursor.x and cursor.y are in the range [-1,1]

N.

Thanks for your quick reply. In what coordinate the cursor.x and cursor.y are defined? Suppose that my mouse position is located at (200, 200), how the cursor.x and cursor.y are calcuated?
Does glTranslate() have to be called before glOrtho()?

If your window is of size 640x480

cursor.x = 2.0f*(200 + 0.5)/640-1.0;
cursor.y = 2.0f*(200 + 0.5)/480-1.0;

Yes it does.

N.

hi, i’m in perspective view, dragging the mouse i draw a square with the cursor.x and y saved.
i don’t want to change the perspective matrix, but use only glscale and gltranslate to move and scale the square at the center of the video…it is possible?
thanks