/indra/llcharacter/lljoint.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 199 lines · 103 code · 42 blank · 54 comment · 0 complexity · 6f1161e867cecf08d861757d34c3694b MD5 · raw file

  1. /**
  2. * @file lljoint.h
  3. * @brief Implementation of LLJoint class.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLJOINT_H
  27. #define LL_LLJOINT_H
  28. //-----------------------------------------------------------------------------
  29. // Header Files
  30. //-----------------------------------------------------------------------------
  31. #include <string>
  32. #include "linked_lists.h"
  33. #include "v3math.h"
  34. #include "v4math.h"
  35. #include "m4math.h"
  36. #include "llquaternion.h"
  37. #include "xform.h"
  38. #include "lldarray.h"
  39. const S32 LL_CHARACTER_MAX_JOINTS_PER_MESH = 15;
  40. const U32 LL_CHARACTER_MAX_JOINTS = 32; // must be divisible by 4!
  41. const U32 LL_HAND_JOINT_NUM = 31;
  42. const U32 LL_FACE_JOINT_NUM = 30;
  43. const S32 LL_CHARACTER_MAX_PRIORITY = 7;
  44. const F32 LL_MAX_PELVIS_OFFSET = 5.f;
  45. //-----------------------------------------------------------------------------
  46. // class LLJoint
  47. //-----------------------------------------------------------------------------
  48. class LLJoint
  49. {
  50. public:
  51. // priority levels, from highest to lowest
  52. enum JointPriority
  53. {
  54. USE_MOTION_PRIORITY = -1,
  55. LOW_PRIORITY = 0,
  56. MEDIUM_PRIORITY,
  57. HIGH_PRIORITY,
  58. HIGHER_PRIORITY,
  59. HIGHEST_PRIORITY,
  60. ADDITIVE_PRIORITY = LL_CHARACTER_MAX_PRIORITY
  61. };
  62. enum DirtyFlags
  63. {
  64. MATRIX_DIRTY = 0x1 << 0,
  65. ROTATION_DIRTY = 0x1 << 1,
  66. POSITION_DIRTY = 0x1 << 2,
  67. ALL_DIRTY = 0x7
  68. };
  69. protected:
  70. std::string mName;
  71. // parent joint
  72. LLJoint *mParent;
  73. // explicit transformation members
  74. LLXformMatrix mXform;
  75. LLXformMatrix mOldXform;
  76. LLXformMatrix mDefaultXform;
  77. LLUUID mId;
  78. public:
  79. U32 mDirtyFlags;
  80. BOOL mUpdateXform;
  81. BOOL mResetAfterRestoreOldXform;
  82. // describes the skin binding pose
  83. LLVector3 mSkinOffset;
  84. S32 mJointNum;
  85. // child joints
  86. typedef std::list<LLJoint*> child_list_t;
  87. child_list_t mChildren;
  88. // debug statics
  89. static S32 sNumTouches;
  90. static S32 sNumUpdates;
  91. public:
  92. LLJoint();
  93. LLJoint( const std::string &name, LLJoint *parent=NULL );
  94. virtual ~LLJoint();
  95. // set name and parent
  96. void setup( const std::string &name, LLJoint *parent=NULL );
  97. void touch(U32 flags = ALL_DIRTY);
  98. // get/set name
  99. const std::string& getName() const { return mName; }
  100. void setName( const std::string &name ) { mName = name; }
  101. // getParent
  102. LLJoint *getParent() { return mParent; }
  103. // getRoot
  104. LLJoint *getRoot();
  105. // search for child joints by name
  106. LLJoint *findJoint( const std::string &name );
  107. // add/remove children
  108. void addChild( LLJoint *joint );
  109. void removeChild( LLJoint *joint );
  110. void removeAllChildren();
  111. // get/set local position
  112. const LLVector3& getPosition();
  113. void setPosition( const LLVector3& pos );
  114. void setDefaultPosition( const LLVector3& pos );
  115. // get/set world position
  116. LLVector3 getWorldPosition();
  117. LLVector3 getLastWorldPosition();
  118. void setWorldPosition( const LLVector3& pos );
  119. // get/set local rotation
  120. const LLQuaternion& getRotation();
  121. void setRotation( const LLQuaternion& rot );
  122. // get/set world rotation
  123. LLQuaternion getWorldRotation();
  124. LLQuaternion getLastWorldRotation();
  125. void setWorldRotation( const LLQuaternion& rot );
  126. // get/set local scale
  127. const LLVector3& getScale();
  128. void setScale( const LLVector3& scale );
  129. // get/set world matrix
  130. const LLMatrix4 &getWorldMatrix();
  131. void setWorldMatrix( const LLMatrix4& mat );
  132. void updateWorldMatrixChildren();
  133. void updateWorldMatrixParent();
  134. void updateWorldPRSParent();
  135. void updateWorldMatrix();
  136. // get/set skin offset
  137. const LLVector3 &getSkinOffset();
  138. void setSkinOffset( const LLVector3 &offset);
  139. LLXformMatrix *getXform() { return &mXform; }
  140. void clampRotation(LLQuaternion old_rot, LLQuaternion new_rot);
  141. virtual BOOL isAnimatable() const { return TRUE; }
  142. S32 getJointNum() const { return mJointNum; }
  143. void setJointNum(S32 joint_num) { mJointNum = joint_num; }
  144. void restoreOldXform( void );
  145. void restoreToDefaultXform( void );
  146. void setDefaultFromCurrentXform( void );
  147. void storeCurrentXform( const LLVector3& pos );
  148. //Accessor for the joint id
  149. LLUUID getId( void ) { return mId; }
  150. //Setter for the joints id
  151. void setId( const LLUUID& id ) { mId = id;}
  152. //If the old transform flag has been set, then the reset logic in avatar needs to be aware(test) of it
  153. const BOOL doesJointNeedToBeReset( void ) const { return mResetAfterRestoreOldXform; }
  154. //Setter for joint reset flag
  155. void setJointToBeReset( BOOL val ) { mResetAfterRestoreOldXform = val; }
  156. };
  157. #endif // LL_LLJOINT_H