tags:

views:

166

answers:

2

I have an OpenGL scene with a top left coordinate system. When I glScale it zooms in from (0,0) the top left. I want it to zoom in from the mouse's coordinate (reletive to the OGL frame). How is this done? Thanks

+5  A: 

I believe this can be done in four steps:

  1. Find the mouse's x and y coordinates using whatever function your windowing system (i.e. GLUT or SDL) has for that, and use gluUnProject to get the object coordinates that correspond to those window coordinates
  2. Translate by (x,y,0) to put the origin at those coordinates
  3. Scale by your desired vector (i,j,k)
  4. Translate by (-x,-y,0) to put the origin back at the top left
Jordan Lewis
+1  A: 

I did a smooth zoom in using glortho . The skeleton of my solution is

glortho(initial viewport x,y & size)
glcalllist(my display list)
render
.
.
loop to gradually go to final viewrport coordinates/size . Implement your timing and FPS requirements
.
.
glortho(final viewport x,y & size)
glcalllist(my display list)
render

I hope you get the general idea. There are few other methods to acheive this, but I find glortho the method the easiest to comprehend.

Gary