OgreAnimable.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __ANIMABLE_H__
29#define __ANIMABLE_H__
30
31#include "OgrePrerequisites.h"
32#include "OgreVector2.h"
33#include "OgreVector3.h"
34#include "OgreVector4.h"
35#include "OgreQuaternion.h"
36#include "OgreColourValue.h"
37#include "OgreSharedPtr.h"
38#include "OgreStringVector.h"
39#include "OgreException.h"
40#include "OgreAny.h"
41#include "OgreHeaderPrefix.h"
42
43namespace Ogre {
73 {
74 public:
77 {
86 DEGREE
87 };
88 protected:
91
93 union
94 {
96 Real mBaseValueReal[4];
97 };
98
100 virtual void setAsBaseValue(int val) { mBaseValueInt = val; }
102 virtual void setAsBaseValue(Real val) { mBaseValueReal[0] = val; }
104 virtual void setAsBaseValue(const Vector2& val)
105 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*2); }
107 virtual void setAsBaseValue(const Vector3& val)
108 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*3); }
110 virtual void setAsBaseValue(const Vector4& val)
111 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); }
113 virtual void setAsBaseValue(const Quaternion& val)
114 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); }
116 virtual void setAsBaseValue(const Any& val);
118 virtual void setAsBaseValue(const ColourValue& val)
119 {
120 mBaseValueReal[0] = val.r;
121 mBaseValueReal[1] = val.g;
122 mBaseValueReal[2] = val.b;
123 mBaseValueReal[3] = val.a;
124 }
126 virtual void setAsBaseValue(const Radian& val)
127 {
128 mBaseValueReal[0] = val.valueRadians();
129 }
131 virtual void setAsBaseValue(const Degree& val)
132 {
133 mBaseValueReal[0] = val.valueRadians();
134 }
135
136
137 public:
139 virtual ~AnimableValue() {}
140
142 ValueType getType(void) const { return mType; }
143
145 virtual void setCurrentStateAsBaseValue(void) = 0;
146
148 virtual void setValue(int) {
149 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
150 }
152 virtual void setValue(Real) {
153 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
154 }
156 virtual void setValue(const Vector2&) {
157 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
158 }
160 virtual void setValue(const Vector3&) {
161 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
162 }
164 virtual void setValue(const Vector4&) {
165 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
166 }
168 virtual void setValue(const Quaternion&) {
169 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
170 }
172 virtual void setValue(const ColourValue&) {
173 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
174 }
176 virtual void setValue(const Radian&) {
177 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
178 }
180 virtual void setValue(const Degree&) {
181 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
182 }
184 virtual void setValue(const Any& val);
185
186 // reset to base value
187 virtual void resetToBaseValue(void);
188
190 virtual void applyDeltaValue(int) {
191 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
192 }
194 virtual void applyDeltaValue(Real) {
195 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
196 }
198 virtual void applyDeltaValue(const Vector2&) {
199 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
200 }
202 virtual void applyDeltaValue(const Vector3&) {
203 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
204 }
206 virtual void applyDeltaValue(const Vector4&) {
207 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
208 }
210 virtual void applyDeltaValue(const Quaternion&) {
211 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
212 }
214 virtual void applyDeltaValue(const ColourValue&) {
215 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
216 }
218 virtual void applyDeltaValue(const Degree&) {
219 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
220 }
222 virtual void applyDeltaValue(const Radian&) {
223 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
224 }
226 virtual void applyDeltaValue(const Any& val);
227
228
229 };
230
232
233
234
239 {
240 protected:
249 virtual const String& getAnimableDictionaryName(void) const
250 { return StringUtil::BLANK; }
255 {
256 if (msAnimableDictionary.find(getAnimableDictionaryName())
257 == msAnimableDictionary.end())
258 {
260 initialiseAnimableDictionary(vec);
261 msAnimableDictionary[getAnimableDictionaryName()] = vec;
262 }
263
264 }
265
268 {
269 AnimableDictionaryMap::iterator i =
270 msAnimableDictionary.find(getAnimableDictionaryName());
271 if (i != msAnimableDictionary.end())
272 {
273 return i->second;
274 }
275 else
276 {
277 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
278 "Animable value list not found for " + getAnimableDictionaryName(),
279 "AnimableObject::getAnimableValueNames");
280 }
281
282 }
283
288
289
290 public:
292 virtual ~AnimableObject() {}
293
296 {
297 createAnimableDictionary();
298
299 AnimableDictionaryMap::iterator i =
300 msAnimableDictionary.find(getAnimableDictionaryName());
301 if (i != msAnimableDictionary.end())
302 {
303 return i->second;
304 }
305 else
306 {
307 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
308 "Animable value list not found for " + getAnimableDictionaryName(),
309 "AnimableObject::getAnimableValueNames");
310 }
311
312 }
313
321 {
322 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
323 "No animable value named '" + valueName + "' present.",
324 "AnimableObject::createAnimableValue");
325 }
326
327
328
329 };
330
334}
335
336#include "OgreHeaderSuffix.h"
337
338#endif
339
#define _OgreExport
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Defines an interface to classes which have one or more AnimableValue instances to expose.
static AnimableDictionaryMap msAnimableDictionary
Static map of class name to list of animable value names.
map< String, StringVector >::type AnimableDictionaryMap
virtual void initialiseAnimableDictionary(StringVector &) const
Internal method for initialising dictionary; should be implemented by subclasses wanting to expose an...
virtual const String & getAnimableDictionaryName(void) const
Get the name of the animable dictionary for this class.
void createAnimableDictionary(void) const
Internal method for creating a dictionary of animable value names for the class, if it does not alrea...
const StringVector & getAnimableValueNames(void) const
Gets a list of animable value names for this object.
virtual AnimableValuePtr createAnimableValue(const String &valueName)
Create a reference-counted AnimableValuePtr for the named value.
StringVector & _getAnimableValueNames(void)
Get an updateable reference to animable value list.
Defines an object property which is animable, i.e.
virtual void applyDeltaValue(int)
Apply delta value.
virtual void setValue(const Radian &)
Set value.
virtual void setAsBaseValue(const ColourValue &val)
Internal method to set a value as base.
AnimableValue(ValueType t)
virtual void setAsBaseValue(const Degree &val)
Internal method to set a value as base.
virtual void setValue(const ColourValue &)
Set value.
virtual void setValue(const Vector2 &)
Set value.
virtual void setAsBaseValue(const Vector2 &val)
Internal method to set a value as base.
virtual void applyDeltaValue(const Vector4 &)
Apply delta value.
virtual void setAsBaseValue(Real val)
Internal method to set a value as base.
virtual void applyDeltaValue(const Vector2 &)
Apply delta value.
virtual void setValue(const Quaternion &)
Set value.
virtual void applyDeltaValue(const Any &val)
Apply delta value.
virtual void setAsBaseValue(const Vector3 &val)
Internal method to set a value as base.
virtual void setValue(int)
Set value.
virtual void applyDeltaValue(const Quaternion &)
Apply delta value.
virtual void setAsBaseValue(const Any &val)
Internal method to set a value as base.
virtual void applyDeltaValue(const Radian &)
Apply delta value.
virtual void applyDeltaValue(Real)
Set value.
virtual void applyDeltaValue(const Degree &)
Apply delta value.
virtual void setValue(const Vector3 &)
Set value.
virtual void setValue(const Vector4 &)
Set value.
virtual void setValue(Real)
Set value.
ValueType mType
Value type.
virtual void setAsBaseValue(int val)
Internal method to set a value as base.
virtual void setCurrentStateAsBaseValue(void)=0
Sets the current state as the 'base' value; used for delta animation.
virtual void applyDeltaValue(const Vector3 &)
Apply delta value.
virtual void setValue(const Any &val)
Set value.
ValueType getType(void) const
Gets the value type of this animable value.
virtual void applyDeltaValue(const ColourValue &)
Apply delta value.
virtual void setAsBaseValue(const Vector4 &val)
Internal method to set a value as base.
virtual void setAsBaseValue(const Quaternion &val)
Internal method to set a value as base.
ValueType
The type of the value being animated.
virtual void setValue(const Degree &)
Set value.
virtual void resetToBaseValue(void)
virtual void setAsBaseValue(const Radian &val)
Internal method to set a value as base.
Variant type that can hold Any other type.
Definition OgreAny.h:57
Class representing colour.
Wrapper class which indicates a given angle value is in Degrees.
Definition OgreMath.h:99
Implementation of a Quaternion, i.e.
Real * ptr()
Pointer accessor for direct copying.
Wrapper class which indicates a given angle value is in Radians.
Definition OgreMath.h:48
Real valueRadians() const
Definition OgreMath.h:59
Reference-counted shared pointer, used for objects where implicit destruction is required.
Standard 2-dimensional vector.
Definition OgreVector2.h:52
Real * ptr()
Pointer accessor for direct copying.
Standard 3-dimensional vector.
Definition OgreVector3.h:52
Real * ptr()
Pointer accessor for direct copying.
4-dimensional homogeneous vector.
Definition OgreVector4.h:46
Real * ptr()
Pointer accessor for direct copying.
SharedPtr< AnimableValue > AnimableValuePtr
vector< String >::type StringVector
#define OGRE_EXCEPT(num, desc, src)
Real valueRadians() const
Definition OgreMath.h:727
_StringBase String
std::map< K, V, P, A > type

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.