www.pudn.com > QuadTreeLOD4cs.rar > Loaders.h, change:2003-06-12,size:4115b


//------------------------------------------------------------------// 
//- class CTexture --------------------------------------------------// 
//------------------------------------------------------------------// 
//- The main m_nTxt class, has loading support for truevision	   -// 
//- targas (.tga), and the Microsoft Bitmap (.bmp) format.		   -// 
//------------------------------------------------------------------// 
#include "gamehead.h" 
 
 
 
//------------------------------------------------------------------// 
//- CMD2 STRUCTURES -------------------------------------------------// 
//------------------------------------------------------------------// 
 
//------------------------------------------------------------------// 
//- class CMD2 ------------------------------------------------------// 
//------------------------------------------------------------------// 
//- A class for the Quake 2 model mesh (includes key m_pFrames for    -// 
//- animation).													   -// 
//------------------------------------------------------------------// 
class CMD2 
{ 
	typedef struct MD2_HEADER_TYP 
	{ 
		int magic;				//The 'magic' number (always 844121161) 
		int version;			//The version number of the file (always 8) 
		int skinWidth;			//The width of the model's skin 
		int skinHeight;		//The height of the model's skin 
		int m_nFrameSize;			//The size of each frame (in BYTEs) 
		int numSkins;			//The model's number of skins 
		int numBertices;		//The model's number of vertices 
		int numTexcoords;		//The model's number of m_nTxt coordinates (most likely, its not the same number as the vertices) 
		int nTriangles;		//The number of triangles that make up the model 
		int nGlCommands;		//The number of DWORDs (4 bytes) in the GLcommand list (which decide to render the model with tri strips, or fans) 
		int nFrames;			//The number of m_pFrames (of animation) that the model has 
		int offsetSkins;		//Offset in the file of the model, to where the skin information is 
		int offsetTexcoords;	//Offset in the file of the model, to where the m_nTxt coordinate information is 
		int offsetTriangles;	//Offset in the file of the model, to where the traingle information is 
		int offsetFrames;		//Offset in the file of the model, to where the first frame information is given 
		int offsetGlCommands;	//Offset in the file of the model, to where the GLcommand information is 
		int offsetEnd;			//Offset in the file of the model, to where the end of it is 
	} MD2_HEADER, *MD2_HEADER_PTR; 
	 
	typedef struct MD2_VERTEX_TYP 
	{ 
		unsigned char vertex[3];		//Scaled version of the model's 'real' vertex coordinate 
		unsigned char lightNormalIndex;	//An index into the table of normals, kept by Quake 2 
	} MD2_VERTEX, *MD2_VERTEX_PTR; 
	 
	typedef struct MD2_FRAME_TYP 
	{ 
		float	   scale[3];		//The scale used by the model's 'fake' vertex structure 
		float	   translate[3];	//The translation used by the model's 'fake' vertex structure 
		char	   name[16];		//The name for the frame 
		MD2_VERTEX vertices[1];		//An array of MD2_VERTEX structures 
	} MD2_FRAME, *MD2_FRAME_PTR; 
	 
	typedef struct MD2_MODELVERTEX_TYP 
	{ 
		float x,y,z;				//The (x,y,z) location of the vertex 
		float u,v;					//The (u,v) location of the m_nTxt coordinate 
	} MD2_MODELVERTEX, *MD2_MODELVERTEX_PTR; 
	 
private: 
	int m_nGlCommands; 
	long* m_pGLCommands; 
	 
	int m_nTriangles; 
	 
public: 
	void Animate(); 
	int stateStart; 
	int stateEnd; 
	 
	int m_nFrameSize; 
	int m_nFrames; 
	char* m_pFrames; 
	 
	int currentFrame; 
	int nextFrame; 
	int m_nCurrentFrame; 
	int m_nNextFrame; 
	int endFrame; 
	float interpolation; 
	 
	bool Load(char* filename); 
	void Render(int numFrame); 
	float GetPercent(); 
	CMD2() : stateStart(0), stateEnd(0), 
		m_nGlCommands(0), m_nFrameSize(0), m_nFrames(0),  
		currentFrame(0), nextFrame(currentFrame+1), 
		endFrame(0), interpolation(0.0f) 
	{ 
		m_nCurrentFrame = 0; 
		m_nNextFrame = 0; 
		m_pGLCommands = 0; 
		m_pFrames = 0; 
	} 
	 
	~CMD2() 
	{	 
		if(m_pGLCommands) 
			delete[] m_pGLCommands; 
		if(m_pFrames) 
			delete[] m_pFrames; 
	} 
};