Page 1 of 1

Question on storing n sided polygon data

Posted: Mon Mar 29, 2010 1:19 pm
by xiphirx
Right, so the game that I am building a map editor for has a section like so

Code: Select all

collision {
(0,0);(12,12);(34,2)
(23,45);(23,4);(5,76);(1,2)
}
where each lines represents a series of coordinates that make up a polygon. Now, reading in this data is fine, but I am wondering on how I am going to store it. I recently started things like linked lists in my C++ class, and they seem to be a good candidate, but if I need to have multiple polygons, then I would have to make an array of linked lists, which seems like a huge headache...

What do guys recommend?
*note*: there is no definite size to anything here, so static stuff wont help D:

Re: Question on storing n sided polygon data

Posted: Mon Mar 29, 2010 1:55 pm
by RyanPridgeon
I wouldn't recommend having a linked list for each vertex. Just have a class for each shape that holds an array of n vertices,
then I suppose you could have a linked list to store all the shapes.

Code: Select all


struct Shape {
    Shape* next; // pointer to next shape in the linked list
    Vec2* vertices; // heap array of vertex data
    int n; // number of vertices on this shape
};

// whatever manages the shapes
class AllShapes {
    Shape* shapes; // start of the linked list
};
(Where Vec2 is your 2d vector class)

This must work pretty well as it's similar to what Box2d does, and Box2D is rather fast :)