# What's a good data structure to hold object vertex positions?

Hi,

I’ve just started OpenGL, I’ve got no books so I’m working entirely from the web. Tricky but I’m making some progress.

What I need to do is think of the best way to hold vertex positions. Currently I use a simple structure:

#define MAX_POLYGONS 50

// Polygon vertex position structure
struct
{
float VertexX, VertexY, VertexZ;
} Poly[MAX_POLYGONS];

However, this takes up all the memory straight away (MAX_POLYONS). Also I need to seperate the vertexes for each object.

So what I need is a sensible way of storing information for each object, which can also store vertex position data for any number of polygons. It doesn’t matter if each polygon is limited to an exact number of vertexes (I will probably stick to GL_TRIANGLES for now).

Any ideas?

Thanks.

[This message has been edited by Rottbott (edited 06-21-2001).]

theres heaps of ppls examples out there in there code. eg i recommend taking a look at dave eberly’s code www.magic-software.com

btw i use something like this (condensed)
struct VECTOR
{
float x,y,z;
};

struct POLYGON
{
int num_verts;
VECTOR *v;
}

Ok, heres how i work things in OpenGL, i use Vertex Arrays to hold the infromation for drawing my object, then I make a struct for my object, i give it a draw function , and a matrix (m) the matrix hold the positioning data for the object, so in the draw function i just load the objects matrix, the call the functions do draw from the vertex arrays. hope that made sence.

i have a site with some tutorials, home.earthlink.net~/eberkain/

I would reccomend downloading the large .pdf tutorials from nehe.gamedev.net, its only 1500 pages of OpenGL stuff.

Thanks for your help, and the links. I’ll be back with more questions before long .

have you considered using STL vectors to store all of the data on the heap?

No I hadn’t, because I’ve never heard of one I think the best way is to keep data in three arrays:
1)vertex array of 3D vectors
2)normal array of 3D vectors
3)Triangle array of structs
struct {
int p1,p2,p3;
} TTri;
Or data about tri_strips.

where p1,p2 and p3 are indexes in vertex array.