VAnimation.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 "Verve/Torque/TAnimation.h"
  24. #include "T3D/shapeBase.h"
  25. //-----------------------------------------------------------------------------
  26. //
  27. // Animation Methods.
  28. //
  29. //-----------------------------------------------------------------------------
  30. bool VTorque::isAnimationLooping( SceneObjectType *pObject, const char *pData )
  31. {
  32. ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
  33. if ( !shape || !shape->getShape() )
  34. {
  35. // Sanity!
  36. return false;
  37. }
  38. // Find Sequence.
  39. const S32 sequenceIndex = shape->getShape()->findSequence( pData );
  40. if ( sequenceIndex == -1 )
  41. {
  42. // Invalid Sequence.
  43. return false;
  44. }
  45. // Return Cyclic.
  46. return shape->getShape()->sequences[sequenceIndex].isCyclic();
  47. }
  48. String VTorque::getAnimation( SceneObjectType *pObject, const U32 &pThreadIndex )
  49. {
  50. ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
  51. if ( !shape )
  52. {
  53. // Sanity!
  54. return "";
  55. }
  56. // Return Name.
  57. return shape->getThreadSequenceName( pThreadIndex );
  58. }
  59. F32 VTorque::getAnimationDuration( SceneObjectType *pObject, const char *pData )
  60. {
  61. ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
  62. if ( !shape || !shape->getShape() )
  63. {
  64. // Sanity!
  65. return 0.f;
  66. }
  67. // Find Sequence.
  68. const S32 sequenceIndex = shape->getShape()->findSequence( pData );
  69. if ( sequenceIndex == -1 )
  70. {
  71. // Invalid Sequence.
  72. return 0.f;
  73. }
  74. // Return Duration.
  75. return shape->getShape()->sequences[sequenceIndex].duration;
  76. }
  77. void VTorque::setAnimationPosition( SceneObjectType *pObject, const U32 &pThreadIndex, const F32 &pPosition )
  78. {
  79. ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
  80. if ( !shape )
  81. {
  82. // Sanity!
  83. return;
  84. }
  85. // Set Position.
  86. shape->setThreadPosition( 0, pPosition );
  87. }
  88. void VTorque::setAnimationTimeScale( SceneObjectType *pObject, const U32 &pThreadIndex, const F32 &pTimeScale )
  89. {
  90. ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
  91. if ( !shape )
  92. {
  93. // Sanity!
  94. return;
  95. }
  96. // Set TimeScale.
  97. shape->setThreadTimeScale( pThreadIndex, pTimeScale );
  98. }
  99. void VTorque::playAnimation( SceneObjectType *pObject, const U32 &pThreadIndex, const char *pData )
  100. {
  101. ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
  102. if ( !shape || !shape->getShape() )
  103. {
  104. // Sanity!
  105. return;
  106. }
  107. // Find Sequence.
  108. const S32 sequenceIndex = shape->getShape()->findSequence( pData );
  109. if ( sequenceIndex == -1 )
  110. {
  111. // Invalid Sequence.
  112. return;
  113. }
  114. // Play Sequence.
  115. shape->setThreadSequence( pThreadIndex, sequenceIndex );
  116. }
  117. void VTorque::playAnimation( SceneObjectType *pObject, const U32 &pThreadIndex )
  118. {
  119. ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
  120. if ( !shape )
  121. {
  122. // Sanity!
  123. return;
  124. }
  125. // Play Sequence.
  126. shape->playThread( pThreadIndex );
  127. }
  128. void VTorque::stopAnimation( SceneObjectType *pObject, const U32 &pThreadIndex )
  129. {
  130. ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
  131. if ( !shape )
  132. {
  133. // Sanity!
  134. return;
  135. }
  136. // Pause Thread.
  137. shape->stopThread( pThreadIndex );
  138. }
  139. void VTorque::pauseAnimation( SceneObjectType *pObject, const U32 &pThreadIndex )
  140. {
  141. ShapeBase *shape = dynamic_cast<ShapeBase*>( pObject );
  142. if ( !shape )
  143. {
  144. // Sanity!
  145. return;
  146. }
  147. // Pause Thread.
  148. shape->pauseThread( pThreadIndex );
  149. }