8

Question and Update.
First of all, I would like to thank @ScriptCoded for an idea in the previous post, so then I have beautiful terrain now, and the complete world map generated like plots, and each of them consists of 5x5 different plots defined by neighbors :) Hired a digital artist who is working on much nicer plots as well.

The new issue is regarding the zoom.
The map is saved as JSON with the pixel-perfect location of each generated plot so I am detecting the collision with the mouse based on their location. After I zoom in, the script is still comparing the pixel location of the element, but the real screen is scaled already so the pointer is off (image2). The problem is described in image3 as well. How can I still get the canvas relative value of the mouse instead of the x,y coordinate on the current zoomed screen?

Comments
  • 2
  • 0
  • 1
    Coordinate systems are hard. What language are you in? Check out affine transforms. Basically, define a transform that gets from one coordinate space to another.
  • 0
    @atheist It's a web-based game, based on javascript and html5 canvas. I'm looking to somehow define how much is missing from which side after the zoom, to try to decrease the position value of the elements by this number. So far I have only the new width and height of the zoomed map compared to the initial, but I need this value from each side. I knew before that this zoom will be a headache..
  • 0
    Wow! Nice
  • 1
    @blindXfish you only need the left offset and top offset, and relative zoom (I've done this sort of thing before). But yes, it's hard and messes with my brain. I wrote a thing that does this ages ago, one of my most tested pieces of code, because I wasn't totally sure it was correct, but I could describe what it should do.
  • 0
    @atheist Yep. I have the offsets and the scale/zoom. I will try to check if two objects are in collision:
    {pointer.x+offsetx, pointer.y+offsety} and {el.x-offsetx, el.y-offsety, el.width*scale, el.height*scale}
    Burned out.
  • 1
    Would it be better to use some other map projection to get a better sense of proportions?
  • 0
    @atheist Solved this nightmare...
  • 0
    and this
  • 0
    Also received the art for base plots, so basically, here is how it looks like in Mtirala National Park in Georgia. :D
Add Comment