c++ - Zooming into the mouse, factoring in a camera translation? (OpenGL) -


This is my problem, I have a scale point, which is the unrestricted mouse position. I also have a "camera which is basically transformed by x and y all the things i want to do is zoom in mouse position

I'v tried this.

  1. Find the X of the mouse and the y coordinate 2. Translate the original (x, y, 0) by its desired vector on its coordinates (i, j, k) 4. By pouring the scale To return the original (- x, -y, 0) to  

but this camera A translation for this is not included.

How can I do this properly. Thanks to this

  glTranslatef (controls.MainGlFrame.GetCameraX (), controls.MainGlFrame.GetCameraY (), 0); glTranslatef (current.ScalePoint.x, current.ScalePoint.y, 0); glScalef (current.ScaleFactor, current.ScaleFactor, 0); glTranslatef (-current.ScalePoint.x, -current.ScalePoint. Y, 0);  

Text after "div class =" itemprop = "text">

Instead of using glTranslate to move all the objects , You should try it. It takes wanted as the left coords parameter, right coords, bot ohm core, top Coorz, and minimum / maximum depth.

For example if you call Glotho (-5, 5, -2, 2, ...); Your screen will show all the points whose counces are going from a rectangle (-5,2) to (5, -2). The advantage of this is that you can easily adjust the zoom level.

If you do not multiply any visual / projection matrix (which I think is the case), then default screen cord range (-1, 1) (1, -1).

But in your project it can be very useful to control the camera. Before placing an object instead of your glTranslate, call it:

  float left = camera x - zoom level * 2; Float right = camera x + zoom level * 2; Float top = cameraY + zoomLevel * 2; Float bottom = cameraY - zoom level * 2; Glotho (left, right, bottom, top, -1.f, 1.f);  

Note that camera X and camera now represent the center of the screen.

Now when you zoom to a point, you just have to do something like this:

  CameraX + = (camerax-screenx) * 0.5F; Camera Y + = (Camera Y - Screen Y) * 0.5 F; Zoom Level + = 0.5 F;  

Comments