Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
atheist99913yCoordinate systems are hard. What language are you in? Check out affine transforms. Basically, define a transform that gets from one coordinate space to another.
-
@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..
-
atheist99913y@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.
-
@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. -
Would it be better to use some other map projection to get a better sense of proportions?
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?
question