/* * ImportWorld Objs.cpp * ---------------------------------------- * A part of "Intelligent AI" * © 2001 SCC Team 064 * ---------------------------------------- * * This file: * € imports the various ships from external files. */ #include "MacInput.h" #include int iNumVert, sNumVert; /* readstr() */ //---------------------------------------------------------------------------------------------- void readstr(FILE *f, char *string) { do { fgets(string, 255, f); } while ((string[0] == '/') || (string[0] == '\n')); return; } /* Setup World Objects */ //---------------------------------------------------------------------------------------------- void SetupObjcts() { float x, y, z; int i1, i2, i3, i4; FILE *fileShip, *fileIndices; char oneline[255]; fileShip = fopen(":DATA:SHIP.TXT", "rt"); // File To Load Ship Data From File fileIndices = fopen(":DATA:SINDICES.TXT", "rt"); // File To Load ShipIndices Data From File if (fileShip) { readstr(fileShip, oneline); sscanf(oneline, "Vertices: %d\n", &sNumVert); // Read plane Vertices for (int loop = 0; loop < sNumVert; loop++) // Import plane Vertices { readstr(fileShip, oneline); sscanf(oneline, "%f %f %f\n", &x, &y, &z); vertices[loop][0] = x * .001; vertices[loop][1] = y * .001; vertices[loop][2] = z * .001; } fclose(fileShip); } if (fileIndices) { readstr(fileIndices, oneline); sscanf(oneline, "Indices: %d\n", &iNumVert); // Read plane Indices for (int loop = 0; loop < iNumVert; loop++) // Import plane Indices { i4 = 0; readstr(fileIndices, oneline); sscanf(oneline, "%i %i %i %i\n", &i1, &i2, &i3, &i4); indices[loop][0] = i1; indices[loop][1] = i2; indices[loop][2] = i3; indices[loop][3] = i4; } fclose(fileIndices); } }