Results 1 to 4 of 4

Thread: Zooming to a Point

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #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.

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
  •