00001 #ifndef _ANIMATION_H
00002 #define _ANIMATION_H
00003
00004 #include "Token.h"
00005 #include "math/vector3.h"
00006
00007 enum AnimEndType {
00008 ANIM_END_LOOP,
00009 ANIM_END_HOLD,
00010 ANIM_END_STOP,
00011 };
00012
00013 class AnimPose {
00014 public:
00015 AnimPose() {}
00016 void Init(int numBones) { this->numBones = numBones;
00017 pose = new Vector3[numBones]; }
00018 ~AnimPose() { }
00019
00020 Vector3 *GetPose() { return pose; }
00021 void SetTime(float time) { this->time = time; }
00022 float GetTime() { return time; }
00023 int GetNumBones() { return numBones; }
00024 void SetRootPos(float x, float y, float z) { rootPos.Set(x,y,z); }
00025 Vector3 &GetRootPos() { return rootPos; }
00026 void SetRootTranslation(bool rt) { rootTranslation = rt; }
00027 bool GetRootTranslation() { return rootTranslation; }
00028
00029 private:
00030 float time;
00031 Vector3 *pose, rootPos;
00032 int numBones;
00033 bool rootTranslation;
00034 };
00035
00036
00037 class Animation {
00038 public:
00039 Animation() {}
00040 ~Animation() { }
00041
00042 void Load(Tokenizer &tokens);
00043 AnimPose *GetPose(float time);
00044
00045 public:
00046 AnimPose pose;
00047 AnimPose *keyFrames;
00048 float keyRate;
00049 int numBones;
00050 int numKeys;
00051 enum AnimEndType endType;
00052 bool done;
00053 };
00054
00055 class AnimPlayer {
00056 public:
00057 AnimPlayer() : playing(false), t(0.0f) {}
00058 ~AnimPlayer() {}
00059
00060 void SetAnimation(Animation *a) { anim = a; }
00061
00062 void Play() { playing = true; }
00063 void Stop() { t = 0.0f; playing = false; }
00064 void Pause() { playing = false; }
00065
00066 void Update(float dt) {
00067 if(playing) { t += dt; currPose = anim->GetPose(t); }
00068 }
00069 AnimPose *GetPose() { return currPose; }
00070
00071 private:
00072 Animation *anim;
00073 AnimPose *currPose;
00074 bool playing;
00075 float t;
00076 };
00077 #endif //_ANIMATION_H