How come I don't get the complete track from the SMX file? Problem with my program or is that the whole thing you get from the SMX? (see attachment)
FILE *file;
file = fopen(filename_, "rb");
if (file == NULL) {
open_ = false;
// TODO: raise error, could not open
} else {
lfsSMX_HEADER smxHeader;
fread(&smxHeader, sizeof(lfsSMX_HEADER), 1, file);
glBegin(GL_TRIANGLES);
for (int i = 1; i <= smxHeader.num_objects; i++) {
lfsSMX_OBJECT smxObject;
fread(&smxObject, sizeof(lfsSMX_OBJECT), 1, file);
// store object points for use below when we get the triangles
lfsSMX_POINT smxPoints[smxObject.num_points];
fread(smxPoints, sizeof(lfsSMX_POINT), smxObject.num_points, file);
// easy to adjust opacity
int alpha = 255;
// read all the triangles for this object
for (int j = 1; j <= smxObject.num_tris; j++) {
lfsSMX_TRIANGLE smxTriangle;
fread(&smxTriangle, sizeof(lfsSMX_TRIANGLE), 1, file);
glColor4ub(smxPoints[smxTriangle.vertex_A].colour[2], smxPoints[smxTriangle.vertex_A].colour[1], smxPoints[smxTriangle.vertex_A].colour[0], alpha);
glVertex3i(smxPoints[smxTriangle.vertex_A].X, smxPoints[smxTriangle.vertex_A].Y, smxPoints[smxTriangle.vertex_A].Z);
glColor4ub(smxPoints[smxTriangle.vertex_B].colour[2], smxPoints[smxTriangle.vertex_B].colour[1], smxPoints[smxTriangle.vertex_B].colour[0], alpha);
glVertex3i(smxPoints[smxTriangle.vertex_B].X, smxPoints[smxTriangle.vertex_B].Y, smxPoints[smxTriangle.vertex_B].Z);
glColor4ub(smxPoints[smxTriangle.vertex_C].colour[2], smxPoints[smxTriangle.vertex_C].colour[1], smxPoints[smxTriangle.vertex_C].colour[0], alpha);
glVertex3i(smxPoints[smxTriangle.vertex_C].X, smxPoints[smxTriangle.vertex_C].Y, smxPoints[smxTriangle.vertex_C].Z);
}
}
glEnd();
open_ = true;
}
FileStream fs = new FileStream(SMX_file_name, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
int numOfPoints, numOfTriangles;
fs.Position = 60;
int numberOfObjects = br.ReadInt32();
int[] pointX = new int[3000];
int[] pointY = new int[3000];
int[] pointZ = new int[3000];
Color[] vertexColor = new Color[3000];
int red, green, blue;
int triangleA, triangleB, triangleC;
int vert_offset = 0;
fs.Position = 64;
for (int i = 0; i < numberOfObjects; i++)
{
fs.Position = fs.Position + 16;
numOfPoints = br.ReadInt32();
numOfTriangles = br.ReadInt32();
for (int j = 0; j < numOfPoints; j++)
{
pointX[j] = br.ReadInt32();
pointY[j] = br.ReadInt32();
pointZ[j] = br.ReadInt32();
red = br.ReadByte();
green = br.ReadByte();
blue = br.ReadByte();
vertexColor[j] = Color.FromArgb(blue, green, red);
fs.Position = fs.Position + 1;
}
for (int j = 0; j < numOfTriangles; j++)
{
triangleA = br.ReadInt16();
triangleB = br.ReadInt16();
triangleC = br.ReadInt16();
fs.Position = fs.Position + 2;
vertices[vert_offset].Position = new Vector3(pointX[triangleA], pointY[triangleA], pointZ[triangleA]);
vertices[vert_offset].Color = vertexColor[triangleA].ToArgb();
vertices[vert_offset + 1].Position = new Vector3(pointX[triangleB], pointY[triangleB], pointZ[triangleB]);
vertices[vert_offset + 1].Color = vertexColor[triangleB].ToArgb();
vertices[vert_offset + 2].Position = new Vector3(pointX[triangleC], pointY[triangleC], pointZ[triangleC]);
vertices[vert_offset + 2].Color = vertexColor[triangleC].ToArgb();
vert_offset = vert_offset + 3;
numberOfTrianglesToDraw++;
}
}
fs.Close();
br.Close();
struct lfsSMX_HEADER {
char LFSSMX[6];
unsigned char game_version, game_revision, SMX_version;
unsigned char dimensions, resolution, vertex_colours;
char spare1[4];
char track[32];
unsigned char ground_col[3];
char spare2[9];
int num_objects;
};
struct lfsSMX_OBJECT {
int X, Y, Z, radius;
int num_points, num_tris;
};
struct lfsSMX_POINT {
int X, Y, Z;
unsigned char colour[4];
};
struct lfsSMX_TRIANGLE {
unsigned short vertex_A, vertex_B, vertex_C, spare;
};
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
drag = true;
mouseX = e.X;
mouseY = e.Y;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
drag = false;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (drag)
{
vCameraPos.X = vCameraPos.X - (e.X - mouseX) * 70000 * aspectRatio;
vCameraPos.Y = vCameraPos.Y + (e.Y - mouseY) * 70000;
vTarget.X = vTarget.X - (e.X - mouseX) * 70000 * aspectRatio;
vTarget.Y = vTarget.Y + (e.Y - mouseY) * 70000;
drawFromData();
}
mouseX = e.X;
mouseY = e.Y;
}