Synergy Blades, could you post struct and code that reads values from file (the walkmesh and camera). My error might be in there.
Here s mine
void
DatFile::GetWalkMesh(TotalGeometry &walkmesh)
{
u32 offset_to_walkmesh = 0x1C + GetU32LE(0x04) - GetU32LE(0x00);
Geometry geometry;
geometry.TexEnabled = false;
u32 number_of_poly = GetU32LE(offset_to_walkmesh);
int start = offset_to_walkmesh + 0x04;
for (u32 i = 0; i < number_of_poly; ++i)
{
Vertex v[3];
v[0].p.x = -static_cast<s16>(GetU16LE(start + 0x00));
v[0].p.z = static_cast<s16>(GetU16LE(start + 0x02));
v[0].p.y = static_cast<s16>(GetU16LE(start + 0x04));
v[0].c.r = 1.0f; v[0].c.g = 0.0f; v[0].c.b = 0.0f; v[0].c.a = 1.0f;
v[1].p.x = -static_cast<s16>(GetU16LE(start + 0x08));
v[1].p.z = static_cast<s16>(GetU16LE(start + 0x0A));
v[1].p.y = static_cast<s16>(GetU16LE(start + 0x0C));
v[1].c.r = 1.0f; v[1].c.g = 0.0f; v[1].c.b = 0.0f; v[1].c.a = 1.0f;
v[2].p.x = -static_cast<s16>(GetU16LE(start + 0x10));
v[2].p.z = static_cast<s16>(GetU16LE(start + 0x12));
v[2].p.y = static_cast<s16>(GetU16LE(start + 0x14));
v[2].c.r = 1.0f; v[2].c.g = 0.0f; v[2].c.b = 0.0f; v[2].c.a = 1.0f;
geometry.AddTriangle(v);
// go to the next triangle
start += 0x18;
}
walkmesh.GeometryVector.push_back(geometry);
}
void
DatFile::GetCameraMatrix(Matrix &camera)
{
u32 offset_to_camera = 0x1C + GetU32LE(0x0C) - GetU32LE(0x00);
// get camera matrix (3 vectors)
float vxx = static_cast<float>( static_cast<s16>(GetU16LE(offset_to_camera + 0x00))) / 4096.0f;
float vxy = static_cast<float>( static_cast<s16>(GetU16LE(offset_to_camera + 0x04))) / 4096.0f;
float vxz = static_cast<float>( static_cast<s16>(GetU16LE(offset_to_camera + 0x02))) / 4096.0f;
float vyx = static_cast<float>(-static_cast<s16>(GetU16LE(offset_to_camera + 0x06))) / 4096.0f;
float vyy = static_cast<float>(-static_cast<s16>(GetU16LE(offset_to_camera + 0x0A))) / 4096.0f;
float vyz = static_cast<float>(-static_cast<s16>(GetU16LE(offset_to_camera + 0x08))) / 4096.0f;
float vzx = static_cast<float>( static_cast<s16>(GetU16LE(offset_to_camera + 0x0C))) / 4096.0f;
float vzy = static_cast<float>( static_cast<s16>(GetU16LE(offset_to_camera + 0x10))) / 4096.0f;
float vzz = static_cast<float>( static_cast<s16>(GetU16LE(offset_to_camera + 0x0E))) / 4096.0f;
Matrix mat(vxx, vyx, vzx, 0,
vxy, vyy, vzy, 0,
vxz, vyz, vzz, 0,
0, 0, 0, 1);
// get camera position in world
s16 ox = static_cast<s16>(GetU16LE(offset_to_camera + 0x14));
s16 oy = -static_cast<s16>(GetU16LE(offset_to_camera + 0x16));
s16 oz = static_cast<s16>(GetU16LE(offset_to_camera + 0x18));
float tx = -(ox * vxx + oy * vyx + oz * vzx);
float ty = -(ox * vxy + oy * vyy + oz * vzy);
float tz = -(ox * vxz + oy * vyz + oz * vzz);
// Matrix mat2;
// MatrixTranslation(mat2, -tx, -ty, -tz);
// printf("%f %f %f", tx, ty, tz);
// MatrixMultiply(camera, mat, mat2);
camera = LookAt(tx, ty, tz, vzx, vzy, vzz, 0, 1, 0);
}