[Gambas-user] algorithm for scaling 2D coordinates centered on an arbitrary point
Kevin Fishburne
kevinfishburne at ...1887...
Wed Aug 17 07:15:56 CEST 2011
On 08/17/2011 12:48 AM, Kevin Fishburne wrote:
> I'm sure this is ridiculously simple, but my simple brain can't seem
> to figure it out.
>
> I have a set of screen coordinates, xPos and yPos. I need to adjust
> their positions based on a zoom level, CameraZoom. The zoom level is
> relative to the center of the screen (swidth / 2, sheight / 2), and
> the zoom level range is from 1 to 2. If the zoom is at 1, the x and y
> coordinates wouldn't change. If the zoom is at 2, they would be half
> their previous distance from the center of the screen. This simulates
> the positions of objects changing as the camera zooms in and out.
>
> There has to be some simple equation to produce this. I've attached
> the procedure that needs this just for reference. Any clues
> appreciated, as always.
Maybe I'm not quite as dumb as I thought. ;) I got it.
I needed to do this:
' Assign initial values to variables
CameraZoom = 1 / Zoom.Current
' Modify screen coordinates for zoom level.
xPos = (swidth / 2) + ((xPos - (swidth / 2)) / CameraZoom)
yPos = (sheight / 2) + ((yPos - (sheight / 2)) / CameraZoom)
' Modify dimensions for zoom level.
Width = Width / CameraZoom
Height = Height / CameraZoom
I could probably just multiply by Zoom.Current instead of dividing by
CameraZoom, but whatever. Hopefully someone will find the algorithm
useful someday.
--
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271
More information about the User
mailing list