Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So I have a picture(for easier understanding of problem like this: http://www.lib.utexas.edu/maps/europe/europe_95.jpg).

My goal is to click on any of the countries and get what country I clicked. The picture is full of colors, not just simple lets say Germany is purple. Also if I hover above a country I could also do things, like highlight it, write some text in a bar, etc.

What solutions popped in my mind:

  • Draw every slice into a mesh, and ray trace the click. (making lots of meshes is a lot of time)
  • Draw a single quad with texture, make a pixelmap, and get the coordinates clicked, then look up in the table.(I have to make a map for every resolution)

Is there any better way of doing this? Or are there any algorithms for it?

share|improve this question

2 Answers 2

If you take a look, there are rivers and names etc. This will make it rather hard to use the second approach. I would definitely go with the approach were you create a polygon shape for every country, and use simple maths to determine wether a given point lies in the polygon or not. I know this will require you to make a shape for every country. But I think that using the color of the pixel is going to bring you a lot of headache.

This approach will preform pretty good I guess, since you can filter first on AABB, and possibly filter further using a quadtree.

share|improve this answer
    
Well, it wont be a country map, but something I will draw on my own. But borders would take irregular shapings. I would not use the color of the pixels, it's just silly. What I would do is make a 1920x1200 array, which stores numbers for every country. And then I could correlate the coordinates to that array. The array could be created this way: paint a map of different colors, then transform the color into a number. – WuXorT Dec 27 '13 at 13:21
    
I see. Well, if you have the chance of doing so, draw it in SVG. This way you can interpret the SVG in your application so the boundaries of the shapes will be vectorial. This would mean that it is pixel perfect on any resolution. However, you might experience some hard time, parsing the SVG. There should be some good libraries out there for that. – Martijn Courteaux Dec 27 '13 at 13:23
    
"What I would do is make a 1920x1200 array, which stores numbers for every country. [...] paint a map of different colors, then transform the color into a number." - sounds like a texture to me :) – melak47 Dec 27 '13 at 13:37
    
@melak47: I know. And I recommend him to not do that. But my advice of not doing that was maybe not clear, that is true :) – Martijn Courteaux Dec 27 '13 at 13:38

How about using a transparent layer with a different value for each country? Then, you could just query the alpha value for the pixel and use a lookup table.

The only challenge is getting the alpha data there in the first place, but I'm sure you can come up with a creative answer to do that. Maybe just write a very simple editor which flood fills based on each mouse click and then prompts you for a name. It could write both the alpha layer and the look up table for you.

share|improve this answer
    
That would limit you to 255 countries. – Martijn Courteaux Dec 28 '13 at 9:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.