Question on storing n sided polygon data

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Question on storing n sided polygon data

Post 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:
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: Question on storing n sided polygon data

Post 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 :)
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
Post Reply