The MD2 Model seems fairly straightforward and simple, up until one point. What is stored after you get to the frame offset? Reading the code supplied from gametutorials.com, it seems like the data there is in the format
struct AliasVertex
{
unsigned char vertex[3];
unsigned char NormalIndex;
};
struct AliasFrame
{
float scale[3];
float translate[3];
char name[16]
AliasVertex *Vertices;
// It appears to me that this number will be assigned *Vertices = (unsigned char *)malloc(sizeof(unsigned char) * NumVertices))
};
This would make sense to me, as the code given by gametutorials has a loop that looks like this:
for (int j=0; j < m_Header.numVertices; j++)
{
pVertices[j].vertex[0] = pFrame->aliasVertices[j].vertex[0] * pFrame->scale[0] + pFrame->translate[0];
pVertices[j].vertex[2] = -1 * (pFrame->aliasVertices[j].vertex[1] * pFrame->scale[1] + pFrame->translate[1]);
pVertices[j].vertex[1] = pFrame->aliasVertices[j].vertex[2] * pFrame->scale[2] + pFrame->translate[2];
}
Where pFrame is a pointer to an unsigned char buffer, that is casted to an AliasTriangle. Anyways, I mean that scale, transform are never incremented, so it looks like there is just one, with a whole list of vertices. Also, it looks like the name is only specified once because they have
strcpy(m_pFrames[i].strName, pFrame->name);
If it were specified as I stated above, this might make sense to me, but it''s not. Here is what they do. They have these struct:
struct AliasTriangle
{
unsigned char vertex[3];
unsigned char NormalIndex;
};
struct AliasFrame
{
float scale[3];
float translate[3];
char name[16]
AliasTriangle Vertices[1];
// It appears to me that this number will be assigned *Vertices = (unsigned char *)malloc(sizeof(unsigned char) * NumVertices)) so why in the world is there only one space allocated, and why in an unsigned char array, parsed as an AliasFrame *, is there only one of everything but this?
};
What in the hell? How is their loop possible then? Only one vertex is ever allocated. Why aren''t there a series of AliasFrames then, and only one name, one scale, and one translate value, (i.e. no pframe
.scale[0]. They just put pframe.scale[0]) (also no pframe.scale[0] or pframe.translate[0]. It is just pframe.scale[0] and pframe.translate[0]). I''m so lost as to how this little piece of code is working.
Anyways, if you know how the data is formatted at this section of the file, please enlighten me, as I''d love to know. If you want to look at the code itself, it is the md2 animation code at www.gametutorials.com. </i>