PDA

View Full Version : Zoom center point



Jeff1000
01-28-2008, 01:07 PM
Hello,

I am implementing a zoom operation with

glOrtho(left*zoomFactor, right*zoomFactor, bottom*zoomFactor, top*zoomFactor, 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

-NiCo-
01-28-2008, 01:18 PM
glTranslatef(-cursor.x,-cursor.y,0.0f);
glOrtho(left*zoomFactor, right*zoomFactor, bottom*zoomFactor, top*zoomFactor, zNear, zFar);

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

N.

Jeff1000
01-28-2008, 03:07 PM
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()?

-NiCo-
01-28-2008, 03:25 PM
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?


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;




Does glTranslate() have to be called before glOrtho()?


Yes it does.

N.

sefiroths
07-29-2010, 02:15 AM
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