PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcharacter/lljointsolverrp3.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 176 lines | 36 code | 19 blank | 121 comment | 0 complexity | 3acd179ed36e8b4c031b5d6f62523aff MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lljointsolverrp3.h
  3. * @brief Implementation of LLJointSolverRP3 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_LLJOINTSOLVERRP3_H
  27. #define LL_LLJOINTSOLVERRP3_H
  28. //-----------------------------------------------------------------------------
  29. // Header Files
  30. //-----------------------------------------------------------------------------
  31. #include "lljoint.h"
  32. /* -some compilers don't like line continuation chars-
  33. //-----------------------------------------------------------------------------
  34. // class LLJointSolverRP3
  35. //
  36. // This class is a "poor man's" IK for simple 3 joint kinematic chains.
  37. // It is modeled after the 'ikRPSolver' in Maya.
  38. // This class takes 4 LLJoints:
  39. // jointA
  40. // jointB
  41. // jointC
  42. // jointGoal
  43. //
  44. // Such that jointA is the parent of jointB, jointB is the parent of jointC.
  45. // When invoked, this class modifies the rotations of jointA and jointB such
  46. // that the position of the jointC attempts to reach the position of jointGoal.
  47. //
  48. // At object initialization time, the distances between jointA - jointB and
  49. // jointB - jointC are cached. During evaluation these bone lengths are
  50. // preserved.
  51. //
  52. // A A
  53. // | |
  54. // | |
  55. // B B---CG A---B---C...G
  56. // \
  57. // \
  58. // CG
  59. //
  60. //
  61. // In addition a "poleVector" is specified that does two things:
  62. //
  63. // a) defines the plane in which the solution occurs, thus
  64. // reducing an infinite number of solutions, down to 2.
  65. //
  66. // b) disambiguates the resulting two solutions as follows:
  67. //
  68. // A A A--->poleVector
  69. // | \ \
  70. // | \ \
  71. // B vs. B ==> B
  72. // \ | |
  73. // \ | |
  74. // CG CG CG
  75. //
  76. // A "twist" setting allows the solution plane to be rotated about the
  77. // line between A and C. A handy animation feature.
  78. //
  79. // For "smarter" results for non-coplanar limbs, specify the joints axis
  80. // of bend in the B's local frame (see setBAxis())
  81. //-----------------------------------------------------------------------------
  82. */
  83. class LLJointSolverRP3
  84. {
  85. protected:
  86. LLJoint *mJointA;
  87. LLJoint *mJointB;
  88. LLJoint *mJointC;
  89. LLJoint *mJointGoal;
  90. F32 mLengthAB;
  91. F32 mLengthBC;
  92. LLVector3 mPoleVector;
  93. LLVector3 mBAxis;
  94. BOOL mbUseBAxis;
  95. F32 mTwist;
  96. BOOL mFirstTime;
  97. LLMatrix4 mSavedJointAMat;
  98. LLMatrix4 mSavedInvPlaneMat;
  99. LLQuaternion mJointABaseRotation;
  100. LLQuaternion mJointBBaseRotation;
  101. public:
  102. //-------------------------------------------------------------------------
  103. // Constructor/Destructor
  104. //-------------------------------------------------------------------------
  105. LLJointSolverRP3();
  106. virtual ~LLJointSolverRP3();
  107. //-------------------------------------------------------------------------
  108. // setupJoints()
  109. // This must be called one time to setup the solver.
  110. // This must be called AFTER the skeleton has been created, all parent/child
  111. // relationships are established, and after the joints are placed in
  112. // a valid configuration (as distances between them will be cached).
  113. //-------------------------------------------------------------------------
  114. void setupJoints( LLJoint* jointA,
  115. LLJoint* jointB,
  116. LLJoint* jointC,
  117. LLJoint* jointGoal );
  118. //-------------------------------------------------------------------------
  119. // getPoleVector()
  120. // Returns the current pole vector.
  121. //-------------------------------------------------------------------------
  122. const LLVector3& getPoleVector();
  123. //-------------------------------------------------------------------------
  124. // setPoleVector()
  125. // Sets the pole vector.
  126. // The pole vector is defined relative to (in the space of) jointA's parent.
  127. // The default pole vector is (1,0,0), and this is used if this function
  128. // is never called.
  129. // This vector is normalized when set.
  130. //-------------------------------------------------------------------------
  131. void setPoleVector( const LLVector3& poleVector );
  132. //-------------------------------------------------------------------------
  133. // setBAxis()
  134. // Sets the joint's axis in B's local frame, and enable "smarter" solve().
  135. // This allows for smarter IK when for twisted limbs.
  136. //-------------------------------------------------------------------------
  137. void setBAxis( const LLVector3& bAxis );
  138. //-------------------------------------------------------------------------
  139. // getTwist()
  140. // Returns the current twist in radians.
  141. //-------------------------------------------------------------------------
  142. F32 getTwist();
  143. //-------------------------------------------------------------------------
  144. // setTwist()
  145. // Sets the twist value.
  146. // The default is 0.0.
  147. //-------------------------------------------------------------------------
  148. void setTwist( F32 twist );
  149. //-------------------------------------------------------------------------
  150. // solve()
  151. // This is the "work" function.
  152. // When called, the rotations of jointA and jointB will be modified
  153. // such that jointC attempts to reach jointGoal.
  154. //-------------------------------------------------------------------------
  155. void solve();
  156. };
  157. #endif // LL_LLJOINTSOLVERRP3_H