How to write a C Program to Extracts height data from a specially prepared OBJ file and inserts it into ADT.
//--------------------------------------
//
// File: OBJtoADT Terrain Exporter
// Author: Koward and Skarn
// Revision: 1.0.0
// Purpose: Extracts height data from a specially prepared OBJ file and inserts it into ADT.
//--------------------------------------
char sFile[], tFile[];
int sIndex, tIndex;
sFile = InputOpenFileName("Select an OBJ file", ".obj");
sIndex = FileOpen(sFile);
if(sIndex < 0)
return;
ObjParsing();
FileClose();
tFile = InputOpenFileName("Select an ADT file", ".adt");
tIndex = FileOpen(tFile);
if(tIndex < 0)
return;
Insertion();
FileSave();
FileClose();
// Functions
void OBJParsing()
{
int maxLineSize = 1024;
int heightNumber = 37120;
int fileSize = FileSize();
int pos = 0;
float heights[heightNumber][16][16];
int index = 0;
int row = 0;
int mcnk = 0;
char line[maxLineSize];
string x, y, z, a, b;
float height;
string token;
while(pos < fileSize) {
line = ReadLine(pos);
SScanf(line, "%s *", token);
Printf("Found %s token\n", token);
if(token == "o")
{
SScanf(line, "o %s %s", a, b);
row = Atoi(a);
mcnk = Atoi(b);
pos = pos + Strlen(line);
line = ReadLine(pos);
SScanf(line, "%s *", token);
while(token == "v")
{
SScanf(line, "v %s %s %s", x, y, z);
height = Atof(z);
heights[index][row][mcnk] = height;
index++;
pos = pos + Strlen(line);
line = ReadLine(pos);
SScanf(line, "%s *", token);
}
}
}
}
void Insertion()
{
int a, y, z;
RunTemplate( "WoWADT.bt" );
for( z = 0; z < 16; z++ )
{
for( y = 0; y < 16; y++ )
{
for( a = 0; a < 145; a++)
{
ADT_file.MCNKs.row[z].mcnk[y].mcvt.heightmap[a] = heights[a][z][y];
}
}
}
}