home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / game / IK.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  4KB  |  156 lines

  1.  
  2. #ifndef __GAME_IK_H__
  3. #define __GAME_IK_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.   IK base class with a simple fast two bone solver.
  9.  
  10. ===============================================================================
  11. */
  12.  
  13. #define IK_ANIM                "ik_pose"
  14.  
  15. class idIK {
  16. public:
  17.                             idIK( void );
  18.     virtual                    ~idIK( void );
  19.  
  20.     void                    Save( idSaveGame *savefile ) const;
  21.     void                    Restore( idRestoreGame *savefile );
  22.  
  23.     bool                    IsInitialized( void ) const;
  24.  
  25.     virtual bool            Init( idEntity *self, const char *anim, const idVec3 &modelOffset );
  26.     virtual void            Evaluate( void );
  27.     virtual void            ClearJointMods( void );
  28.  
  29.     bool                    SolveTwoBones( const idVec3 &startPos, const idVec3 &endPos, const idVec3 &dir, float len0, float len1, idVec3 &jointPos );
  30.     float                    GetBoneAxis( const idVec3 &startPos, const idVec3 &endPos, const idVec3 &dir, idMat3 &axis );
  31.  
  32. protected:
  33.     bool                    initialized;
  34.     bool                    ik_activate;
  35.     idEntity *                self;                // entity using the animated model
  36.     idAnimator *            animator;            // animator on entity
  37.     int                        modifiedAnim;        // animation modified by the IK
  38.     idVec3                    modelOffset;
  39. };
  40.  
  41.  
  42. /*
  43. ===============================================================================
  44.  
  45.   IK controller for a walking character with an arbitrary number of legs.    
  46.  
  47. ===============================================================================
  48. */
  49.  
  50. class idIK_Walk : public idIK {
  51. public:
  52.  
  53.                             idIK_Walk( void );
  54.     virtual                    ~idIK_Walk( void );
  55.  
  56.     void                    Save( idSaveGame *savefile ) const;
  57.     void                    Restore( idRestoreGame *savefile );
  58.  
  59.     virtual bool            Init( idEntity *self, const char *anim, const idVec3 &modelOffset );
  60.     virtual void            Evaluate( void );
  61.     virtual void            ClearJointMods( void );
  62.  
  63.     void                    EnableAll( void );
  64.     void                    DisableAll( void );
  65.     void                    EnableLeg( int num );
  66.     void                    DisableLeg( int num );
  67.  
  68. private:
  69.     static const int        MAX_LEGS        = 8;
  70.  
  71.     idClipModel *            footModel;
  72.  
  73.     int                        numLegs;
  74.     int                        enabledLegs;
  75.     jointHandle_t            footJoints[MAX_LEGS];
  76.     jointHandle_t            ankleJoints[MAX_LEGS];
  77.     jointHandle_t            kneeJoints[MAX_LEGS];
  78.     jointHandle_t            hipJoints[MAX_LEGS];
  79.     jointHandle_t            dirJoints[MAX_LEGS];
  80.     jointHandle_t            waistJoint;
  81.  
  82.     idVec3                    hipForward[MAX_LEGS];
  83.     idVec3                    kneeForward[MAX_LEGS];
  84.  
  85.     float                    upperLegLength[MAX_LEGS];
  86.     float                    lowerLegLength[MAX_LEGS];
  87.  
  88.     idMat3                    upperLegToHipJoint[MAX_LEGS];
  89.     idMat3                    lowerLegToKneeJoint[MAX_LEGS];
  90.  
  91.     float                    smoothing;
  92.     float                    waistSmoothing;
  93.     float                    footShift;
  94.     float                    waistShift;
  95.     float                    minWaistFloorDist;
  96.     float                    minWaistAnkleDist;
  97.     float                    footUpTrace;
  98.     float                    footDownTrace;
  99.     bool                    tiltWaist;
  100.     bool                    usePivot;
  101.  
  102.     // state
  103.     int                        pivotFoot;
  104.     float                    pivotYaw;
  105.     idVec3                    pivotPos;
  106.     bool                    oldHeightsValid;
  107.     float                    oldWaistHeight;
  108.     float                    oldAnkleHeights[MAX_LEGS];
  109.     idVec3                    waistOffset;
  110. };
  111.  
  112.  
  113. /*
  114. ===============================================================================
  115.  
  116.   IK controller for reaching a position with an arm or leg.
  117.  
  118. ===============================================================================
  119. */
  120.  
  121. class idIK_Reach : public idIK {
  122. public:
  123.  
  124.                             idIK_Reach( void );
  125.     virtual                    ~idIK_Reach( void );
  126.  
  127.     void                    Save( idSaveGame *savefile ) const;
  128.     void                    Restore( idRestoreGame *savefile );
  129.  
  130.     virtual bool            Init( idEntity *self, const char *anim, const idVec3 &modelOffset );
  131.     virtual void            Evaluate( void );
  132.     virtual void            ClearJointMods( void );
  133.  
  134. private:
  135.  
  136.     static const int        MAX_ARMS    = 2;
  137.  
  138.     int                        numArms;
  139.     int                        enabledArms;
  140.     jointHandle_t            handJoints[MAX_ARMS];
  141.     jointHandle_t            elbowJoints[MAX_ARMS];
  142.     jointHandle_t            shoulderJoints[MAX_ARMS];
  143.     jointHandle_t            dirJoints[MAX_ARMS];
  144.  
  145.     idVec3                    shoulderForward[MAX_ARMS];
  146.     idVec3                    elbowForward[MAX_ARMS];
  147.  
  148.     float                    upperArmLength[MAX_ARMS];
  149.     float                    lowerArmLength[MAX_ARMS];
  150.  
  151.     idMat3                    upperArmToShoulderJoint[MAX_ARMS];
  152.     idMat3                    lowerArmToElbowJoint[MAX_ARMS];
  153. };
  154.  
  155. #endif /* !__GAME_IK_H__ */
  156.