/src/ogre/OgreMain/include/OgreAnimable.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #ifndef __ANIMABLE_H__ |
29 | | #define __ANIMABLE_H__ |
30 | | |
31 | | #include "OgrePrerequisites.h" |
32 | | #include "OgreCommon.h" |
33 | | #include "OgreVector.h" |
34 | | #include "OgreColourValue.h" |
35 | | #include "OgreStringVector.h" |
36 | | #include "OgreException.h" |
37 | | #include "OgreHeaderPrefix.h" |
38 | | |
39 | | namespace Ogre { |
40 | | |
41 | | class Any; |
42 | | |
43 | | /** \addtogroup Core |
44 | | * @{ |
45 | | */ |
46 | | |
47 | | /** \addtogroup Animation |
48 | | * @{ |
49 | | */ |
50 | | |
51 | | /** Defines an object property which is animable, i.e. may be keyframed. |
52 | | |
53 | | Animable properties are those which can be altered over time by a |
54 | | predefined keyframe sequence. They may be set directly, or they may |
55 | | be modified from their existing state (common if multiple animations |
56 | | are expected to apply at once). Implementors of this interface are |
57 | | expected to override the 'setValue', 'setCurrentStateAsBaseValue' and |
58 | | 'applyDeltaValue' methods appropriate to the type in question, and to |
59 | | initialise the type. |
60 | | @par |
61 | | AnimableValue instances are accessible through any class which extends |
62 | | AnimableObject in order to expose it's animable properties. |
63 | | @note |
64 | | This class is an instance of the Adapter pattern, since it generalises |
65 | | access to a particular property. Whilst it could have been templated |
66 | | such that the type which was being referenced was compiled in, this would |
67 | | make it more difficult to aggregated generically, and since animations |
68 | | are often comprised of multiple properties it helps to be able to deal |
69 | | with all values through a single class. |
70 | | */ |
71 | | class _OgreExport AnimableValue : public AnimableAlloc |
72 | | { |
73 | | public: |
74 | | /// The type of the value being animated |
75 | | enum ValueType |
76 | | { |
77 | | INT, |
78 | | REAL, |
79 | | VECTOR2, |
80 | | VECTOR3, |
81 | | VECTOR4, |
82 | | QUATERNION, |
83 | | COLOUR, |
84 | | RADIAN |
85 | | }; |
86 | | protected: |
87 | | /// Value type |
88 | | ValueType mType; |
89 | | |
90 | | /// Base value data |
91 | | union |
92 | | { |
93 | | int mBaseValueInt; |
94 | | Real mBaseValueReal[4]; |
95 | | }; |
96 | | |
97 | | /// Internal method to set a value as base |
98 | 0 | virtual void setAsBaseValue(int val) { mBaseValueInt = val; } |
99 | | /// Internal method to set a value as base |
100 | 0 | virtual void setAsBaseValue(Real val) { mBaseValueReal[0] = val; } |
101 | | /// Internal method to set a value as base |
102 | | virtual void setAsBaseValue(const Vector2& val) |
103 | 0 | { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*2); } |
104 | | /// Internal method to set a value as base |
105 | | virtual void setAsBaseValue(const Vector3& val) |
106 | 0 | { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*3); } |
107 | | /// Internal method to set a value as base |
108 | | virtual void setAsBaseValue(const Vector4& val) |
109 | 0 | { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); } |
110 | | /// Internal method to set a value as base |
111 | | virtual void setAsBaseValue(const Quaternion& val) |
112 | 0 | { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); } |
113 | | /// Internal method to set a value as base |
114 | | virtual void setAsBaseValue(const Any& val); |
115 | | /// Internal method to set a value as base |
116 | | virtual void setAsBaseValue(const ColourValue& val) |
117 | 0 | { |
118 | 0 | mBaseValueReal[0] = val.r; |
119 | 0 | mBaseValueReal[1] = val.g; |
120 | 0 | mBaseValueReal[2] = val.b; |
121 | 0 | mBaseValueReal[3] = val.a; |
122 | 0 | } |
123 | | /// Internal method to set a value as base |
124 | | virtual void setAsBaseValue(const Radian& val) |
125 | 0 | { |
126 | 0 | mBaseValueReal[0] = val.valueRadians(); |
127 | 0 | } |
128 | | /// Internal method to set a value as base |
129 | | virtual void setAsBaseValue(const Degree& val) |
130 | 0 | { |
131 | 0 | mBaseValueReal[0] = val.valueRadians(); |
132 | 0 | } |
133 | | |
134 | | |
135 | | public: |
136 | 0 | AnimableValue(ValueType t) : mType(t) {} |
137 | 0 | virtual ~AnimableValue() {} |
138 | | |
139 | | /// Gets the value type of this animable value |
140 | 0 | ValueType getType(void) const { return mType; } |
141 | | |
142 | | /// Sets the current state as the 'base' value; used for delta animation |
143 | | virtual void setCurrentStateAsBaseValue(void) = 0; |
144 | | |
145 | | /// Set value |
146 | 0 | virtual void setValue(int) { |
147 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
148 | 0 | } |
149 | | /// Set value |
150 | 0 | virtual void setValue(Real) { |
151 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
152 | 0 | } |
153 | | /// Set value |
154 | 0 | virtual void setValue(const Vector2&) { |
155 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
156 | 0 | } |
157 | | /// Set value |
158 | 0 | virtual void setValue(const Vector3&) { |
159 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
160 | 0 | } |
161 | | /// Set value |
162 | 0 | virtual void setValue(const Vector4&) { |
163 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
164 | 0 | } |
165 | | /// Set value |
166 | 0 | virtual void setValue(const Quaternion&) { |
167 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
168 | 0 | } |
169 | | /// Set value |
170 | 0 | virtual void setValue(const ColourValue&) { |
171 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
172 | 0 | } |
173 | | /// Set value |
174 | 0 | virtual void setValue(const Radian&) { |
175 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
176 | 0 | } |
177 | | /// Set value |
178 | 0 | void setValue(const Degree& val) { setValue(Radian(val)); } |
179 | | /// Set value |
180 | | virtual void setValue(const Any& val); |
181 | | |
182 | | // reset to base value |
183 | | virtual void resetToBaseValue(void); |
184 | | |
185 | | /// Apply delta value |
186 | 0 | virtual void applyDeltaValue(int) { |
187 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
188 | 0 | } |
189 | | /// Set value |
190 | 0 | virtual void applyDeltaValue(Real) { |
191 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
192 | 0 | } |
193 | | /// Apply delta value |
194 | 0 | virtual void applyDeltaValue(const Vector2&) { |
195 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
196 | 0 | } |
197 | | /// Apply delta value |
198 | 0 | virtual void applyDeltaValue(const Vector3&) { |
199 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
200 | 0 | } |
201 | | /// Apply delta value |
202 | 0 | virtual void applyDeltaValue(const Vector4&) { |
203 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
204 | 0 | } |
205 | | /// Apply delta value |
206 | 0 | virtual void applyDeltaValue(const Quaternion&) { |
207 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
208 | 0 | } |
209 | | /// Apply delta value |
210 | 0 | virtual void applyDeltaValue(const ColourValue&) { |
211 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
212 | 0 | } |
213 | | /// Apply delta value |
214 | 0 | void applyDeltaValue(const Degree& val) { applyDeltaValue(Radian(val)); } |
215 | | /// Apply delta value |
216 | 0 | virtual void applyDeltaValue(const Radian&) { |
217 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); |
218 | 0 | } |
219 | | /// Apply delta value |
220 | | virtual void applyDeltaValue(const Any& val); |
221 | | |
222 | | |
223 | | }; |
224 | | |
225 | | /** Defines an interface to classes which have one or more AnimableValue |
226 | | instances to expose. |
227 | | */ |
228 | | class _OgreExport AnimableObject |
229 | | { |
230 | | public: |
231 | 0 | AnimableObject() {} |
232 | 0 | virtual ~AnimableObject() {} |
233 | | |
234 | | /** Gets a list of animable value names for this object. */ |
235 | | virtual const StringVector& getAnimableValueNames(void) const |
236 | 0 | { |
237 | 0 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Animable value list not implemented"); |
238 | 0 | } |
239 | | |
240 | | /** Create a reference-counted AnimableValuePtr for the named value. |
241 | | |
242 | | You can use the returned object to animate a value on this object, |
243 | | using AnimationTrack. Subclasses must override this if they wish |
244 | | to support animation of their values. |
245 | | */ |
246 | | virtual AnimableValuePtr createAnimableValue(const String& valueName) |
247 | 0 | { |
248 | 0 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "No animable value named '" + valueName + "' present"); |
249 | 0 | } |
250 | | |
251 | | |
252 | | |
253 | | }; |
254 | | |
255 | | /** @} */ |
256 | | /** @} */ |
257 | | |
258 | | } |
259 | | |
260 | | #include "OgreHeaderSuffix.h" |
261 | | |
262 | | #endif |
263 | | |