View Single Post
  #31  
Old 09-20-2004, 10:26 AM
jbb
Hill Giant
 
Join Date: Mar 2003
Location: UK
Posts: 242
Default

Well I'm doing this... Based slightly on your code... It's not perfect code but I've been hacking it a lot as I go, it could do with some proper structures and stuff. Too many global variables :(

I'm hoping that "verts" and "tris" will contain pointers to the vertex and triangle structures based on counting back from the end of the file. Which is why I suspected that either I've somehow got yhe counts, or the file size wrong.

Code:
void ProcessTERFile(char* terdata, int size)
{
	int magic		= *(long*)(terdata+0);
	int unk			= *(long*)(terdata+4);
	int list_length = *(long*)(terdata+8);
	int obj_count   = *(long*)(terdata+12);
	int vert_count  = *(long*)(terdata+16);
	int poly_count  = *(long*)(terdata+20);

	assert(sizeof(TERVertex) == 32);
	assert(sizeof(TERTriangle) == 20);

	char* verts = terdata + size - (vert_count * sizeof(TERVertex) + poly_count * sizeof(TERTriangle) + 4);
	char* tris  = terdata + sizeof(TERVertex) * vert_count;

	g_nVerts = vert_count;
	g_Verts  = (TERVertex*)verts;

	g_nTriangles = poly_count;
	g_Triangles  = (TERTriangle*)tris;

	/* Now process the texture names part */
	char* p = terdata + 24;
Reply With Quote