: What I want to do exactly, is create a polygon that can have between three and a thousand VERTEX structures in it. It would be a total waste of memory to declare my vertices like "VERTEX vert;" though, especially if you're only making a small object, like the 3D triangle I am attempting to use and display. How could I do this and have it automatically create or remove vertices for me? In an older DOS 3D program I looked at, it was declared this way and accessed with a for loop like this:
: for(int x = 0; x < polygon.vert_num; x++)
: polygon.vert[x].x = blah;
: polygon.vert[x].y = blah2;
: polygon.vert[x].z = blah3;
: Now how could I create my structure (the POLYGON structure) to allow me up to 1000 vertices without declaring it as "VERTEX vert;"? Note: I have not used pointers much aside from file-accessing stuff. Thanks for the help thus far Adrian.
If you're not comfortable with pointers then use a vector. It's less efficient, but a little easier to grasp. Create an empty vector in your POLYGON like this...
... this is now conceptually VERTEX vert;
Statically create a VERTEX...
... then initialise the vertex and put it into the vector...
temp.x = blah1;
temp.y = blah2;
temp.z = blah3;
Now your vector looks like VERTEX vert with that element in it. Keep calling push_back(), (literally, push this on the back of whatever is there so far), until you have all your vertexs defined. Voila, an array of VERTEX struct's just the right size. You need to include the <vector> header file to use them.
You might want to start with a simpler example and get comfortable with vectors, they are really very easy to use. Look at this, and look in the help for other members of the vector class you can play with.
using namespace std;
cout << v[i] << endl;
Med venlig hilsen,