00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __MD3PLAYER_H__
00022 #define __MD3PLAYER_H__
00023
00024 #include "Md3Model.h"
00025
00026
00027
00028 enum Md3PlayerLOD
00029 {
00030 kLodLow,
00031 kLodMedium,
00032 kLodHigh,
00033
00034 kLodDefault = kLodHigh,
00035 };
00036
00037
00038
00039 enum Md3PlayerAnimType
00040 {
00041
00042
00043 kBothDeath1,
00044 kBothDead1,
00045 kBothDeath2,
00046 kBothDead2,
00047 kBothDeath3,
00048 kBothDead3,
00049
00050
00051 kTorsoGesture,
00052
00053 kTorsoAttack,
00054 kTorsoAttack2,
00055
00056 kTorsoDrop,
00057 kTorsoRaise,
00058
00059 kTorsoStand,
00060 kTorsoStand2,
00061
00062
00063 kLegsWalkCr,
00064 kLegsWalk,
00065 kLegsRun,
00066 kLegsBack,
00067 kLegsSwim,
00068
00069 kLegsJump,
00070 kLegsLand,
00071
00072 kLegsJumpB,
00073 kLegsLandB,
00074
00075 kLegsIdle,
00076 kLegsIdleCr,
00077
00078 kLegsTurn,
00079
00080 kMaxAnimations,
00081 };
00082
00083
00084
00085 struct Md3PlayerAnim_t
00086 {
00087 int index;
00088 int first;
00089 int num;
00090 int looping;
00091 int fps;
00092 };
00093
00094
00095
00096 enum eAnimationArea {
00097 eAnimationArea_Upper = 1,
00098 eAnimationArea_Lower = 2,
00099
00100 eAnimationArea_Invalid = 0
00101 };
00102
00103
00104 struct Md3AnimState_t {
00105 Md3AnimState_t(void) throw() { this->clear(); }
00106 void clear(void) throw() {
00107 animationIndex = -1;
00108 time = -1;
00109 }
00110
00111
00112 int animationIndex;
00113 float time;
00114 };
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 class Md3PlayerSkin
00127 {
00128 public:
00129
00130 Md3PlayerSkin (const string &path, const string &name);
00131 ~Md3PlayerSkin ();
00132
00133 public:
00134
00135 void setLowerTextures (Md3Model *model) {
00136 setModelTextures (model, _lowerTextures);
00137 }
00138
00139 void setUpperTextures (Md3Model *model) {
00140 setModelTextures (model, _upperTextures);
00141 }
00142
00143 void setHeadTextures (Md3Model *model) {
00144 setModelTextures (model, _headTextures);
00145 }
00146
00147
00148 const string &path () const { return _path; }
00149 const string &name () const { return _name; }
00150
00151 private:
00152
00153 typedef map<string, const Texture2D *> TexMap;
00154
00155 private:
00156
00157 void loadSkinFile (const string &filename, TexMap &tmap);
00158 void setModelTextures (Md3Model *model, const TexMap &tmap) const;
00159
00160 private:
00161
00162 TexMap _lowerTextures;
00163 TexMap _upperTextures;
00164 TexMap _headTextures;
00165
00166 string _path;
00167 string _name;
00168 };
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 class Md3Weapon
00183 {
00184 public:
00185
00186 Md3Weapon (const string &path, Md3PlayerLOD lod = kLodDefault);
00187 ~Md3Weapon ();
00188
00189 private:
00190
00191 typedef smart_ptr<Md3Model> Md3ModelPtr;
00192
00193 public:
00194
00195 void draw () const;
00196 void scaleModels () const;
00197 void linkToModel (Md3Model *model);
00198
00199 void setScale (float scale) { _scale = scale; }
00200
00201
00202 float scale () const { return _scale; }
00203 const string &path () const { return _path; }
00204 const string &name () const { return _name; }
00205 Md3PlayerLOD lod () const { return _lod; }
00206
00207 private:
00208
00209 Md3ModelPtr _weapon;
00210 Md3ModelPtr _barrel;
00211
00212 string _path;
00213 string _name;
00214 float _scale;
00215 Md3PlayerLOD _lod;
00216 };
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 class Md3Player
00230 {
00231 public:
00232
00233 Md3Player (const string &path, Md3PlayerLOD lod = kLodDefault);
00234 ~Md3Player ();
00235
00236 private:
00237
00238
00239
00240 struct Md3AnimState
00241 {
00242 public:
00243
00244 Md3AnimState ();
00245
00246
00247 void setup (Md3PlayerAnim_t *a);
00248 void update (float dt);
00249
00250
00251 Md3PlayerAnim_t *anim;
00252 float curr_time;
00253 float old_time;
00254 int curr_frame;
00255 int next_frame;
00256 float interp;
00257 };
00258
00259 typedef smart_ptr<Md3Model> Md3ModelPtr;
00260 typedef smart_ptr<Md3PlayerSkin> Md3PlayerSkinPtr;
00261
00262 public:
00263 typedef map<string, Md3PlayerSkinPtr> SkinMap;
00264
00265 public:
00266
00267 void draw () const;
00268 void renderFrame (int upperFrame, int lowerFrame) const;
00269 void animate (float dt);
00270
00271 void setScale (float scale) { _scale = scale; }
00272 void setAnimation (Md3PlayerAnimType type);
00273 void setSkin (const string &name);
00274
00275 void linkWeapon (Md3Weapon *weapon);
00276 void unlinkWeapon ();
00277
00278
00279 float scale () const { return _scale; }
00280 const string &path () const { return _path; }
00281 const string &name () const { return _name; }
00282 Md3PlayerLOD lod () const { return _lod; }
00283 const SkinMap &skins () const { return _skins; }
00284 const string &skinName () const { return _currentSkinName; }
00285 void getAnimationState(eAnimationArea area,
00286 Md3AnimState_t& state);
00287 void setAnimationState(eAnimationArea area,
00288 const Md3AnimState_t& state);
00289
00290 private:
00291
00292 void loadModels (const string &path);
00293
00294 void loadAnimations (const string &path);
00295
00296 void loadSkins (const string &path);
00297
00298 static void setState(const Md3AnimState& anim,
00299 Md3AnimState_t& state);
00300
00301 static void updateAnim(Md3AnimState& anim,
00302 const Md3AnimState_t& state,
00303 Md3PlayerAnim_t * a);
00304
00305 private:
00306
00307 Md3ModelPtr _lower;
00308 Md3ModelPtr _upper;
00309 Md3ModelPtr _head;
00310
00311 Md3AnimState _lowerAnim;
00312 Md3AnimState _upperAnim;
00313
00314
00315 Md3PlayerAnim_t _anims[kMaxAnimations];
00316
00317
00318 SkinMap _skins;
00319 Md3PlayerSkin *_currentSkin;
00320 string _currentSkinName;
00321
00322 Md3Weapon *_weapon;
00323
00324 string _path;
00325 string _name;
00326 float _scale;
00327 Md3PlayerLOD _lod;
00328 };
00329
00330 #endif // __MD3PLAYER_H__