00001 00032 #ifndef LL_LLJOINTSOLVERRP3_H 00033 #define LL_LLJOINTSOLVERRP3_H 00034 00035 //----------------------------------------------------------------------------- 00036 // Header Files 00037 //----------------------------------------------------------------------------- 00038 #include "lljoint.h" 00039 00040 /* -some compilers don't like line continuation chars- 00041 //----------------------------------------------------------------------------- 00042 // class LLJointSolverRP3 00043 // 00044 // This class is a "poor man's" IK for simple 3 joint kinematic chains. 00045 // It is modeled after the 'ikRPSolver' in Maya. 00046 // This class takes 4 LLJoints: 00047 // jointA 00048 // jointB 00049 // jointC 00050 // jointGoal 00051 // 00052 // Such that jointA is the parent of jointB, jointB is the parent of jointC. 00053 // When invoked, this class modifies the rotations of jointA and jointB such 00054 // that the position of the jointC attempts to reach the position of jointGoal. 00055 // 00056 // At object initialization time, the distances between jointA - jointB and 00057 // jointB - jointC are cached. During evaluation these bone lengths are 00058 // preserved. 00059 // 00060 // A A 00061 // | | 00062 // | | 00063 // B B---CG A---B---C...G 00064 // \ 00065 // \ 00066 // CG 00067 // 00068 // 00069 // In addition a "poleVector" is specified that does two things: 00070 // 00071 // a) defines the plane in which the solution occurs, thus 00072 // reducing an infinite number of solutions, down to 2. 00073 // 00074 // b) disambiguates the resulting two solutions as follows: 00075 // 00076 // A A A--->poleVector 00077 // | \ \ 00078 // | \ \ 00079 // B vs. B ==> B 00080 // \ | | 00081 // \ | | 00082 // CG CG CG 00083 // 00084 // A "twist" setting allows the solution plane to be rotated about the 00085 // line between A and C. A handy animation feature. 00086 // 00087 // For "smarter" results for non-coplanar limbs, specify the joints axis 00088 // of bend in the B's local frame (see setBAxis()) 00089 //----------------------------------------------------------------------------- 00090 */ 00091 00092 class LLJointSolverRP3 00093 { 00094 protected: 00095 LLJoint *mJointA; 00096 LLJoint *mJointB; 00097 LLJoint *mJointC; 00098 LLJoint *mJointGoal; 00099 00100 F32 mLengthAB; 00101 F32 mLengthBC; 00102 00103 LLVector3 mPoleVector; 00104 LLVector3 mBAxis; 00105 BOOL mbUseBAxis; 00106 00107 F32 mTwist; 00108 00109 BOOL mFirstTime; 00110 LLMatrix4 mSavedJointAMat; 00111 LLMatrix4 mSavedInvPlaneMat; 00112 00113 LLQuaternion mJointABaseRotation; 00114 LLQuaternion mJointBBaseRotation; 00115 00116 public: 00117 //------------------------------------------------------------------------- 00118 // Constructor/Destructor 00119 //------------------------------------------------------------------------- 00120 LLJointSolverRP3(); 00121 virtual ~LLJointSolverRP3(); 00122 00123 //------------------------------------------------------------------------- 00124 // setupJoints() 00125 // This must be called one time to setup the solver. 00126 // This must be called AFTER the skeleton has been created, all parent/child 00127 // relationships are established, and after the joints are placed in 00128 // a valid configuration (as distances between them will be cached). 00129 //------------------------------------------------------------------------- 00130 void setupJoints( LLJoint* jointA, 00131 LLJoint* jointB, 00132 LLJoint* jointC, 00133 LLJoint* jointGoal ); 00134 00135 //------------------------------------------------------------------------- 00136 // getPoleVector() 00137 // Returns the current pole vector. 00138 //------------------------------------------------------------------------- 00139 const LLVector3& getPoleVector(); 00140 00141 //------------------------------------------------------------------------- 00142 // setPoleVector() 00143 // Sets the pole vector. 00144 // The pole vector is defined relative to (in the space of) jointA's parent. 00145 // The default pole vector is (1,0,0), and this is used if this function 00146 // is never called. 00147 // This vector is normalized when set. 00148 //------------------------------------------------------------------------- 00149 void setPoleVector( const LLVector3& poleVector ); 00150 00151 //------------------------------------------------------------------------- 00152 // setBAxis() 00153 // Sets the joint's axis in B's local frame, and enable "smarter" solve(). 00154 // This allows for smarter IK when for twisted limbs. 00155 //------------------------------------------------------------------------- 00156 void setBAxis( const LLVector3& bAxis ); 00157 00158 //------------------------------------------------------------------------- 00159 // getTwist() 00160 // Returns the current twist in radians. 00161 //------------------------------------------------------------------------- 00162 F32 getTwist(); 00163 00164 //------------------------------------------------------------------------- 00165 // setTwist() 00166 // Sets the twist value. 00167 // The default is 0.0. 00168 //------------------------------------------------------------------------- 00169 void setTwist( F32 twist ); 00170 00171 //------------------------------------------------------------------------- 00172 // solve() 00173 // This is the "work" function. 00174 // When called, the rotations of jointA and jointB will be modified 00175 // such that jointC attempts to reach jointGoal. 00176 //------------------------------------------------------------------------- 00177 void solve(); 00178 }; 00179 00180 #endif // LL_LLJOINTSOLVERRP3_H 00181