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:
- 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
- Translate by (x,y,0) to put the origin at those coordinates
- Scale by your desired vector (i,j,k)
- Translate by (-x,-y,0) to put the origin back at the top left
Jordan Lewis
2010-06-06 03:30:52
+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
2010-06-06 13:56:03