I'm trying to declare a reusable class for mesh storage. I have structs for Vertices and Triangles, both used in a variable-length array as follows:
class Mesh
{
public:
int VertCount; int TriCount;
Vert Vertices[];
Tri Triangles[];
LPSTR texpath;
};
However, whenever I write to one array, it resets the previous array. For example:
Vertices[0] = CreateVertex(100,50,10);
Vertices[1] = CreateVertex(50,100,30);
Vertices[2] = CreateVertex(10,50,30);
//if I draw the vertex array here, it will show up fine, but it won't be able to connect without the triangles.
Triangles[0] = CreateTriangle(0,1,2);
//now if I try to draw it, only Vertices[2] retains its original position, the other two are zeroed out.
Then I tried:
Vertices[0] = CreateVertex(100,50,10);
Vertices[1] = CreateVertex(50,100,30);
Vertices[2] = CreateVertex(10,50,30);
Triangles[3] = CreateTriangle(0,1,2);
and it all dispalyed fine except Vertices[0]. Vertices[0] was empty.
This is a very very very wierd problem, I'm not very used to cpp arrays (this same code worked fine when ported to VB) and I really need some help! If there's a better way to have two non-fixed arrays in a class, that would be great, or if there's some obscure C++ eqivilant to ReDim, that would be even better.