Game Development Reference
In-Depth Information
One slight surprise is that the z orientation for a Lightwave model is the
inverse of that expected by OpenGL, so we flip the z value to ensure
consistency between the Lightwave interface display and our OpenGL
display. As long as there are no file read errors, the function returns the
number of points read. If there is a file read error then the function returns
zero.
int CLWObject::LoadPoints(FILE *fp, int length)
{
int numpts, count;
VECTOR *pt;
numpts = length/12;
pts = new VECTOR[numpts];;
if (!pts) return 0;
count=0;
pt = pts;
while(count<length){
if (!ReadFloat(fp, pt->x)) return 0;
if (!ReadFloat(fp, pt->y)) return 0;
if (!ReadFloat(fp, pt->z)) return 0;
pt->z = -pt->z;
pt++;
count+=12;
}
numpoints=numpts;
//Align to even boundary
if (length%2) fseek(fp,1,SEEK_CUR);
//Must have gone OK
return numpts;
}
Having created an array of points we next create an array of polygons.
A polygon is defined as having a certain number of vertices; in our simple
application this value is restricted to three or four. Vertices are indicated
by the index into the point array. Surface information is stored as an index
into the surface array. Polygon chunks can also define sub-patch
polygons, so we check first that we are dealing with a regular polygon list
Search Nedrilad ::




Custom Search