www.pudn.com > notWow.rar > Bone.h
//--------------------------------------------------------- // This file is partly from WoWModelViewer's Sourc codes // and made some modify // @BY : HADX //--------------------------------------------------------- // !!!CalMatrix() could do some modify #pragma once #includeusing namespace std; #include "Animated.h" #include "AnimMgr.h" #include "M2Block.h" #include "Enums.h" #include class Bone { protected: Animated trans; Animated rot; Animated scale; D3DXVECTOR3 pivot, transPivot; int parent; bool billboard; D3DXMATRIX* pmat; ModelBoneDef boneDef; public: bool m_bCalc; bool m_bBlend; bool m_bKey; void CalcMatrix(Bone* allbones, int anim, int time, bool rotate = true); void Init(char* f, ModelBoneDef &b, int *global,bool bBlend,D3DXMATRIX* pAMat = NULL); void Free(); inline D3DXVECTOR3 GetPivot() { return pivot; } inline D3DXMATRIX* GetMatrix() { return pmat; } inline int GetParent() { return parent;} }; // a model has 100+ bones,however,not every one is in Matrix Pallette. // if we couldnot put all the matrix of bones into the constant registers // in shader. // So,we build a matrices array:m_Matrices.it stores // all the matrix would be blended (whose bone's m_bBlend is true) class BonesContainer { protected: Bone* m_pBones; // Bones int m_nBones; int m_iBoneCounter; D3DXMATRIX* m_pMatrices; int m_nMatrices; char* m_pBlendIndex; // not all the bones will participate in vertex blending int m_BonesLookup[27]; // Bones lookup list ModelAnimation* m_pAnimations; int m_nAnimations; AnimManager* m_pAnimMgr; vector m_AnimLookup[256]; public: BonesContainer() : m_pMatrices(NULL),m_pBlendIndex(NULL), m_pAnimations(NULL),m_pAnimMgr(NULL) { memset(m_BonesLookup,-1,sizeof(int)*27); } vector GetAnimationByAct(int Act) { assert(Act >= 0 && Act <= 255); return m_AnimLookup[Act]; } inline int GetBonesCount() { return m_nBones; } inline int GetBlendMatricesCount() { return m_nMatrices ; } inline D3DXMATRIX* GetMatrices() { return m_pMatrices; } inline char* GetBlendIndex() { return m_pBlendIndex; } inline ModelAnimation* GetAnimations() { return m_pAnimations; } inline int GetAnimationsCount() { return m_nAnimations; } inline Bone* GetBones() { return m_pBones; } void Init(int nBones,int nMatrices,char* pIndices, char *pFile,ModelHeader &Header,int *global); void Free(); void SetupBoneMatrices(int Act, int Time); }; // WOW use a Z-Up Coordination System // So,we must fix the vector and quaternion /* z y z | | / |_____ x |/___x / / y */ inline D3DXVECTOR3 fixCoordSystem(D3DXVECTOR3 v) { return D3DXVECTOR3(v.x, v.z, -v.y); } inline D3DXVECTOR3 fixCoordSystem2(D3DXVECTOR3 v) { return D3DXVECTOR3(v.x, v.z, v.y); } inline D3DXQUATERNION fixCoordSystemQuat(D3DXQUATERNION v) { return D3DXQUATERNION(v.x, v.z, -v.y, v.w); } static D3DXVECTOR3 VxM(const D3DXVECTOR3 *pV,const D3DXMATRIX *pM) { /* D3DXVECTOR3 res; res.x = pM->m[0][0]*pV->x + pM->m[1][0]*pV->y + pM->m[2][0]*pV->z + pM->m[3][0]; res.y = pM->m[0][1]*pV->x + pM->m[1][1]*pV->y + pM->m[2][1]*pV->z + pM->m[3][1]; res.z = pM->m[0][2]*pV->x + pM->m[1][2]*pV->y + pM->m[2][2]*pV->z + pM->m[3][2]; */ D3DXVECTOR3 res; res.x = pM->m[0][0]*pV->x + pM->m[1][0]*pV->y + pM->m[2][0]*pV->z + pM->m[3][0]; res.y = pM->m[0][1]*pV->x + pM->m[1][1]*pV->y + pM->m[2][1]*pV->z + pM->m[3][1]; res.z = pM->m[0][2]*pV->x + pM->m[1][2]*pV->y + pM->m[2][2]*pV->z + pM->m[3][2]; return res; }