开发者

Algorithm to zoom into mouse(OpenGL)

I have an OpenGL scene with a top left co开发者_Go百科ordinate system. When I glScale it zooms in from (0,0) the top left. I want it to zoom in from the mouse's coordinate (relative to the OGL frame). How is this done? Thanks


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜