VHumanoidAnimationStates.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) 2014 - Violent Tulip
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #include "VHumanoidAnimationStates.h"
  24. #include "VHumanoidActor.h"
  25. #include "../VActorAnimationController.h"
  26. #include "../VActorPhysicsController.h"
  27. //-----------------------------------------------------------------------------
  28. //
  29. // Implement Animation States.
  30. //
  31. //-----------------------------------------------------------------------------
  32. ImplementActorAnimationState( HumanoidIdle, VHumanoidActorData::k_IdleAnimation );
  33. ImplementActorAnimationState( HumanoidWalkForward, VHumanoidActorData::k_WalkForwardAnimation );
  34. ImplementActorAnimationState( HumanoidWalkBackward, VHumanoidActorData::k_WalkBackwardAnimation );
  35. ImplementActorAnimationState( HumanoidRunForward, VHumanoidActorData::k_RunForwardAnimation );
  36. ImplementActorAnimationState( HumanoidRunBackward, VHumanoidActorData::k_RunBackwardAnimation );
  37. ImplementActorAnimationState( HumanoidSwimIdle, VHumanoidActorData::k_SwimIdleAnimation );
  38. ImplementActorAnimationState( HumanoidSwimForward, VHumanoidActorData::k_SwimForwardAnimation );
  39. ImplementActorAnimationState( HumanoidSwimBackward, VHumanoidActorData::k_SwimBackwardAnimation );
  40. //-----------------------------------------------------------------------------
  41. //
  42. // Execute Animation States.
  43. //
  44. //-----------------------------------------------------------------------------
  45. //-----------------------------------------------------------------------------
  46. //
  47. // OnGround Animation States
  48. //
  49. //-----------------------------------------------------------------------------
  50. ExecuteActorAnimationState( HumanoidIdle )
  51. {
  52. // Always Enter.
  53. return true;
  54. }
  55. ExecuteActorAnimationState( HumanoidWalkForward )
  56. {
  57. // Fetch Controller.
  58. VActorPhysicsController *physicsController = pObject->getPhysicsController();
  59. // On the Ground?
  60. if ( physicsController->getPhysicsState() != VHumanoidActorData::k_OnGroundPhysics )
  61. {
  62. // Can't Run Forward.
  63. return false;
  64. }
  65. // Fetch Velocity.
  66. const VectorF &velocity = physicsController->getVelocity();
  67. // Determine Move Speed.
  68. const F32 moveSpeed = mSqrt( velocity.x * velocity.x + velocity.y * velocity.y );
  69. // Moving Forward & Slow Enough?
  70. return ( ( physicsController->getMoveState() & k_ForwardMove ) &&
  71. ( moveSpeed < pObject->getDataBlock()->getRunSpeed() ) );
  72. }
  73. ExecuteActorAnimationState( HumanoidWalkBackward )
  74. {
  75. // Fetch Controller.
  76. VActorPhysicsController *physicsController = pObject->getPhysicsController();
  77. // On the Ground?
  78. if ( physicsController->getPhysicsState() != VHumanoidActorData::k_OnGroundPhysics )
  79. {
  80. // Can't Run Backward.
  81. return false;
  82. }
  83. // Fetch Velocity.
  84. const VectorF &velocity = physicsController->getVelocity();
  85. // Determine Move Speed.
  86. const F32 moveSpeed = mSqrt( velocity.x * velocity.x + velocity.y * velocity.y );
  87. // Moving Backward?
  88. return ( ( physicsController->getMoveState() & k_BackwardMove ) &&
  89. ( moveSpeed < pObject->getDataBlock()->getRunSpeed() ) );
  90. }
  91. ExecuteActorAnimationState( HumanoidRunForward )
  92. {
  93. // Fetch Controller.
  94. VActorPhysicsController *physicsController = pObject->getPhysicsController();
  95. // On the Ground?
  96. if ( physicsController->getPhysicsState() != VHumanoidActorData::k_OnGroundPhysics )
  97. {
  98. // Can't Run Forward.
  99. return false;
  100. }
  101. // Fetch Velocity.
  102. const VectorF &velocity = physicsController->getVelocity();
  103. // Determine Move Speed.
  104. const F32 moveSpeed = mSqrt( velocity.x * velocity.x + velocity.y * velocity.y );
  105. // Moving Forward?
  106. return ( ( physicsController->getMoveState() & k_ForwardMove ) &&
  107. ( moveSpeed >= pObject->getDataBlock()->getRunSpeed() ) );
  108. }
  109. ExecuteActorAnimationState( HumanoidRunBackward )
  110. {
  111. // Fetch Controller.
  112. VActorPhysicsController *physicsController = pObject->getPhysicsController();
  113. // On the Ground?
  114. if ( physicsController->getPhysicsState() != VHumanoidActorData::k_OnGroundPhysics )
  115. {
  116. // Can't Run Backward.
  117. return false;
  118. }
  119. // Fetch Velocity.
  120. const VectorF &velocity = physicsController->getVelocity();
  121. // Determine Move Speed.
  122. const F32 moveSpeed = mSqrt( velocity.x * velocity.x + velocity.y * velocity.y );
  123. // Moving Backward?
  124. return ( ( physicsController->getMoveState() & k_BackwardMove ) &&
  125. ( moveSpeed >= pObject->getDataBlock()->getRunSpeed() ) );
  126. }
  127. //-----------------------------------------------------------------------------
  128. //
  129. // InWater Animation States
  130. //
  131. //-----------------------------------------------------------------------------
  132. ExecuteActorAnimationState( HumanoidSwimIdle )
  133. {
  134. // Fetch Controller.
  135. VActorPhysicsController *physicsController = pObject->getPhysicsController();
  136. // In the Water?
  137. if ( physicsController->getPhysicsState() != VHumanoidActorData::k_InWaterPhysics )
  138. {
  139. // Can't Swim.
  140. return false;
  141. }
  142. // Idle?
  143. return ( physicsController->getMoveState() & k_NullMove );
  144. }
  145. ExecuteActorAnimationState( HumanoidSwimForward )
  146. {
  147. // Fetch Controller.
  148. VActorPhysicsController *physicsController = pObject->getPhysicsController();
  149. // In the Water?
  150. if ( physicsController->getPhysicsState() != VHumanoidActorData::k_InWaterPhysics )
  151. {
  152. // Can't Swim.
  153. return false;
  154. }
  155. // Moving Around?
  156. return ( physicsController->getMoveState() & ( k_ForwardMove |
  157. k_UpMove |
  158. k_DownMove ) );
  159. }
  160. ExecuteActorAnimationState( HumanoidSwimBackward )
  161. {
  162. // Fetch Controller.
  163. VActorPhysicsController *physicsController = pObject->getPhysicsController();
  164. // In the Water?
  165. if ( physicsController->getPhysicsState() != VHumanoidActorData::k_InWaterPhysics )
  166. {
  167. // Can't Swim.
  168. return false;
  169. }
  170. // Moving Backward?
  171. return ( physicsController->getMoveState() & k_BackwardMove );
  172. }