3d Modeller (Array Problems)

I also posted this on a c++ board but what the hell this forum has more people

Here is a bit of my source code

typedef struct{
float x,y,z;
}vertex_type;

typedef struct{
int a,b,c;
}polygon_type;

typedef struct {
vertex_type vertex[MAX_VERTICES];
polygon_type polygon[MAX_POLYGONS];

} obj_type, *obj_type_ptr;

All this means that instead of the regular types of identifiers(int,float)
I can now call obj_type!!

Here is code to say what vertexes the object has and where they are-

obj_type name =
{
{
-10, -10, 10, // vertex v0
10, -10, 10, // vertex v1
10, -10, -10, // vertex v2
-10, -10, -10, // vertex v3
-10, 10, 10, // vertex v4
10, 10, 10, // vertex v5
10, 10, -10, // vertex v6
-10, 10, -10 // vertex v7
},
this is the vertecies and there position in 3d space.
{
0, 1, 4, // polygon v0,v1,v4
1, 5, 4, // polygon v1,v5,v4
1, 2, 5, // polygon v1,v2,v5
2, 6, 5, // polygon v2,v6,v5
2, 3, 6, // polygon v2,v3,v6
3, 7, 6, // polygon v3,v7,v6
3, 0, 7, // polygon v3,v0,v7
0, 4, 7, // polygon v0,v4,v7
4, 5, 7, // polygon v4,v5,v7
5, 6, 7, // polygon v5,v6,v7
3, 2, 0, // polygon v3,v2,v0
2, 1, 0, // polygon v2,v1,v0
}
};
This code continues from the other one and says which verticies join to form the face.
Anyway my question is how can I later add new verticies and polgons if I use plus won’t I just edit the currently existing vertexies!!
PLEASE HELP!!

Please help me!!

instead of having an array of verts and indices. Try using a linked list of verts and indices. www.gametutorials.com has a tutorial on them in either the C or C++ tutorial section. Hope I helped

Use pointers:
let vector3f be
float vector3f[3];

then
instead of declaring:
vector3f vertices[MAX_VERTS];
do it:
vector3f* vertices;

NumberOfVertices = SomeNumber;

vertices = (vector3f*) malloc (sizeof (vector3f) * NumberOfVertices);

and when you add a vertex:
vector3f tmp[NumberOfVertices];

copyArray(vertices, tmp, NumberOfVertices);

NumberOfVertices++;

vertices = (vector3f*) malloc (sizeof (vector3f) * NumberOfVertices);

copyArray(tmp, vertices, NumberOfVertices - 1);

vertices[NumberOfVertices - 1][0] = new_vert[0];
vertices[NumberOfVertices - 1][1] = new_vert[1];
vertices[NumberOfVertices - 1][2] = new_vert[2];

and the same with faces…
You don’t have to use linked lists

the way I was thinking with the linked list would be doing the same thing you have stated. Different ways but acheive the same thing

Lordoftheuniverse I get what you say but how would I draw the object from there.
Please reply or send a full example to

shanedudddy2@hotmail.com
Anyone can send me an example
Thanks!!

One more thing.
If I do it your way how would I add code to make it select one object from another
thanks bye.

SHANEDUDDDY2

Please send example to shanedudddy2@hotmail.com

1: to draw objects:

faces array consist of entries like:
{
{0, 1, 2},
{0, 2, 3},
};

which are indexes of vertices.
to draw:

glBegin(GL_TRIANGLES);
glVertex3fv(Vertices[Faces[i][0]]);
glVertex3fv(Vertices[Faces[i][1]]);
glVertex3fv(Vertices[Faces[i][2]]);
glEnd();

where i runs throught entire array…

copyArray says it`s an undeclared Identifier
Please give some explanation how come and how to fix it!!
PLEASE,
PLEASE,
PLEASE,
PLEASE,
PLEASE,
PLEASE,
PLEASE,
PLEASE!!!

It’s called pseudocode. It was assumed you would understand how to copy elements from one array to another. If that assumption was incorrect, perhaps you should be reading up in your favorite C/C++ books a bit more. It’s going to be awful tough to get a handle on OpenGL if you don’t yet have a handle on general programming techniques.

Check that out :
http://www.cprogrammming.com