Game Development Reference
In-Depth Information
BOOL CLWObject::ReadLayer(FILE *fp){
char buf[4];
int length;
while(1){
if (!ReadChunkHeader(fp, buf, length)) return FALSE;
if (strncmp(buf, “PNTS”, 4)==0){
if (!LoadPoints(fp, length)) return FALSE;
}
if (strncmp(buf, “POLS”, 4)==0){
if (!LoadPoints(fp, length)) return FALSE;
}
if (strncmp(buf, “PTAG”, 4)==0){
if (!LoadPTag(fp, length)) return FALSE;
}
if (strncmp(buf, “SURF”, 4)==0){
if (!LoadSurface(fp, length)) return FALSE;
}
if (strncmp(buf, “LAYR”, 4)==0) break;
}
return TRUE;
}
The point list always precedes the polygon list, so we will examine this
first.
A point chunk is identified with the chunk identifier 'PNTS'; the length of
a point chunk gives the number of points, since each point is defined by
three floating-point values and a floating-point value uses 4 bytes. To get
the number of points in a chunk, divide the length of the PNTS chunk by
12. For convenience in the sample code, I have defined a VECTOR
structure:
typedef struct stVECTOR{
float x, y, z;
}VECTOR;
A CLWObject has a member variable 'pts' that is a pointer to a
VECTOR. The class also includes a member variable 'numpoints', which
is used to ensure that we do not try to use points outside the range of
those created. In the 'LoadPoints' function we create an array of VECTOR
quantities. Then up to the 'length' of the file we keep calling the
'ReadFloat' function to read each component of the VECTOR structure.
Search Nedrilad ::




Custom Search