AnimationState.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright © 2011-2020 Frictional Games
  3. *
  4. * This file is part of Amnesia: A Machine For Pigs.
  5. *
  6. * Amnesia: A Machine For Pigs is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. * Amnesia: A Machine For Pigs is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Amnesia: A Machine For Pigs. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #ifndef HPL_ANIMATION_STATE_H
  19. #define HPL_ANIMATION_STATE_H
  20. #include "math/MathTypes.h"
  21. #include "system/SystemTypes.h"
  22. #include "graphics/GraphicsTypes.h"
  23. #include "engine/SaveGame.h"
  24. namespace hpl {
  25. class cAnimation;
  26. class cAnimationManager;
  27. class cMeshEntity;
  28. //-----------------------------------------------------------------------
  29. class cSkeletonAABB
  30. {
  31. public:
  32. cSkeletonAABB() { cSkeletonAABB(cVector3f(100000), cVector3f(-100000)); }
  33. cSkeletonAABB(cVector3f avMin, cVector3f avMax) { mvMin = avMin; mvMax = avMax; }
  34. inline void Expand(cSkeletonAABB aBox) { Expand(aBox.mvMin, aBox.mvMax); }
  35. inline void Expand(cVector3f avMin, cVector3f avMax)
  36. {
  37. if(mvMax.x < avMax.x) mvMax.x = avMax.x;
  38. if(mvMax.y < avMax.y) mvMax.y = avMax.y;
  39. if(mvMax.z < avMax.z) mvMax.z = avMax.z;
  40. if(mvMin.x > avMin.x) mvMin.x = avMin.x;
  41. if(mvMin.y > avMin.y) mvMin.y = avMin.y;
  42. if(mvMin.z > avMin.z) mvMin.z = avMin.z;
  43. }
  44. void SetTime(float afTime) { mfTime = afTime; }
  45. cVector3f mvMin;
  46. cVector3f mvMax;
  47. float mfTime;
  48. };
  49. typedef std::vector<cSkeletonAABB> tSkeletonBoundsVec;
  50. typedef tSkeletonBoundsVec::iterator tSkeletonBoundsVecIt;
  51. //---------------------------------------------
  52. class cAnimationEvent
  53. {
  54. public:
  55. float mfTime;
  56. eAnimationEventType mType;
  57. tString msValue;
  58. };
  59. //---------------------------------------------
  60. class cAnimationTransition
  61. {
  62. public:
  63. cAnimationTransition(){}
  64. cAnimationTransition(int alAnimId, int alPreviousAnimId, float afMinTime, float afMaxTime) :
  65. mlPreviousAnimId(alPreviousAnimId), mlAnimId(alAnimId), mfMinTime(afMinTime), mfMaxTime(afMaxTime){}
  66. int mlPreviousAnimId; //-1= default! The animation that is played before, for this to be used.
  67. int mlAnimId; //The transitional animation.
  68. float mfMinTime;
  69. float mfMaxTime;
  70. };
  71. //---------------------------------------------
  72. class cAnimationState
  73. {
  74. public:
  75. cAnimationState(cAnimation* apAnimation,const tString &asName,
  76. cAnimationManager *apAnimationManager);
  77. ~cAnimationState();
  78. const tString& GetName(){ return msName;}
  79. void Update(float afTimeStep);
  80. bool DataIsInMeshFile(){return mpAnimationManager==NULL;}
  81. bool IsFading();
  82. bool IsFadingOut(){ return mfFadeStep<0;}
  83. /**
  84. * If the animation has reached the end.
  85. */
  86. bool IsOver();
  87. void FadeIn(float afTime);
  88. void FadeOut(float afTime);
  89. void FadeInSpeed(float afTime);
  90. void FadeOutSpeed(float afTime);
  91. void SetLength(float afLength);
  92. float GetLength();
  93. void SetWeight(float afWeight);
  94. float GetWeight();
  95. void SetSpeed(float afSpeed);
  96. float GetSpeed();
  97. void SetBaseSpeed(float afSpeed);
  98. float GetBaseSpeed();
  99. void SetTimePosition(float afPosition);
  100. float GetTimePosition();
  101. float GetPreviousTimePosition();
  102. /**
  103. * Set the relative postion. 0 = start, 1 = end
  104. * \param afPosition
  105. */
  106. void SetRelativeTimePosition(float afPosition);
  107. /**
  108. * Get the relative postion. 0 = start, 1 = end
  109. */
  110. float GetRelativeTimePosition();
  111. bool IsActive();
  112. void SetActive(bool abActive);
  113. bool IsLooping();
  114. void SetLoop(bool abLoop);
  115. bool IsPaused();
  116. void SetPaused(bool abPaused);
  117. void SetSpecialEventTime(float afT){ mfSpecialEventTime = afT;}
  118. float GetSpecialEventTime(){ return mfSpecialEventTime;}
  119. bool IsAfterSpecialEvent();
  120. bool IsBeforeSpecialEvent();
  121. void CreateSkeletonBoundsFromMesh(cMeshEntity * apMesh, tBoneStateVec * apvBoneStates);
  122. bool TryGetBoundingVolumeAtTime(float afTime, cVector3f & avMin, cVector3f & avMax);
  123. void AddTimePosition(float afAdd);
  124. cAnimation* GetAnimation();
  125. cAnimationEvent *CreateEvent();
  126. cAnimationEvent *GetEvent(int alIdx);
  127. int GetEventNum();
  128. /**
  129. * If either time is -1 then no limits are checked.
  130. */
  131. void AddTransition(int alAnimId, int alPreviousAnimId, float afMinTime, float afMaxTime);
  132. cAnimationTransition* GetTransitionFromPrevAnim(int alPreviousAnimId, float afPreviousTimePos);
  133. cAnimationTransition* GetTransition(int alIdx);
  134. int GetTransitionNum();
  135. float GetFadeStep(){ return mfFadeStep;}
  136. void SetFadeStep(float afX){ mfFadeStep = afX;}
  137. bool CanBlend() { return mbCanBlend; }
  138. void SetCanBlend( bool abCanBlend ) { mbCanBlend = abCanBlend; }
  139. private:
  140. tString msName;
  141. cAnimationManager *mpAnimationManager;
  142. cAnimation* mpAnimation;
  143. std::vector<cAnimationEvent*> mvEvents;
  144. std::vector<cAnimationTransition> mvTransitions;
  145. tSkeletonBoundsVec mvSkeletonBounds;
  146. //Properties of the animation
  147. float mfLength;
  148. float mfWeight;
  149. float mfSpeed;
  150. float mfTimePos;
  151. float mfPrevTimePos;
  152. float mfBaseSpeed;
  153. float mfSpecialEventTime;
  154. bool mbActive;
  155. bool mbLoop;
  156. bool mbPaused;
  157. bool mbCanBlend;
  158. //properties for update
  159. float mfFadeStep;
  160. float mfFadeSpeed;
  161. };
  162. };
  163. #endif // HPL_ANIMATION_STATE_H