2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code 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
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
33 ===============================================================================
35 IK base class with a simple fast two bone solver.
37 ===============================================================================
40 #define IK_ANIM "ik_pose"
45 virtual ~idIK( void );
47 void Save( idSaveGame *savefile ) const;
48 void Restore( idRestoreGame *savefile );
50 bool IsInitialized( void ) const;
52 virtual bool Init( idEntity *self, const char *anim, const idVec3 &modelOffset );
53 virtual void Evaluate( void );
54 virtual void ClearJointMods( void );
56 bool SolveTwoBones( const idVec3 &startPos, const idVec3 &endPos, const idVec3 &dir, float len0, float len1, idVec3 &jointPos );
57 float GetBoneAxis( const idVec3 &startPos, const idVec3 &endPos, const idVec3 &dir, idMat3 &axis );
62 idEntity * self; // entity using the animated model
63 idAnimator * animator; // animator on entity
64 int modifiedAnim; // animation modified by the IK
70 ===============================================================================
72 IK controller for a walking character with an arbitrary number of legs.
74 ===============================================================================
77 class idIK_Walk : public idIK {
81 virtual ~idIK_Walk( void );
83 void Save( idSaveGame *savefile ) const;
84 void Restore( idRestoreGame *savefile );
86 virtual bool Init( idEntity *self, const char *anim, const idVec3 &modelOffset );
87 virtual void Evaluate( void );
88 virtual void ClearJointMods( void );
90 void EnableAll( void );
91 void DisableAll( void );
92 void EnableLeg( int num );
93 void DisableLeg( int num );
96 static const int MAX_LEGS = 8;
98 idClipModel * footModel;
102 jointHandle_t footJoints[MAX_LEGS];
103 jointHandle_t ankleJoints[MAX_LEGS];
104 jointHandle_t kneeJoints[MAX_LEGS];
105 jointHandle_t hipJoints[MAX_LEGS];
106 jointHandle_t dirJoints[MAX_LEGS];
107 jointHandle_t waistJoint;
109 idVec3 hipForward[MAX_LEGS];
110 idVec3 kneeForward[MAX_LEGS];
112 float upperLegLength[MAX_LEGS];
113 float lowerLegLength[MAX_LEGS];
115 idMat3 upperLegToHipJoint[MAX_LEGS];
116 idMat3 lowerLegToKneeJoint[MAX_LEGS];
119 float waistSmoothing;
122 float minWaistFloorDist;
123 float minWaistAnkleDist;
133 bool oldHeightsValid;
134 float oldWaistHeight;
135 float oldAnkleHeights[MAX_LEGS];
141 ===============================================================================
143 IK controller for reaching a position with an arm or leg.
145 ===============================================================================
148 class idIK_Reach : public idIK {
152 virtual ~idIK_Reach( void );
154 void Save( idSaveGame *savefile ) const;
155 void Restore( idRestoreGame *savefile );
157 virtual bool Init( idEntity *self, const char *anim, const idVec3 &modelOffset );
158 virtual void Evaluate( void );
159 virtual void ClearJointMods( void );
163 static const int MAX_ARMS = 2;
167 jointHandle_t handJoints[MAX_ARMS];
168 jointHandle_t elbowJoints[MAX_ARMS];
169 jointHandle_t shoulderJoints[MAX_ARMS];
170 jointHandle_t dirJoints[MAX_ARMS];
172 idVec3 shoulderForward[MAX_ARMS];
173 idVec3 elbowForward[MAX_ARMS];
175 float upperArmLength[MAX_ARMS];
176 float lowerArmLength[MAX_ARMS];
178 idMat3 upperArmToShoulderJoint[MAX_ARMS];
179 idMat3 lowerArmToElbowJoint[MAX_ARMS];
182 #endif /* !__GAME_IK_H__ */