doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IK.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
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.
13 
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.
18 
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/>.
21 
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.
23 
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.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __GAME_IK_H__
30 #define __GAME_IK_H__
31 
32 /*
33 ===============================================================================
34 
35  IK base class with a simple fast two bone solver.
36 
37 ===============================================================================
38 */
39 
40 #define IK_ANIM "ik_pose"
41 
42 class idIK {
43 public:
44  idIK( void );
45  virtual ~idIK( void );
46 
47  void Save( idSaveGame *savefile ) const;
48  void Restore( idRestoreGame *savefile );
49 
50  bool IsInitialized( void ) const;
51 
52  virtual bool Init( idEntity *self, const char *anim, const idVec3 &modelOffset );
53  virtual void Evaluate( void );
54  virtual void ClearJointMods( void );
55 
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 );
58 
59 protected:
62  idEntity * self; // entity using the animated model
63  idAnimator * animator; // animator on entity
64  int modifiedAnim; // animation modified by the IK
66 };
67 
68 
69 /*
70 ===============================================================================
71 
72  IK controller for a walking character with an arbitrary number of legs.
73 
74 ===============================================================================
75 */
76 
77 class idIK_Walk : public idIK {
78 public:
79 
80  idIK_Walk( void );
81  virtual ~idIK_Walk( void );
82 
83  void Save( idSaveGame *savefile ) const;
84  void Restore( idRestoreGame *savefile );
85 
86  virtual bool Init( idEntity *self, const char *anim, const idVec3 &modelOffset );
87  virtual void Evaluate( void );
88  virtual void ClearJointMods( void );
89 
90  void EnableAll( void );
91  void DisableAll( void );
92  void EnableLeg( int num );
93  void DisableLeg( int num );
94 
95 private:
96  static const int MAX_LEGS = 8;
97 
99 
100  int numLegs;
108 
111 
114 
117 
118  float smoothing;
120  float footShift;
121  float waistShift;
124  float footUpTrace;
126  bool tiltWaist;
127  bool usePivot;
128 
129  // state
131  float pivotYaw;
137 };
138 
139 
140 /*
141 ===============================================================================
142 
143  IK controller for reaching a position with an arm or leg.
144 
145 ===============================================================================
146 */
147 
148 class idIK_Reach : public idIK {
149 public:
150 
151  idIK_Reach( void );
152  virtual ~idIK_Reach( void );
153 
154  void Save( idSaveGame *savefile ) const;
155  void Restore( idRestoreGame *savefile );
156 
157  virtual bool Init( idEntity *self, const char *anim, const idVec3 &modelOffset );
158  virtual void Evaluate( void );
159  virtual void ClearJointMods( void );
160 
161 private:
162 
163  static const int MAX_ARMS = 2;
164 
165  int numArms;
171 
174 
177 
180 };
181 
182 #endif /* !__GAME_IK_H__ */
jointHandle_t
Definition: Model.h:156
float lowerArmLength[MAX_ARMS]
Definition: IK.h:176
virtual ~idIK(void)
Definition: IK.cpp:61
void Restore(idRestoreGame *savefile)
Definition: IK.cpp:360
virtual void ClearJointMods(void)
Definition: IK.cpp:1113
virtual bool Init(idEntity *self, const char *anim, const idVec3 &modelOffset)
Definition: IK.cpp:423
Definition: IK.h:77
jointHandle_t elbowJoints[MAX_ARMS]
Definition: IK.h:168
virtual void Evaluate(void)
Definition: IK.cpp:563
idVec3 waistOffset
Definition: IK.h:136
idClipModel * footModel
Definition: IK.h:98
void Save(idSaveGame *savefile) const
Definition: IK.cpp:882
void Restore(idRestoreGame *savefile)
Definition: IK.cpp:918
bool ik_activate
Definition: IK.h:61
idVec3 modelOffset
Definition: IK.h:65
int pivotFoot
Definition: IK.h:130
bool oldHeightsValid
Definition: IK.h:133
idMat3 upperLegToHipJoint[MAX_LEGS]
Definition: IK.h:115
idMat3 lowerArmToElbowJoint[MAX_ARMS]
Definition: IK.h:179
float footDownTrace
Definition: IK.h:125
float oldAnkleHeights[MAX_LEGS]
Definition: IK.h:135
jointHandle_t dirJoints[MAX_LEGS]
Definition: IK.h:106
idVec3 pivotPos
Definition: IK.h:132
idVec3 elbowForward[MAX_ARMS]
Definition: IK.h:173
virtual bool Init(idEntity *self, const char *anim, const idVec3 &modelOffset)
Definition: IK.cpp:122
bool SolveTwoBones(const idVec3 &startPos, const idVec3 &endPos, const idVec3 &dir, float len0, float len1, idVec3 &jointPos)
Definition: IK.cpp:182
int numLegs
Definition: IK.h:100
int enabledLegs
Definition: IK.h:101
float GetBoneAxis(const idVec3 &startPos, const idVec3 &endPos, const idVec3 &dir, idMat3 &axis)
Definition: IK.cpp:214
Definition: Vector.h:316
float oldWaistHeight
Definition: IK.h:134
bool usePivot
Definition: IK.h:127
float footUpTrace
Definition: IK.h:124
float waistSmoothing
Definition: IK.h:119
bool initialized
Definition: IK.h:60
jointHandle_t shoulderJoints[MAX_ARMS]
Definition: IK.h:169
Definition: IK.h:42
GLuint GLuint num
Definition: glext.h:5390
virtual void ClearJointMods(void)
Definition: IK.cpp:779
idMat3 lowerLegToKneeJoint[MAX_LEGS]
Definition: IK.h:116
jointHandle_t waistJoint
Definition: IK.h:107
jointHandle_t ankleJoints[MAX_LEGS]
Definition: IK.h:103
void EnableLeg(int num)
Definition: IK.cpp:822
float minWaistAnkleDist
Definition: IK.h:123
static const int MAX_ARMS
Definition: IK.h:163
float upperLegLength[MAX_LEGS]
Definition: IK.h:112
Definition: IK.h:148
float minWaistFloorDist
Definition: IK.h:122
virtual void Evaluate(void)
Definition: IK.cpp:1051
virtual void ClearJointMods(void)
Definition: IK.cpp:173
float lowerLegLength[MAX_LEGS]
Definition: IK.h:113
jointHandle_t hipJoints[MAX_LEGS]
Definition: IK.h:105
jointHandle_t kneeJoints[MAX_LEGS]
Definition: IK.h:104
int numArms
Definition: IK.h:165
void Save(idSaveGame *savefile) const
Definition: IK.cpp:297
void DisableLeg(int num)
Definition: IK.cpp:831
idIK_Reach(void)
Definition: IK.cpp:849
virtual bool Init(idEntity *self, const char *anim, const idVec3 &modelOffset)
Definition: IK.cpp:954
bool IsInitialized(void) const
Definition: IK.cpp:113
float waistShift
Definition: IK.h:121
float upperArmLength[MAX_ARMS]
Definition: IK.h:175
idIK_Walk(void)
Definition: IK.cpp:238
void EnableAll(void)
Definition: IK.cpp:802
idVec3 kneeForward[MAX_LEGS]
Definition: IK.h:110
Definition: Matrix.h:333
void Save(idSaveGame *savefile) const
Definition: IK.cpp:69
bool tiltWaist
Definition: IK.h:126
void DisableAll(void)
Definition: IK.cpp:812
float footShift
Definition: IK.h:120
idVec3 shoulderForward[MAX_ARMS]
Definition: IK.h:172
idMat3 upperArmToShoulderJoint[MAX_ARMS]
Definition: IK.h:178
jointHandle_t handJoints[MAX_ARMS]
Definition: IK.h:167
float pivotYaw
Definition: IK.h:131
int modifiedAnim
Definition: IK.h:64
jointHandle_t footJoints[MAX_LEGS]
Definition: IK.h:102
idAnimator * animator
Definition: IK.h:63
idIK(void)
Definition: IK.cpp:47
idVec3 hipForward[MAX_LEGS]
Definition: IK.h:109
void Restore(idRestoreGame *savefile)
Definition: IK.cpp:82
jointHandle_t dirJoints[MAX_ARMS]
Definition: IK.h:170
virtual ~idIK_Reach(void)
Definition: IK.cpp:874
virtual void Evaluate(void)
Definition: IK.cpp:165
virtual ~idIK_Walk(void)
Definition: IK.cpp:286
static const int MAX_LEGS
Definition: IK.h:96
float smoothing
Definition: IK.h:118
int enabledArms
Definition: IK.h:166