Well, i decided to rewrite my MD2 loader (to be safer and also to use VBO's)
and ive hit a snag, i got everything loaded up and nice, i can render the first frame fine:
and
but then i went to animate it...it seems that the last few frames of the "stand" animation are corrupted somehow, as if some of the vertices are 0 or infinity or something
*sniff* thats all thats become of john mclain... that happens around frame 38 or 39
heres the majority of my loading code
TempAnim.FirstFrame = 0;
TempAnim.NumFrames = 0;
for (UINT i = 0; i < Header.NumFrames; ++i)
{
iFile.read(reinterpret_cast <char *> (&TempFrame), sizeof(MD2::FileFrame));
TempFrame.Position;
StripNumber(TempFrame.Name);
if (LastAniName == std::string(TempFrame.Name))
++(TempAnim.NumFrames);
else
{
LastAniName = TempFrame.Name;
++TempAnim.NumFrames;
Animations.push_back(TempAnim);
TempAnim.Name = LastAniName;
TempAnim.FirstFrame = i;
TempAnim.NumFrames = 0;
}
for (UINT j = 0; j < Header.NumVertices; ++j)
{
iFile.read(reinterpret_cast <char *> (&TempFileVertex), sizeof(MD2::FileVertex));
TempVertex.x = TempFileVertex.x * TempFrame.Scale.x;
TempVertex.y = TempFileVertex.z * TempFrame.Scale.z;
TempVertex.z = TempFileVertex.y * TempFrame.Scale.y;
TempVertex += TempFrame.Position;
TempVertex *= MD2::SCALE;
FileVertices.push_back(TempVertex);
}
memset(&TempFrame, 0, sizeof(MD2::FileFrame));
}
iFile.close();
//HACK
Animations.erase(Animations.begin());
Vertices.reserve(Header.NumTriangles * Header.NumFrames * 3);
TexCoords.reserve(Header.NumTriangles * 3);
for (UINT Tri = 0; Tri < Header.NumTriangles; ++Tri)
for (UINT Vert = 0; Vert < 3; ++Vert)
{
TexCoords.push_back(CVector2(((FileTexCoords[FileTriangles[Tri].TextureCoordIndices[Vert]].s)
/ static_cast <float> (Header.TextureWidth)),
(FileTexCoords[FileTriangles[Tri].TextureCoordIndices[Vert]].t - 1.0f)
/ static_cast <float> (Header.TextureHeight * -1.0f)
));
}
for (UINT Frame = 0; Frame < Header.NumFrames; ++Frame)
for (UINT Tri = 0; Tri < Header.NumTriangles; ++Tri)
{
for (UINT Vert = 0; Vert < 3; ++Vert)
Vertices.push_back(FileVertices[FileTriangles[Tri].VertexIndices[Vert]
+ Header.NumVertices * Frame]);
}
anything that begins with File, is the actual structure present in the file, all containers are std::vectors, and heres the definitions for most of those structs
struct FileVertex
{
union
{
BYTE Arr[3];
struct
{
BYTE x, y, z;
};
};
BYTE normalIndex;
};
struct FileFrame
{
CVector3 Scale;
CVector3 Position;
char Name[16];
};
struct Frame
{
std::string & Name;
UINT FirstFrame;
UINT LastFrame;
};
struct Triangle
{
USHORT VertexIndices[3];
USHORT TextureCoordIndices[3];
};
struct GLCommandVertex
{
CVector2 TexCoord;
UINT Index;
};
struct GLCommand
{
UINT Type;
UINT NumVertices;
GLCommandVertex * Vertices;
};
struct Shader
{
char Path[MAX_QPATH];
unsigned int ShaderIndex;
};
struct Header
{
GLubyte IDP2[4];
GLuint Version;
GLuint TextureWidth;
GLuint TextureHeight;
GLuint FrameSize; // = sizeof(MD2Frame) + num vertices * sizeof(MD2Vertex) ??
GLuint NumTextureNames;
GLuint NumVertices;
GLuint NumTexCoords;
GLuint NumTriangles;
GLuint NumGLCommands;
GLuint NumFrames;
GLuint OffsetTextureNames;
GLuint OffsetTexCoords;
GLuint OffsetTriangles;
GLuint OffsetFrames;
GLuint OffsetGLCommands;
GLuint OffsetEnd;
};
struct FileTexCoord
{
union
{
struct
{
USHORT s, t;
};
struct
{
USHORT u, v;
};
USHORT Arr[2];
};
};
struct Animation
{
public:
std::string Name;
USHORT FirstFrame;
USHORT NumFrames;
};
i know its a lot of code, but my hunch is the problem lies where i read the vertices in, either that or transfer them into an array (which will eventually be indexed, but untill then)
thanks a ton
-Dan
[Edited by - Ademan555 on January 19, 2005 9:09:06 AM]
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."