Alright, time to kick it up a notch. I’ve been thinking lately:
Say you have a 2D game seen from the side and the map is build using polygons. So when you build the map you need to place each polygon manually.
Imagine if there was a way to automate this - instead of building a map you draw a picture of how you want the map to look and then let the application build the map for you by filling what you have drawn with triangles (polygons).
Here’s a small example, the image drawn will be in black and white (black = air, white = ground). The yellow lines are the polygons that the application has calculated to fill the white space.
http://www.java-gaming.org/index.php?action=dlattach;topic=20699.0;attach=1426
Here’s how I would like the code to look:
VectorizationTool vt = new VectorizationTool(Color.WHITE);
ArrayList<Polygon> ground = vt.process(<image object>);
vt.setColor(Color.RED);
ArrayList<Polygon> lava = vt.process(<image object>);
There we have it, would be very simple to use. We create an instance of the tool where we say that the color white is the ground, then we process the image and get the polygons representing the ground in our map. All other colors that arent pure white will be ignored. Then we just switch which color to process and use the same image to get the polygons that should represent a “lava” type of ground. The “Polygon” object can simply be the polygon’s three corners’ X/Y coordinates measured in pixels. (0,0) would be at the top left corner of the image that is processed.
Now my question to you fellows is as follows: How would one go about implementing this thing? Is there already available source to look at, or maybe even something like this already exists in Java and is ready to use?
I’ve been searching the net for this a bit but come up short. There are many algorithms out there, but I’m not sure which one I want that does what I want it to do or which one that is most effective. Hopefully there are people on this forum that knows this better than I do, I’m not at all good at math so I bet there are plenty of people here that can advise me.
(In case this thread will become a success I will now write down some key words to help others to find this topic more easily by search in the future: trace bitmap to vector, Raster-to-Vector Algorithm, Vectorization, convert bitmap to polygons, convert image to polygons, image edges java, fill image with polygon java, polygon mask java, poly2mask java. Some of these “keywords” might make no sense but they are part of what I searched for in order to finally decide on the thread’s subject.)