www.pudn.com > sxdl.zip > keyframedmesh.h


#if !defined KeyFramedMesh_Included  
#define KeyFramedMesh_Included 
 
#include "sxdl.h" 
 
//  
struct Md2Header 
{ 
	int		Ident ;				// magic number. must be equal to "IPD2" 
	int		Version ;			// md2 version. must be equal to 8 
 
	int		SkinWidth ;			// width of the texture 
	int		SkinHeight ;		// height of the texture 
	int		FrameSize ;			// size of one frame in bytes 
 
	int		SkinCount ;			// number of textures 
	int		VerticeCount ;		// number of vertices 
	int		STCount ;			// number of texture coordinates 
	int		FaceCount ;			// number of triangles 
	int		OGLCount ;			// number of opengl commands 
	int		FrameCount ;		// total number of frames 
 
	int		OffsetSkins ;		// offset to skin names (64 bytes each) 
	int		OffsetST ;			// offset to s-t texture coordinates 
	int		OffsetFaces ;		// offset to triangles 
	int		OffsetFrames ;		// offset to frame data 
	int		OffsetOGL ;			// offset to opengl commands 
	int		OffsetEnd ;			// offset to the end of file 
} ; 
// vertex 
struct Md2Vertex  
{ 
	unsigned char	v[3];				// compressed vertex (x, y, z) coordinates 
	unsigned char	LightNormalIndex;	// index to a normal vector for the lighting 
} ; 
// frame 
struct Md2Frame  
{ 
	float		Scale[3];		// scale values 
	float		Translate[3];	// translation vector 
	char		Name[16];		// frame name 
	Md2Vertex  	Vertices [ 1 ] ;	// first vertex of this frame 
} ; 
// Compressed Tex coords  
struct Md2TexCoord 
{ 
	short s, t ; 
} ; 
// indices into the vertex and texture coordinate arrays 
struct Md2Face 
{ 
	short VertexIndices  [ 3 ] ; 
	short TextureIndices [ 3 ] ; 
} ;  
 
struct Md2Skin 
{ 
	char Skin[64]; 
} ;  
 
// for normal table  
struct Md2Float3  
{ 
	float x , y , z ;  
} ;  
 
// animation 
struct Md2Animation  
{ 
	int		FirstFrame ;			// first frame of the animation 
	int		LastFrame ;				// number of frames 
	int		Fps ;					// number of frames per second 
} ; 
 
class CMd2  
{ 
	friend class CKeyFramedMesh ;  
public: 
	CMd2 ( unsigned char * Data )  
	{  
		Header    = ( Md2Header * )   Data ;  
		TexCoords = ( Md2TexCoord * ) ( Data + Header->OffsetST ) ;  
		Faces     = ( Md2Face * )     ( Data + Header->OffsetFaces ) ; 
		Frames    = ( Md2Frame * )    ( Data + Header->OffsetFrames ) ;  
		Skins     = ( Md2Skin * )     ( Data + Header->OffsetSkins ) ;  
	} ;  
	virtual ~CMd2 ( void ) { } ; 
	static Md2Float3 PrecalculatedNormals [ ] ;   
	inline static Vector3 Normal ( int i )  
	{ 
		return Vector3 ( PrecalculatedNormals [ i ].x , PrecalculatedNormals [ i ].y , PrecalculatedNormals [ i ].z ) ;   
	} ;  
	// see http://www.planetquake.com/polycount/resources/quake2/q2frameslist.shtml 
	static Md2Animation CMd2::Animations [ 20 ] ;   
	static const char * CMd2::AnimationNames [ 20 ] ;   
	enum Md2Animations  
	{ 
		STAND = 0 , 
		RUN, 
		ATTACK, 
		PAIN_A, 
		PAIN_B, 
		PAIN_C, 
		JUMP, 
		FLIPOFF, 
		SALUTE, 
		TAUNT, 
		WAVE, 
		POINT, 
		CROUCH_STAND, 
		CROUCH_WALK, 
		CROUCH_ATTACK, 
		CROUCH_PAIN, 
		CROUCH_DEATH,  
		DEATH_FALLBACK, 
		DEATH_FALLFORWARD, 
		DEATH_FALLBACKSLOW, 
	} ; 
 
private :  
	enum  
	{  
		Md2Magic = (('2'<<24) + ('P'<<16) + ('D'<<8) + 'I') , // magic number "IDP2" or 844121161 
		Md2Version = 8 ,  
		Md2MaxVertices = 2048 , // maximum number of vertices for a MD2 model 
	} ;  
	Md2Header *   Header ;  
	Md2TexCoord * TexCoords ;  
	Md2Face *     Faces ; 
	Md2Frame *    Frames ;  
	Md2Skin *     Skins ;  
} ;  
 
 
class CKeyFramedMesh : 
	public CCustomRenderer 
{ 
public: 
	enum FileFormat { Md2 } ;  
	CKeyFramedMesh (  FileFormat Tag , int FileId , int TextureId , int ShaderId , Color color = 0xFFFFFFFF ) ; 
	virtual ~CKeyFramedMesh ( void ) ; 
 
protected :  
	virtual HRESULT OnSetRenderStates ( LPDIRECT3DDEVICE9 Device ) { return S_OK ; } ;  
	virtual HRESULT OnRestoreRenderStates ( LPDIRECT3DDEVICE9 Device ) { return S_OK ; } ;  
	virtual HRESULT OnRestore ( ) ;  
	virtual HRESULT OnInvalidate ( ) { return S_OK ; } ;  
	virtual HRESULT OnSetVertexShaderConstants ( LPDIRECT3DDEVICE9 Device , CEntity * Entity );  
	virtual HRESULT OnSetPixelShaderConstants ( LPDIRECT3DDEVICE9 Device , CEntity * Entity )	{ return S_OK ; } ;  
private :  
	HRESULT OnPopulateBuffers ( void * Vertices , void * Indices ) ;  
	HRESULT OnRender ( LPDIRECT3DDEVICE9 Device , float RenderStyle ) ;  
 
	FileFormat Tag ;  
	int FileId ;  
	int TextureId ;  
	int ShaderId ;  
	Color color ;  
 
	CMd2 * Model ;  
 
	int Vertices ;  
	int TotalFrames ;  
	int CurrentFrame ;  
} ; 
 
#endif