TargetAnimation.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2016, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file Defines a helper class for the ASE and 3DS loaders to
  34. help them compute camera and spot light animation channels */
  35. #ifndef AI_TARGET_ANIMATION_H_INC
  36. #define AI_TARGET_ANIMATION_H_INC
  37. #include <assimp/anim.h>
  38. #include <vector>
  39. namespace Assimp {
  40. // ---------------------------------------------------------------------------
  41. /** Helper class to iterate through all keys in an animation channel.
  42. *
  43. * Missing tracks are interpolated. This is a helper class for
  44. * TargetAnimationHelper, but it can be freely used for other purposes.
  45. */
  46. class KeyIterator
  47. {
  48. public:
  49. // ------------------------------------------------------------------
  50. /** Constructs a new key iterator
  51. *
  52. * @param _objPos Object position track. May be NULL.
  53. * @param _targetObjPos Target object position track. May be NULL.
  54. * @param defaultObjectPos Default object position to be used if
  55. * no animated track is available. May be NULL.
  56. * @param defaultTargetPos Default target position to be used if
  57. * no animated track is available. May be NULL.
  58. */
  59. KeyIterator(const std::vector<aiVectorKey>* _objPos,
  60. const std::vector<aiVectorKey>* _targetObjPos,
  61. const aiVector3D* defaultObjectPos = NULL,
  62. const aiVector3D* defaultTargetPos = NULL);
  63. // ------------------------------------------------------------------
  64. /** Returns true if all keys have been processed
  65. */
  66. bool Finished() const
  67. {return reachedEnd;}
  68. // ------------------------------------------------------------------
  69. /** Increment the iterator
  70. */
  71. void operator++();
  72. inline void operator++(int)
  73. {return ++(*this);}
  74. // ------------------------------------------------------------------
  75. /** Getters to retrieve the current state of the iterator
  76. */
  77. inline const aiVector3D& GetCurPosition() const
  78. {return curPosition;}
  79. inline const aiVector3D& GetCurTargetPosition() const
  80. {return curTargetPosition;}
  81. inline double GetCurTime() const
  82. {return curTime;}
  83. private:
  84. //! Did we reach the end?
  85. bool reachedEnd;
  86. //! Represents the current position of the iterator
  87. aiVector3D curPosition, curTargetPosition;
  88. double curTime;
  89. //! Input tracks and the next key to process
  90. const std::vector<aiVectorKey>* objPos,*targetObjPos;
  91. unsigned int nextObjPos, nextTargetObjPos;
  92. std::vector<aiVectorKey> defaultObjPos,defaultTargetObjPos;
  93. };
  94. // ---------------------------------------------------------------------------
  95. /** Helper class for the 3DS and ASE loaders to compute camera and spot light
  96. * animations.
  97. *
  98. * 3DS and ASE store the differently to Assimp - there is an animation
  99. * channel for the camera/spot light itself and a separate position
  100. * animation channels specifying the position of the camera/spot light
  101. * look-at target */
  102. class TargetAnimationHelper
  103. {
  104. public:
  105. TargetAnimationHelper()
  106. : targetPositions (NULL)
  107. , objectPositions (NULL)
  108. {}
  109. // ------------------------------------------------------------------
  110. /** Sets the target animation channel
  111. *
  112. * This channel specifies the position of the camera/spot light
  113. * target at a specific position.
  114. *
  115. * @param targetPositions Translation channel*/
  116. void SetTargetAnimationChannel (const
  117. std::vector<aiVectorKey>* targetPositions);
  118. // ------------------------------------------------------------------
  119. /** Sets the main animation channel
  120. *
  121. * @param objectPositions Translation channel */
  122. void SetMainAnimationChannel ( const
  123. std::vector<aiVectorKey>* objectPositions);
  124. // ------------------------------------------------------------------
  125. /** Sets the main animation channel to a fixed value
  126. *
  127. * @param fixed Fixed value for the main animation channel*/
  128. void SetFixedMainAnimationChannel(const aiVector3D& fixed);
  129. // ------------------------------------------------------------------
  130. /** Computes final animation channels
  131. * @param distanceTrack Receive camera translation keys ... != NULL. */
  132. void Process( std::vector<aiVectorKey>* distanceTrack );
  133. private:
  134. const std::vector<aiVectorKey>* targetPositions,*objectPositions;
  135. aiVector3D fixedMain;
  136. };
  137. } // ! end namespace Assimp
  138. #endif // include guard