00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __KIN_Chain__
00023 #define __KIN_Chain__
00024
00025 #include "KIN_API.h"
00026 #include <UT/UT_PtrArray.h>
00027 #include <UT/UT_Matrix4.h>
00028 #include <UT/UT_Vector3.h>
00029 #include <UT/UT_Vector3Array.h>
00030 #include <UT/UT_XformOrder.h>
00031
00032 class KIN_Bone;
00033 class KIN_Solver;
00034
00035 typedef enum {
00036 CHAIN_NUMBER_OF_BONES = 0,
00037 BONE_LENGTH,
00038 BONE_DAMPENING,
00039 BONE_ROTATE,
00040 BONE_DATA
00041 } KIN_ChangeType;
00042
00043 class KIN_API KIN_CurveParm
00044 {
00045 public:
00046 bool myClosedFlag;
00047 bool myOrientToNormalsFlag;
00048 UT_Vector3 myTangent;
00049 UT_Vector3Array myPoints;
00050 UT_Vector3Array myNormals;
00051 };
00052
00053 class KIN_API KIN_SpineParm : public KIN_CurveParm
00054 {
00055 public:
00056 float myTolerance;
00057 };
00058
00059 class KIN_API KIN_IKSolverParm
00060 {
00061 public:
00062 UT_Vector3 myEndAffectorPos;
00063 UT_Vector3 myTwistAffectorPos;
00064 int myTwistAffectorFlag;
00065 float myTwist;
00066 float myDampen;
00067 };
00068
00069 class KIN_API KIN_ConstraintParm : public KIN_IKSolverParm
00070 {
00071 public:
00072 float myTolerance;
00073 };
00074
00075 class KIN_API KIN_InverseParm : public KIN_IKSolverParm
00076 {
00077 public:
00078 KIN_InverseParm()
00079 {
00080 myResistStraight = true;
00081 myTrackingThresholdFactor = 1e-03f;
00082 }
00083
00084 float myTrackingThresholdFactor;
00085 int myResistStraight;
00086 };
00087
00088 class KIN_API KIN_Chain
00089 {
00090 public:
00091
00092 KIN_Chain();
00093 KIN_Chain(const KIN_Chain ©_from);
00094 ~KIN_Chain();
00095
00096 static const UT_XformOrder &getXformOrder() { return myXformOrder; }
00097
00098
00099
00100
00101
00102
00103
00104
00105 int getNbones() const;
00106 void setNbones(int bones);
00107 const KIN_Bone *getBone(int index) const;
00108 void updateBone(int index, float length, float *rot,
00109 float damp, const UT_Matrix4 &xform,
00110 const void *data);
00111 void setBoneRotate(int index, int axis, float r);
00112 void setBoneRotates(int index, float *r);
00113
00114
00115
00116
00117 void setConstraint( int index, float rest[3],
00118 float xrange[2], float yrange[2],
00119 float zrange[2], float damp[3],
00120 float roll[3] );
00121 float constrain( int index, int axis,
00122 float angle, float step ) const;
00123
00124
00125
00126 void getEndPosition(UT_Vector3 &result) const;
00127 void getBoneStates(UT_Matrix4 *xforms) const;
00128 float getLength() const;
00129
00130
00131 int solve(const char *type, const void *parms,
00132 KIN_Chain &solution);
00133
00134
00135 void copyFrom(const KIN_Chain &src);
00136 void copySubChain(const KIN_Chain &src, int from, int to);
00137
00138 private:
00139 void deleteBones();
00140 void initializeSolver();
00141 void chainChanged(KIN_ChangeType type);
00142
00143 UT_PtrArray<KIN_Bone *> myBones;
00144 KIN_Solver *mySolver;
00145 char *mySolverType;
00146 const void *mySolverParms;
00147 static const UT_XformOrder myXformOrder;
00148 };
00149
00150 #endif
00151