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