For Android, let's say you have a image of a map that you draw inside your view. On this map there are many, many "hot spot" locations where you want your user to be able to select. Given that there are so many, you want to give the user the ability to zoom the image, and since it can be zoomed, they need the ability to pan the image too.
Once the user pans and zooms though, the coordinates that originally related to the hot spots have changed since the location the user touches will be based on the view, not the image.
How do you translate the new coordinates back to what they would have been originally before the panning and zooming were done?
Here is the question asked on JavaRanch which may make this more clear:
http://www.coderanch.com/t/567402/java/java/translation#2577725
THANKS!
You're trying to do a coordinate transform, yes?
No, not in the sense that I am doing anything like what I THINK you mean.
What you need to do is apply the transform from the map space to view space in >reverse, or rather undo said transformation.
Hmmm...there is no "map" per se, just the Android screen (the view port I guess you could say) and the image drawn onto it which CAN become larger than the screen.
First store the location and magnification of your viewing area or camera somewhere.
Well, there is no "camera" as in what I think you mean. This isn't 3D, just 2D. The original magnification is 1. Not sure what I would need to store in this case.
Assuming you store the magnification as something like real units/view units or area >of map/area of view. You can then convert from view in magnified units to real units >by doing screen location*magnification. Divide if your ratio is flipped.
Real units? I'm dealing with pixels on a phone.
Now that you have the location relative to the screen in real units you simply do >camera location + relative location which gives you your map location. This does >assume that camera position is in the map coordinate system.
Again, there is no camera position. This is just a phone with an image on it. No 3D. Just a human looking at an image on a phone.
For camera to world transform: (location * magnification) + camera position
So given that there is no camera, what would be used here instead?
For world to camera transform: (location - camera position)/magnification
Again, I am not sure that this is applicable here as there is no camera to have a position.
remember the */ signs flip for view/real rather than real/view
For something more elegant look into how graphics systems do coordinate transforms. >For a 2D system without rotation I think the above is sufficient though.
I really appreciate the effort but I do not see this answer as answering the question. If you look at the code I linked to, I think the question will become much more clearly defined.
It's just an image on a phone that the user can pan and zoom. I keep a pan and a zoom multiplier around and know the touch point on the screen. No camera, no world coordinate system, nothing like that at all. Just an image on a phone that can be manipulated.