home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 5257 / source.7z / x_skel.h < prev    next >
Encoding:
C/C++ Source or Header  |  2012-03-20  |  2.4 KB  |  82 lines

  1. #ifndef __XENTAX_SKELETON_H
  2. #define __XENTAX_SKELETON_H
  3.  
  4. #define INVALID_JOINT 0xFFFFFFFF
  5.  
  6. struct JOINT {
  7.  std::string name;
  8.  uint32 parent;
  9.  boost::shared_array<float> matrix;
  10.  float rel_x;
  11.  float rel_y;
  12.  float rel_z;
  13. };
  14.  
  15. struct JOINTVISITOR {
  16.  typedef const JOINT& argument1;
  17.  typedef uint32 argument2;
  18.  typedef bool return_type;
  19. };
  20.  
  21. class SKELETON {
  22.  private :
  23.   struct TREENODE {
  24.    public :
  25.     JOINT joint;
  26.     std::deque<uint32> children;
  27.    public :
  28.     TREENODE& operator =(const TREENODE& node);
  29.    public :
  30.     TREENODE();
  31.     TREENODE(const TREENODE& node);
  32.    ~TREENODE();
  33.   };
  34.  public :
  35.   typedef TREENODE node_t;
  36.   typedef std::map<uint32, TREENODE> tree_t;
  37.   typedef std::map<uint32, TREENODE>::iterator tree_iterator;
  38.   typedef std::map<uint32, TREENODE>::const_iterator const_tree_iterator;
  39.  private :
  40.   std::string id;
  41.   uint32 root;
  42.   tree_t tree;
  43.  public :
  44.   bool insert(uint32 index, const JOINT& joint);
  45.   bool remove(uint32 index);
  46.   uint32 joints(void)const { return tree.size(); }
  47.   void set_identifier(const char* name) { id = name; }
  48.   const char* get_identifier(void)const { return id.c_str(); }
  49.  private :
  50.   template<class T>
  51.   void traverse(T& function, uint32 index)const
  52.   {
  53.    const_tree_iterator iter = tree.find(index);
  54.    if(iter == tree.end()) return;
  55.    if(!function(iter->second.joint, index)) return;
  56.    for(size_t i = 0; i < iter->second.children.size(); i++) traverse(function, iter->second.children[i]);
  57.   }
  58.  public :
  59.   template<class T>
  60.   void traverse(T& function)const
  61.   {
  62.    traverse(function, root);
  63.   }
  64.  public :
  65.   void PrintJointTree(std::stringstream& ss)const;
  66.   void PrintJointTree(std::stringstream& ss, uint32 index, uint32 level)const;
  67.   void PrintColladaNodeHeirarchy(const std::string& id, std::stringstream& ss)const;
  68.   void PrintColladaNodeHeirarchy(const std::string& id, std::stringstream& ss, uint32 index, uint32 level)const;
  69.   void PrintColladaJoints(const std::string& id, std::stringstream& ss)const;
  70.   void PrintColladaJoints(std::stringstream& ss, uint32 index)const;
  71.   void PrintColladaBindMatrices(const std::string& id, std::stringstream& ss)const;
  72.   void PrintColladaBindMatrices(std::stringstream& ss, uint32 index)const;
  73.  public :
  74.   SKELETON(const char* name = "skeleton");
  75.  ~SKELETON();
  76. };
  77.  
  78. typedef std::deque<SKELETON> SKELETON_LIST;
  79. typedef SKELETON_LIST SKELETON_LIST_ITERATOR;
  80.  
  81. #endif
  82.