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

  1. #ifndef __MILETOS_BONE_H__
  2. #define __MILETOS_BONE_H__
  3.  
  4. //
  5. // Libmiletos
  6. //
  7. // Copyright (C) Lauris Kaplinski 2008
  8. //
  9.  
  10. #include <elea/quaternion.h>
  11.  
  12. #include <miletos/pmesh.h>
  13.  
  14. namespace Miletos {
  15.  
  16. class Skeleton;
  17. class Figure;
  18.  
  19. //
  20. // Bone controller for skeletal meshes
  21. //
  22. // Attributes:
  23. // sid - The SID of bone (for animators etc.) - should be unique in skeleton hierarchy
  24. // orientation - The default transformation from controller coordinate system to parent
  25. // animatedOrientation - The current orientation of controller coordinate system
  26. // vOrientation - The transformation from bone visualization to orientation (bone is rendered along Z axis)
  27. // vLength - The length (local Z coordinate of end) of rendered bone (default 10 cm)
  28. // mirror - The SID of mirrored bone if present (L <-> R)
  29. // visible - Whether bone is visible in skeleton mode (default true)
  30. //
  31. // Bone can be attached to skeleton via skeletalbone interface
  32. // If so, they register themselves in skeleton and obtain unique and sequential index
  33. // Index will be used to signal skeleton about animation changes
  34. // Skeleton will also be notified, if any child is added or removed or bone released
  35. //
  36.  
  37. class Bone : public Object {
  38. public:
  39.     // Default is { true -PI/2 PI/2 1 1 }
  40.     struct Tension {
  41.         unsigned int enabled;
  42.         float threshold[2];
  43.         float rigidity[2];
  44.     };
  45. private:
  46.     // Object implementation
  47.     virtual const Type *objectType (void);
  48.     virtual void build (Thera::Node *pnode, Document *doc, BuildCtx *ctx);
  49.     virtual void release (void);
  50.     // The following two update child pointers and emit signals
  51.     virtual Object *childAdded (Thera::Node *cnode, Thera::Node *rnode);
  52.     virtual void childRemoved (Thera::Node *cnode, Thera::Node *rnode);
  53.     virtual void set (const char *attrid, const char *val);
  54.     virtual void write (const char *attrid);
  55.     virtual void update (UpdateCtx *ctx, unsigned int flags);
  56.  
  57.     // Helper
  58.     void updateChildData (Thera::Node *removed);
  59.     static void setTension (Tension *tension, const char *val);
  60. public:
  61.     char *sid;
  62.     char *mirror;
  63.  
  64.     // Flags
  65.     unsigned int b2p_set : 1;
  66.     unsigned int ab2p_set : 1;
  67.  
  68.     // Bone orientation in parent space
  69.     Elea::Matrix3x4f b2p;
  70.     // Animated bone orientation in parent space
  71.     Elea::Matrix3x4f ab2p;
  72.     // Transformation from object to default bone space
  73.     Elea::Matrix3x4f o2b;
  74.     // Transformation from animated bone to object space
  75.     Elea::Matrix3x4f ab2o;
  76.     // Default bounding box in object space
  77.     Elea::Cuboid3f bbox;
  78.     // Animated bounding box in object space
  79.     Elea::Cuboid3f animbbox;
  80.  
  81.     const int *axisorder;
  82.     Tension tension[3];
  83.  
  84.     // Visual data
  85.     // Orientation relative to bone local coordinate system
  86.     Orientation vOrientation;
  87.     float vLength;
  88.     bool visible;
  89.  
  90.     // Child bones
  91.     int nchildbones;
  92.     Bone **childbones;
  93.  
  94.     Bone (void);
  95.     virtual ~Bone (void);
  96.  
  97.     // Type system
  98.     static const Type *type (void);
  99.  
  100.     // Helpers
  101.     void setAB2P (const Elea::Matrix3x4f& ab2p);
  102.     Elea::Matrix3x4f getAB2O (void);
  103.     void setAB2O (const Elea::Matrix3x4f& ab2o);
  104.     Elea::Matrix3x4f getAB2W (const Elea::Matrix3x4f& o2w);
  105.     void setAB2W (const Elea::Matrix3x4f& ab2w, const Elea::Matrix3x4f& o2w);
  106.  
  107.     //
  108.     // Skeletalbone interface
  109.     //
  110.     Skeleton *skeleton;
  111.     int index;
  112.     // Will be called recursively if skeleton want to do (re)indexing
  113.     void attachToSkeleton (Skeleton *skeleton);
  114.     // Clears skeleton link and index recursively
  115.     void detachFromSkeleton (Skeleton *skeleton);
  116.     // To be called during skeleton update
  117.     // Update o2b
  118.     void UpdatePositionMatrixes (const Elea::Matrix3x4f& o2p);
  119.     // Update ab2o
  120.     void UpdateAnimationMatrixes (const Elea::Matrix3x4f& ap2o);
  121.  
  122.     // Helpers
  123.     static float calculateTension (const Tension *tension, float angle);
  124.     static float calculateDTension (const Tension *tension, float angle);
  125. };
  126.  
  127. } // Namespace Miletos
  128.  
  129. #endif
  130.  
  131.