Values randomly changing to zero!!
Ok, I've got a class as shown below (using a struct, also shown), the important bit is the function 'CreateTriabglePolys':
Code:
struct CUSTOMVERTEX
{
float x,y,z; //The absolute 3D position for this vertex (not transformed)
DWORD colour; //The colour of this vertex
};
class SquarePoly
{
CUSTOMVERTEX Corners[3];
public:
SquarePoly(float x1, float y1, float z1,DWORD colour1,
float x2, float y2, float z2,DWORD colour2,
float x3, float y3, float z3,DWORD colour3,
float x4, float y4, float z4,DWORD colour4)
{
Corners[0].x = x1;//Top-Left
Corners[0].y = y1;
Corners[0].z = z1;
Corners[0].colour = colour1;
Corners[1].x = x2;//Top-Right
Corners[1].y = y2;
Corners[1].z = z2;
orners[1].colour = colour2;
Corners[2].x = x3;//Bottom-Right
Corners[2].y = y3;
Corners[2].z = z3;
Corners[2].colour = colour3;
Corners[3].x = x4;//Bottom-Left
Corners[3].y = y4;
Corners[3].z = z4;
Corners[3].colour = colour4;
};
SquarePoly(){};
void CreateTrianglePolys(CUSTOMVERTEX *Vertices,const int Start)
{
Vertices[Start] = Corners[0];
Vertices[Start+1] = Corners[1];
Vertices[Start+2] = Corners[2];
Vertices[Start+3] = Corners[0];
Vertices[Start+4] = Corners[2];
Vertices[Start+5] = Corners[3];
};
};
I'm calling it in a loop with the code below:
Code:
CUSTOMVERTEX Vertices[TERRAINWIDTH*TERRAINDEPTH*2*3-1];//2 = # of triangle to represent a square, 3 = a vertices of a triangle
for(i=0;i<=TERRAINWIDTH;i++)
{
for(j=0;j<=TERRAINDEPTH;j++)
{
sqPolygons[i][j].CreateTrianglePolys(Vertices,VertexCount);
VertexCount +=2;
}
}
I've added watches to i, j and VertexCount (which is passed as a const!!) and before the call to CreateTriabglePolys, they have their correct values, but directly after, the change back to zero and i cannot for the life of me work out why.
Thanks for any help.