Created
May 21, 2017 16:01
-
-
Save serge-rgb/ddfc7cd9d324a2e64944f0b9c5a5cce4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Not sure if I understood what you meant by "tracking positions", but | |
I'm guessing that you need clarification on how change of coordinates | |
works between screen coordinates and what I call "canvas space". | |
This is how things work as of 1.4.0 (previous versions had a 32 bit | |
canvas instead of 64, but fundamentally it works the same) | |
A milton canvas is a -2^64 X 2^64 image. In that sense, it's not | |
really "infinite", but 64 bits is enough so that no one will ever run | |
out of canvas. | |
The screen is a window onto the canvas. When you zoom-out, the window | |
becomes larger. When you zoom-in, the window becomes smaller. | |
The smallest a window can get is a 1-to-1 correspondence between a | |
screen pixel and a canvas pixel. Milton sets the limit to be a little | |
bit larger than 1-to-1 because of some very good reasons which are not | |
relevant at the moment :P | |
We change coordinates from a screen coordinate S to a canvas | |
coordinate C with this formula: | |
C = S*scale + pan_center | |
So `scale` is the zoom-level, i.e. how big the window is, and | |
pan_center is how much we have panned away from the origin. | |
The inverse function is then: | |
S = (C - pan_center) / scale | |
If you take a look at canvas.cc, you can see these formulas with an | |
extra parameter called zoom_center, which we use to set the zoom | |
center to the location of the cursor. (See how when you zoom with the | |
mouse-wheel the zoom is always relative to your cursor position). For | |
the purpose of this explanation, we can think that zoom_center is | |
zero. | |
Let me know if this answers your question, or if I should clarify | |
anything else! | |
If you prefer email, you can contact me at bigmonachus@gmail.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment