Mouse Enlargement Algorithm (OpenGL)

I have an OpenGL scene with an upper left coordinate system. When I glScale, it scales from (0,0) in the upper left. I want it to zoom from the mouse coordinate (relative to the OGL frame). How it's done? Thanks

+7
c ++ c opengl
source share
2 answers

I believe that this can be done in four stages:

  • Find the x and y coordinates of the mouse using any function for which for your window system (i.e. GLUT or SDL), and use gluUnProject to get the coordinates of the object corresponding to these window coordinates
  • Translate to (x, y, 0) to place the origin in these coordinates.
  • Scaling according to your desired vector (i, j, k)
  • Translate to (-x, -y, 0) to return the beginning in the upper left corner
+10
source share

I did smooth scaling using glortho. Skeleton of my solution

glortho (initial viewport x, y and size)
glcalllist (my display list)
rendering
.
.
to gradually move to the final coordinates / size of the viewrport. Implement your FPS deadlines and requirements
.
.
glortho (final viewport x, y and size)
glcalllist (my display list)
rendering

I hope you get a general idea. There are several other methods for this, but I find the glortho method that is easiest to understand.

+3
source share

All Articles