Results 1 to 4 of 4

Thread: Zooming to a Point

  1. #1

    Zooming to a Point

    Hi!

    Anybody have an idea of how to calculate the new Camera Pos after Zooming It using the current mouse Position as Reference?

    Something like the magnifying glass from photoshop, if you click some point of the image, the zoom will point to that point!

    I tried several things and none worked as expected! =)

    Any advice?

    To change zoom I'm increasing Camera.Zoom.X and Camera.Zoom.Y.... I need the new Camera.Position.X and Camera.Position.Y use the click point as reference after the new Zoom.

  2. #2
    I don't really understand. Zoom is many times represented with just 1 value, where 0.0 (or 1.0) could mean no zoom, and higher values would move camera backwards.

    Is this 2D or 3D program?

  3. #3
    Won't it be enough to calculate the X:Y diff between the center of the current view and the point to zoom into, and just move the camera by some factor of that distance? As in, I'm looking at ( 10, 10 ) and want to zoom onto ( 14, 18 ) - distance is ( 4 , 8 ), so when zooming I move the camera by FACTOR*( 4, 8 ). If there are a few zoom levels, each level will bring the camera even closer to the desired point. With factor of 0.5, you'll be only 1/8 off after zooming in 3 times.

    Edit:
    Unless you mean that after zooming in, the mouse should point the exact same position. In that case, well, I assume you know what portion of the map/image each zoom level contains. Just calculate the camera position so the new point will stay in the same place. Say, current zoom level shows me 0x0 - 20x20, I want to zoom onto 14x16. This point is located, window-wise, at 0.7x0:8. New zoom level will show me an area of 15x15. If the point is to stay at 0.7x0.8 window-wise, that means the camera should now show from (PointCrd - (WindowCrd*AreaCrd)) to (PointCrd + ((1-WindowCrd)*AreaCrd), in this case - from 3.5x4.0 to 18.5x19.0. The point 14x16 is now located at 14x16 - 3.5x4.0 = 10.5x12 from top left, which gives us 10.5x12 / 15x15 = 0.7x0.8. Perfect.

    Edit-2:
    Dang, the forum converts '8' + ')' into an emoticon. Would it be possible to disable smileys per message?
    Last edited by Super Vegeta; 03-08-2013 at 08:49 AM.

  4. #4
    Quote Originally Posted by Super Vegeta View Post
    Dang, the forum converts '8' + ')' into an emoticon. Would it be possible to disable smileys per message?
    Yes you can prevent simleys to be inserted into text. You can do this from Advanced post editing (click on "Go Advanced" button).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •