用多叉數組織骨骼結構

來源:互聯網
上載者:User

       上班了!好久沒來彙報工作情況了。五一過的真累,但也挺開心。爸媽來上海一躺不容易,當然要好好陪著,累並快樂著!

    這兩天寫了個多叉樹的類SkeletonTree,用來組織骨骼資料結構。骨骼資料Frame_EX的設計這是借鑒了D3D中的D3DXFRAME,左子女右兄弟是關鍵,還有一個指向父節點的指標。這麼設計的要點是非常容易遞迴調用,在更新骨骼資料時很管用。哎,做什麼事情之前一定要充分調查,“沒有調查就沒有發言權”!如果路都走錯了,再強的編程能力也是彌補不了的。

class Frame_EX : public ManipulatedFrame 
{
public:
 Frame_EX();
 virtual ~Frame_EX();

public:
 Frame_EX* Find(const char* name);
 void  UpdateHierarchy(CVector3D* pos = NULL, CQuaternion* ori = NULL);
 void  Reset();

public:
 char*   m_name;
 Frame_EX*  m_pFrameSibling;
 Frame_EX*  m_pFrameFirstChild;

 CQuaternion  m_oriCombined;  //儲存當前節點相對於根節點的旋轉位移四元數
 CVector3D  m_posCombined;  //儲存當前節點相對於根節點的位移位移向量

 CQuaternion  m_oriOriginal;  //儲存骨骼的原始旋轉四元數(相對於父節點)
 CVector3D  m_posOriginal;  //儲存骨骼的原始位移向量(相對於父節點)
};

class SkeletonTree 
{
public:
 SkeletonTree();
 virtual ~SkeletonTree();
 SkeletonTree(const SkeletonTree& sTree);
 SkeletonTree& operator=( const SkeletonTree& sTree);

public:
 const Frame_EX* rootFrame() { return m_root; }

 bool empty() { return m_root == NULL; }

 void InsertSibling(Frame_EX* pInsertAfter, const char* name);
 void InsertChild(Frame_EX* pParent, const char* name);
 
 Frame_EX* Find(char *name);

 void DeleteNode(Frame_EX* pNode);

protected:
 void DeleteNodeRecursive(Frame_EX* pNode);

private:
 Frame_EX* m_root;
};
這個SkeletonTree類寫的比較簡單,只是應付一下當下的需要,還有很多地方可以擴充的,有待以後繼續吧!把這些標頭檔列出,給他人一些借鑒的同時更希望得到大家的反饋,思想的交流才能碰撞出火花。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.