• 11
• 14
• 19
• 27
• 9

# MD2 Woes *SCREENIES*

This topic is 4787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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)
{

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)
{

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());

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)
(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]
}


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;
};

{
char Path[MAX_QPATH];
};

{
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]

##### Share on other sites
this looks familiar ;)

this may be something to do with the scale and translate values if you are storing the animation frames as unsigned char vertex coords. You may need to swizzle the values in the scale and translate keys to get the correct looking animations...

##### Share on other sites
Hrm, I agree that it SHOULD be that way (and it works), i looked at my old code and, yep, it was x = x, y = z, and z = y for translation, scale, and the original vertex, but it unfortunately didnt fix my problem with the last few frames

the sas's model has a bit tamer of an error ;-)

EDIT: update, it seems, that its running frames that it shouldnt be, IE i saw a "death" frame in there, yet, when i check the frame that it says its on, it says its on the 35-39 "Stand" frame, which says to me that im not stowing away my frames correctly, somehow im screwing them up when i load, maybe im overwriting some, i dont know (i can pretty safely say its not my rendering code though, because it IS dumping out the correct frame...)

thanks
-Dan

##### Share on other sites
hate to bump... :-(
i must have the lowest posts/views ratio ever lol

any help is appreciated
-Dan

##### Share on other sites
How is California a Hippy State?

##### Share on other sites
Hello !

Could you tell me that how do you order or sort your texture coordinates and texture indices ?? please help im stuck because i draw them but without textures right :D , i want to draw with gldrawelements, i normally draw with glvertex3f, but it is not fast you know !

##### Share on other sites
Well the code above illustrates what you need to do, but ill outline it in pseudocode.

for every frame
for every triangle
for every vertex index in the current triangle
add a vertex into the vertex array using the "vertex index" as an index into the array of MD2 FILE VERTICES from the file

for every triangle
for every tex coord index in the current triangle
add a tex coord into the tex coord array using the "tex coord index" as an index into the tex coords retrieved from the md2 file

EDIT: disclaimer: i am rediculously tired right now, if this doesnt make any sense tell me, im more than out of it :-p

hope that helps
-Dan

[Edited by - Ademan555 on February 7, 2005 7:04:23 PM]