// md2.h

typedef struct Image Image;

typedef struct Vertex3DTNP {
	float u,v;
	float nx,ny,nz;
	float x,y,z;
} Vertex3DTNP;

typedef struct MeshTNP {
	int vertCount;
	Vertex3DTNP *vert;
} MeshTNP;

struct MD2Header {
	int ident;
	int version;
	
	int skinwidth;
	int skinheight;
	
	int framesize;
	
	int numSkins;
	int numVertices;
	int numSt;
	int numTris;
	int numGlcmds;
	int numFrames;
	
	int offsetSkins;
	int offsetSt;
	int offsetTris;
	int offsetFrames;
	int offsetGlcmds;
	int offsetEnd;
};

struct MD2Skin
{
	char name[64];
};

struct MD2TexCoord
{
	short s,t;
};

struct MD2Triangle
{
	unsigned short vertex[3];	// Index in compressed verticies
	unsigned short st[3];		// Texture coords.
};

struct MD2Vertex
{
	unsigned char v[3];
	unsigned char normalIndex;
};

struct MD2Frame
{
	float scale[3];
	float translate[3];
	char name[16];
	MD2Vertex *verts;
};

struct MD2Glcmd
{
	float s,t;
	int index;
};

typedef struct MD2Model
{
	int skinCount;
	int texCoordCount;
	int triangleCount;
	int frameCount;
	int glcmdCount;
	int vertexCount;
	
	int skinWidth,skinHeight;
	
	struct MD2Skin *skins;
	struct MD2TexCoord *texCoords;
	struct MD2Triangle *triangles;
	struct MD2Frame *frames;
	int *glcmds;
	Image *texture;
	MeshTNP *mesh;
} MD2Model;

MD2Model *md2Load(const char *fname);
MeshTNP *md2GetFrame(int frame);
MeshTNP *md2GetFractionalFrame(int frame,int nextFrame,float fraction);
void md2Free(MD2Model *model);

