CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    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?

  2. #2
    Join Date
    Dec 2002
    Location
    London, UK
    Posts
    1,569

    Re: Coordination System For Game

    sorry? i am not sure i understand your question
    Mike

  3. #3
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    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!
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  4. #4
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    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.

  5. #5
    Join Date
    Dec 2001
    Posts
    6,332

    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.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  6. #6
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    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.

  7. #7
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    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

  8. #8
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    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

  9. #9
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    Re: Coordination System For Game

    Anyone?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured