home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 5164 / miletos.7z / bvh.h < prev    next >
Encoding:
C/C++ Source or Header  |  2011-04-02  |  1.8 KB  |  83 lines

  1. #ifndef __MILETOS_BVH_H__
  2. #define __MILETOS_BVH_H__
  3.  
  4. //
  5. // Miletos
  6. //
  7. // Copyright (C) Lauris Kaplinski 2010
  8. //
  9.  
  10. #include <string>
  11. #include <vector>
  12.  
  13. #include <miletos/animation.h>
  14.  
  15. namespace Miletos {
  16.  
  17. class BVHData {
  18. public:
  19.     enum AnimCodes { XPOSITION, YPOSITION, ZPOSITION, XROTATION, YROTATION, ZROTATION };
  20. private:
  21.     u32 refcount;
  22.  
  23.     BVHData (const char *url);
  24.     BVHData (const unsigned char *cdata, size_t csize, const char *url);
  25.     ~BVHData (void);
  26.  
  27.     unsigned int parse (const unsigned char *cdata, size_t csize);
  28.     unsigned int parseBone (int parent, const char *name, const unsigned char *cdata, size_t csize, size_t& cpos);
  29. public:
  30.     char *url;
  31.  
  32.     unsigned int nframes;
  33.  
  34.     struct Bone {
  35.         std::string name;
  36.         int idx;
  37.         int pidx;
  38.         Elea::Vector3f offset;
  39.         Elea::Vector3f endsite;
  40.         // Channels
  41.         int ncodes;
  42.         AnimCodes codes[6];
  43.     };
  44.     std::vector<Bone> bones;
  45.     std::vector<Orientation> ab2p;
  46.  
  47.     // Static constructor
  48.     static BVHData *getBVHData (const char *url);
  49.     static BVHData *getBVHData (const unsigned char *cdata, size_t csize, const char *url);
  50.  
  51.     // Lifecycle
  52.     void ref (void) { refcount += 1; }
  53.     void unRef (void) { refcount -= 1; if (!refcount) delete this; }
  54. };
  55.  
  56. class BoneAnimationBVH : public Animation::BoneAnimation {
  57. private:
  58.     char *source;
  59.  
  60.     BVHData *bdata;
  61.     int bidx;
  62.  
  63.     // Object implementation
  64.     virtual const Type *objectType (void);
  65.     virtual void build (Thera::Node *pnode, Document *doc, BuildCtx *ctx);
  66.     virtual void release (void);
  67.     virtual void set (const char *attrid, const char *val);
  68.  
  69.     // BoneAnimation implementation
  70.     virtual Elea::Vector3f getPosition (unsigned int frameidx);
  71.     virtual Elea::Quaternionf getQuaternion (unsigned int frameidx);
  72. public:
  73.     BoneAnimationBVH (void);
  74.     virtual ~BoneAnimationBVH (void);
  75.  
  76.     // Type system
  77.     static const Type *type (void);
  78. };
  79.  
  80. } // Namespace Miletos
  81.  
  82. #endif
  83.