home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 5036 / source.7z / x_bone.h < prev    next >
Encoding:
C/C++ Source or Header  |  2012-02-05  |  4.2 KB  |  117 lines

  1. #ifndef __XENTAX_BONE_H
  2. #define __XENTAX_BONE_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 JOINTTREENODE {
  16.  typedef std::deque<uint32> list_t;
  17.  JOINT joint;
  18.  list_t children;
  19. };
  20.  
  21. class JOINTTREE {
  22.  public :
  23.   typedef JOINTTREENODE node_t;
  24.   typedef std::map<uint32, JOINTTREENODE> tree_t;
  25.   typedef tree_t::iterator tree_iterator;
  26.   typedef tree_t::const_iterator const_tree_iterator;
  27.  private :
  28.   uint32 root;
  29.   tree_t tree;
  30.  public :
  31.   bool InsertJoint(uint32 index, const JOINT& joint);
  32.   bool RemoveJoint(uint32 index);
  33.  public :
  34.   void PrintJointTree(std::stringstream& ss)const;
  35.   void PrintJointTree(std::stringstream& ss, uint32 index, uint32 level)const;
  36.   void PrintColladaNodeHeirarchy(const std::string& id, std::stringstream& ss)const;
  37.   void PrintColladaNodeHeirarchy(const std::string& id, std::stringstream& ss, uint32 index, uint32 level)const;
  38.   void PrintColladaJoints(const std::string& id, std::stringstream& ss)const;
  39.   void PrintColladaJoints(std::stringstream& ss, uint32 index)const;
  40.   void PrintColladaBindMatrices(const std::string& id, std::stringstream& ss)const;
  41.   void PrintColladaBindMatrices(std::stringstream& ss, uint32 index)const;
  42.  public :
  43.   JOINTTREE();
  44. };
  45.  
  46. /*
  47.  
  48. template<class T>
  49. void AbsoluteToRelativeJointList(JOINTLIST<T>& jl, const JOINTTREE<T>& jt, const T& node)
  50. {
  51.  // visit children of joint tree node
  52.  JOINTTREE<T>::const_iterator jt_iter = jt.data.find(node);
  53.  if(jt_iter == jt.data.end()) return;
  54.  for(size_t i = 0; i < jt_iter->second.size(); i++) AbsoluteToRelativeJointList(jl, jt, jt_iter->second[i]);
  55.  
  56.  // obtain pointers to joints
  57.  JOINTLIST<T>::const_iterator jl_citer = jl.data.find(node);
  58.  JOINTLIST<T>::const_iterator jl_piter = jl.data.find(jl_citer->second.parent);
  59.  if(jl_piter == jl.data.end()) return;
  60.  
  61.  // modify matrix
  62.  jl_citer->second.matrix[ 3] = jl_piter->second.matrix[ 3] - jl_citer->second.matrix[ 3];
  63.  jl_citer->second.matrix[ 7] = jl_piter->second.matrix[ 7] - jl_citer->second.matrix[ 7];
  64.  jl_citer->second.matrix[11] = jl_piter->second.matrix[11] - jl_citer->second.matrix[11];
  65. }
  66.  
  67. template<class T>
  68. void AbsoluteToRelativeJointList(JOINTLIST<T>& jl, const JOINTTREE<T>& jt)
  69. {
  70.  JOINTTREE<T>::const_iterator iter = jt.data.find(jt.root);
  71.  if(iter == jt.data.end()) return;
  72.  AbsoluteToRelativeJointList(jl, jt, iter->first);
  73. }
  74.  
  75. template<class T>
  76. void PrintDAEJointTree(const JOINTLIST<T>& jl, const JOINTTREE<T>& jt, const T& node, uint32 level, std::stringstream& ss)
  77. {
  78.  // determine spacing
  79.  std::string spacing = "";
  80.  for(size_t i = 0; i < level; i++) spacing += ' ';
  81.  
  82.  // begin node
  83.  JOINTLIST<T>::const_iterator jl_iter = jl.data.find(node);
  84.  if(jl_iter == jl.data.end()) return;
  85.  ss << "   " << spacing << "<node name=\"" << jl_iter->second.name << "\" id=\"" << jl_iter->second.name << "\" type=\"JOINT\">" << std::endl;
  86.  
  87.  // print matrix
  88.  boost::shared_array<float> m = jl_iter->second.matrix;
  89.  ss << "   " << spacing << " <matrix>" << std::endl;
  90.  ss << "   " << spacing << "  " << m[ 0] << " " << m[ 1] << " " << m[ 2] << " " << m[ 3] << std::endl;
  91.  ss << "   " << spacing << "  " << m[ 4] << " " << m[ 5] << " " << m[ 6] << " " << m[ 7] << std::endl;
  92.  ss << "   " << spacing << "  " << m[ 8] << " " << m[ 9] << " " << m[10] << " " << m[11] << std::endl;
  93.  ss << "   " << spacing << "  " << m[12] << " " << m[13] << " " << m[14] << " " << m[15] << std::endl;
  94.  ss << "   " << spacing << " </matrix>" << std::endl;
  95.  
  96.  // visit children of joint tree node
  97.  JOINTTREE<T>::const_iterator jt_iter = jt.data.find(node);
  98.  if(jt_iter == jt.data.end()) return;
  99.  for(size_t i = 0; i < jt_iter->second.size(); i++) PrintDAEJointTree(jl, jt, jt_iter->second[i], level + 1, ss);
  100.  
  101.  // end node
  102.  ss << "   " << spacing << "</node>" << std::endl;
  103. }
  104.  
  105. template<class T>
  106. void PrintDAEJointTree(const JOINTLIST<T>& jl, const JOINTTREE<T>& jt, std::stringstream& ss)
  107. {
  108.  JOINTTREE<T>::const_iterator iter = jt.data.find(jt.root);
  109.  if(iter == jt.data.end()) return;
  110.  uint32 level = 0;
  111.  PrintDAEJointTree(jl, jt, iter->first, level, ss);
  112. }
  113.  
  114. */
  115.  
  116. #endif
  117.