1 /** Calculates a pose for a given time of an animation */
2 /*
3 ---------------------------------------------------------------------------
4 Open Asset Import Library (assimp)
5 ---------------------------------------------------------------------------
6 
7 Copyright (c) 2006-2012, assimp team
8 
9 All rights reserved.
10 
11 Redistribution and use of this software in source and binary forms,
12 with or without modification, are permitted provided that the following
13 conditions are met:
14 
15 * Redistributions of source code must retain the above
16   copyright notice, this list of conditions and the
17   following disclaimer.
18 
19 * Redistributions in binary form must reproduce the above
20   copyright notice, this list of conditions and the
21   following disclaimer in the documentation and/or other
22   materials provided with the distribution.
23 
24 * Neither the name of the assimp team, nor the names of its
25   contributors may be used to endorse or promote products
26   derived from this software without specific prior
27   written permission of the assimp team.
28 
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 ---------------------------------------------------------------------------
41 */
42 
43 #ifndef AV_ANIMEVALUATOR_H_INCLUDED
44 #define AV_ANIMEVALUATOR_H_INCLUDED
45 
46 #include <tuple>
47 #include <vector>
48 
49 namespace AssimpView
50 {
51 
52 /** Calculates transformations for a given timestamp from a set of animation tracks. Not directly useful,
53  * better use the AnimPlayer class.
54  */
55 class AnimEvaluator
56 {
57 public:
58     /** Constructor on a given animation. The animation is fixed throughout the lifetime of
59      * the object.
60      * @param pAnim The animation to calculate poses for. Ownership of the animation object stays
61      *   at the caller, the evaluator just keeps a reference to it as long as it persists.
62      */
63     AnimEvaluator( const aiAnimation* pAnim);
64 
65     /** Evaluates the animation tracks for a given time stamp. The calculated pose can be retrieved as a
66      * array of transformation matrices afterwards by calling GetTransformations().
67      * @param pTime The time for which you want to evaluate the animation, in seconds. Will be mapped into the animation cycle, so
68      *   it can be an arbitrary value. Best use with ever-increasing time stamps.
69      */
70     void Evaluate( double pTime);
71 
72     /** Returns the transform matrices calculated at the last Evaluate() call. The array matches the mChannels array of
73      * the aiAnimation. */
GetTransformations()74     const std::vector<aiMatrix4x4>& GetTransformations() const { return mTransforms; }
75 
76 protected:
77     /** The animation we're working on */
78     const aiAnimation* mAnim;
79 
80     /** At which frame the last evaluation happened for each channel.
81      * Useful to quickly find the corresponding frame for slightly increased time stamps
82      */
83     double mLastTime;
84     std::vector<std::tuple<unsigned int, unsigned int, unsigned int> > mLastPositions;
85 
86     /** The array to store the transformations results of the evaluation */
87     std::vector<aiMatrix4x4> mTransforms;
88 };
89 
90 } // end of namespace AssimpView
91 
92 #endif // AV_ANIMEVALUATOR_H_INCLUDED
93