PDA

View Full Version : What's a good data structure to hold object vertex positions?



Rottbott
06-21-2001, 01:46 PM
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[3], VertexY[3], VertexZ[3];
} 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).]

zed
06-21-2001, 05:00 PM
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 (http://www.magic-software.com)

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

struct POLYGON
{
int num_verts;
VECTOR *v;
}

Eber Kain
06-21-2001, 08:18 PM
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[15]) 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.

Rottbott
06-21-2001, 10:51 PM
Thanks for your help, and the links. I'll be back with more questions before long http://www.opengl.org/discussion_boards/ubb/wink.gif.

noninterleaved
06-22-2001, 09:06 PM
have you considered using STL vectors to store all of the data on the heap?

Rottbott
06-23-2001, 12:03 AM
No I hadn't, because I've never heard of one http://www.opengl.org/discussion_boards/ubb/wink.gif

RandyU
06-23-2001, 11:03 AM
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.