Coordination System For Game
I have two full sizes pictures of a map of the world. It's for a game.
I know the coordinates of the upper-left corner and the lower-right.
Can someone explain how I can calculate the coordinates anywhere on the map with that information and to show it as a "ToolTip" or in the StatusBar.
I wanna show the X & Y according to the mouse pointer on these pictures.
Anyone with a clue?
Re: Coordination System For Game
sorry? i am not sure i understand your question
Re: Coordination System For Game
You could load the pictures into a picturebox, then use the mousemove event to retrieve your coords....
i.e
Code:
Private Sub PictureBox_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lbl_X.Caption = X
lbl_Y.Caption = Y
End Sub
Are you hoping to get back accurate longitude and latitude co-ords? that would be a lot more difficult!
Re: Coordination System For Game
This is for a game so the coordinates are very strict. The upper-left corner and lower-right must have a specific coordinate and the other will have to be adjusted around that Scale. I just don't know how to do it.
Re: Coordination System For Game
Are you saying that each map is for one hemisphere (half) of the Earth? If you want the second map to have an X coordinate which is a continuation of the first map, you can add the width of the first map to the coordinate. Or are you saying that you want the X coordinate of the second map to decrement back down to zero? If so, then subtract the X coordinate from the width.
Re: Coordination System For Game
Let's say this. It's divided into two and let's work with one of them.
The upper-left corner's maximum coordinate is: X: 4795, Y: 3195
The lower-right corner's maximum coordinate is: X: -15580, Y: -7461
How can I make the mouse input read where you have pointer, and it should show the exact location when you hoover over a specific location?
.... X
Y.|-------------|
...|#########|
...|#########|
...|###(a)####|
...|#########|
...|#(b) ######|
...|-------------| Y2
.................. X2
X: 4795, Y: 3195
X2: -15580, Y2: -7461
What are the XY coordinates of (a) & (b) ?
Cause as far as I've learned you should be able to point out any location on a map if you know those two ends. I just haven't been done anything with math for over a year so I've completly forgotten.
Anyone got a brigther sight of what I mean now?
But that (a) & (b) should be wherever you might point the mousepointer.
Re: Coordination System For Game
Ok, ignoring my 500p book on projection between different coordinate systems, the easy way is:
Code:
iMapX = 100 'where upper left of map is placed on screen
iMapY = 100 'where upper left of map is placed in screen
iMapWidth = 300 'map width in pixels
iMapHeight = 200 'map height in pixels
x1 = 4795 ' upper left x
y1 = 3195 ' upper left y
x2 = -15580 ' lower right x
y2 = -7461 ' lower right y
cX = ((MouseX - iMapX) * (x2 - x1) / iMapWidth) + x1
cY = ((MouseY - iMapY) * (y2 - y1) /iMapHeight) + y1
Now if you place your mouse in the middle of the map (250, 200) :
Code:
cX = ((250 - 100) * (-15580 - 4795) / 300) + 4795 = -5392.5
cY = ((200 - 100) * (-7461 - 3195) / 200) + 3195 = -2133
- petter
Re: Coordination System For Game
Where should I make that input? It's easier if you write where it should be too. I tested it with a MouseMove over the picture but it doesn't read the Coordinates according to the mouse pointer.
can you be a bit more specific?
This is how it looks like now but it doesn't work:
Private Sub Map_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
iMapX = Map.Left 'where upper left of map is placed on screen
iMapY = Map.Left 'where upper left of map is placed in screen
iMapWidth = Map.Width 'map width in pixels
iMapHeight = Map.Height 'map height in pixels
X1 = 4795 ' upper left x
Y1 = 3195 ' upper left y
X2 = -15580 ' lower right x
y2 = -7461 ' lower right y
cX = ((MouseX - iMapX) * (X2 - X1) / iMapWidth) + X1
cY = ((MouseY - iMapY) * (y2 - Y1) / iMapHeight) + Y1
Map.ToolTipText = cX & " , " & cY
End Sub
Re: Coordination System For Game