OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreAnimable.h
Go to the documentation of this file.
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 "OgreVector2.h"
34 #include "OgreVector4.h"
35 #include "OgreColourValue.h"
36 #include "OgreStringVector.h"
37 #include "OgreException.h"
38 #include "OgreHeaderPrefix.h"
39 
40 namespace Ogre {
41 
42  class Any;
43 
73  {
74  public:
76  enum ValueType
77  {
78  INT,
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:
138  AnimableValue(ValueType t) : mType(t) {}
139  virtual ~AnimableValue() {}
140 
142  ValueType getType(void) const { return mType; }
143 
145  virtual void setCurrentStateAsBaseValue(void) = 0;
146 
148  virtual void setValue(int) {
150  }
152  virtual void setValue(Real) {
154  }
156  virtual void setValue(const Vector2&) {
158  }
160  virtual void setValue(const Vector3&) {
162  }
164  virtual void setValue(const Vector4&) {
166  }
168  virtual void setValue(const Quaternion&) {
170  }
172  virtual void setValue(const ColourValue&) {
174  }
176  virtual void setValue(const Radian&) {
178  }
180  virtual void setValue(const Degree&) {
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) {
192  }
194  virtual void applyDeltaValue(Real) {
196  }
198  virtual void applyDeltaValue(const Vector2&) {
200  }
202  virtual void applyDeltaValue(const Vector3&) {
204  }
206  virtual void applyDeltaValue(const Vector4&) {
208  }
210  virtual void applyDeltaValue(const Quaternion&) {
212  }
214  virtual void applyDeltaValue(const ColourValue&) {
216  }
218  virtual void applyDeltaValue(const Degree&) {
220  }
222  virtual void applyDeltaValue(const Radian&) {
224  }
226  virtual void applyDeltaValue(const Any& val);
227 
228 
229  };
230 
235  {
236  protected:
245  virtual const String& getAnimableDictionaryName(void) const
246  { return BLANKSTRING; }
250  void createAnimableDictionary(void) const
251  {
252  if (msAnimableDictionary.find(getAnimableDictionaryName())
253  == msAnimableDictionary.end())
254  {
255  StringVector vec;
256  initialiseAnimableDictionary(vec);
257  msAnimableDictionary[getAnimableDictionaryName()] = vec;
258  }
259 
260  }
261 
264  {
265  AnimableDictionaryMap::iterator i =
266  msAnimableDictionary.find(getAnimableDictionaryName());
267  if (i != msAnimableDictionary.end())
268  {
269  return i->second;
270  }
271  else
272  {
274  "Animable value list not found for " + getAnimableDictionaryName(),
275  "AnimableObject::getAnimableValueNames");
276  }
277 
278  }
279 
284 
285 
286  public:
288  virtual ~AnimableObject() {}
289 
292  {
293  createAnimableDictionary();
294 
295  AnimableDictionaryMap::iterator i =
296  msAnimableDictionary.find(getAnimableDictionaryName());
297  if (i != msAnimableDictionary.end())
298  {
299  return i->second;
300  }
301  else
302  {
304  "Animable value list not found for " + getAnimableDictionaryName(),
305  "AnimableObject::getAnimableValueNames");
306  }
307 
308  }
309 
316  virtual AnimableValuePtr createAnimableValue(const String& valueName)
317  {
319  "No animable value named '" + valueName + "' present.",
320  "AnimableObject::createAnimableValue");
321  }
322 
323 
324 
325  };
326 
330 }
331 
332 #include "OgreHeaderSuffix.h"
333 
334 #endif
335 
virtual void setValue(Real)
Set value.
Definition: OgreAnimable.h:152
Real * ptr()
Pointer accessor for direct copying.
virtual void setAsBaseValue(const Radian &val)
Internal method to set a value as base.
Definition: OgreAnimable.h:126
virtual void applyDeltaValue(const Vector4 &)
Apply delta value.
Definition: OgreAnimable.h:206
float Real
Software floating point type.
virtual void setAsBaseValue(int val)
Internal method to set a value as base.
Definition: OgreAnimable.h:100
Defines an object property which is animable, i.e.
Definition: OgreAnimable.h:72
#define _OgreExport
Definition: OgrePlatform.h:255
Variant type that can hold Any other type.
Definition: OgreAny.h:54
virtual ~AnimableObject()
Definition: OgreAnimable.h:288
virtual void applyDeltaValue(const ColourValue &)
Apply delta value.
Definition: OgreAnimable.h:214
virtual void applyDeltaValue(const Vector3 &)
Apply delta value.
Definition: OgreAnimable.h:202
Class representing colour.
virtual void initialiseAnimableDictionary(StringVector &) const
Internal method for initialising dictionary; should be implemented by subclasses wanting to expose an...
Definition: OgreAnimable.h:283
Real valueRadians() const
Definition: OgreMath.h:762
virtual void setValue(const Quaternion &)
Set value.
Definition: OgreAnimable.h:168
virtual void setValue(const Degree &)
Set value.
Definition: OgreAnimable.h:180
virtual void setValue(const Vector2 &)
Set value.
Definition: OgreAnimable.h:156
virtual void setValue(const Vector3 &)
Set value.
Definition: OgreAnimable.h:160
Defines an interface to classes which have one or more AnimableValue instances to expose...
Definition: OgreAnimable.h:234
virtual void setValue(const Radian &)
Set value.
Definition: OgreAnimable.h:176
virtual AnimableValuePtr createAnimableValue(const String &valueName)
Create a reference-counted AnimableValuePtr for the named value.
Definition: OgreAnimable.h:316
const StringVector & getAnimableValueNames(void) const
Gets a list of animable value names for this object.
Definition: OgreAnimable.h:291
const String BLANKSTRING
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreCommon.h:574
Real * ptr()
Pointer accessor for direct copying.
Definition: OgreVector3.h:119
Implementation of a Quaternion, i.e.
ValueType mType
Value type.
Definition: OgreAnimable.h:90
Real * ptr()
Pointer accessor for direct copying.
Definition: OgreVector4.h:123
map< String, StringVector >::type AnimableDictionaryMap
Definition: OgreAnimable.h:237
virtual void applyDeltaValue(const Degree &)
Apply delta value.
Definition: OgreAnimable.h:218
ValueType getType(void) const
Gets the value type of this animable value.
Definition: OgreAnimable.h:142
virtual void setAsBaseValue(const ColourValue &val)
Internal method to set a value as base.
Definition: OgreAnimable.h:118
virtual void applyDeltaValue(const Radian &)
Apply delta value.
Definition: OgreAnimable.h:222
virtual void applyDeltaValue(Real)
Set value.
Definition: OgreAnimable.h:194
virtual void setAsBaseValue(const Vector2 &val)
Internal method to set a value as base.
Definition: OgreAnimable.h:104
StringVector & _getAnimableValueNames(void)
Get an updateable reference to animable value list.
Definition: OgreAnimable.h:263
ValueType
The type of the value being animated.
Definition: OgreAnimable.h:76
#define OGRE_EXCEPT(num, desc, src)
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Standard 2-dimensional vector.
Definition: OgreVector2.h:51
Wrapper class which indicates a given angle value is in Degrees.
Definition: OgreMath.h:100
vector< String >::type StringVector
virtual void applyDeltaValue(const Vector2 &)
Apply delta value.
Definition: OgreAnimable.h:198
virtual void setValue(const Vector4 &)
Set value.
Definition: OgreAnimable.h:164
Real valueRadians() const
Definition: OgreMath.h:61
virtual void setAsBaseValue(Real val)
Internal method to set a value as base.
Definition: OgreAnimable.h:102
virtual const String & getAnimableDictionaryName(void) const
Get the name of the animable dictionary for this class.
Definition: OgreAnimable.h:245
virtual void setAsBaseValue(const Vector3 &val)
Internal method to set a value as base.
Definition: OgreAnimable.h:107
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
std::map< K, V, P, A > type
virtual void setAsBaseValue(const Quaternion &val)
Internal method to set a value as base.
Definition: OgreAnimable.h:113
virtual ~AnimableValue()
Definition: OgreAnimable.h:139
AnimableValue(ValueType t)
Definition: OgreAnimable.h:138
static AnimableDictionaryMap msAnimableDictionary
Static map of class name to list of animable value names.
Definition: OgreAnimable.h:239
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:49
virtual void setValue(const ColourValue &)
Set value.
Definition: OgreAnimable.h:172
_StringBase String
Definition: OgreCommon.h:53
virtual void applyDeltaValue(const Quaternion &)
Apply delta value.
Definition: OgreAnimable.h:210
virtual void applyDeltaValue(int)
Apply delta value.
Definition: OgreAnimable.h:190
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
void createAnimableDictionary(void) const
Internal method for creating a dictionary of animable value names for the class, if it does not alrea...
Definition: OgreAnimable.h:250
Real * ptr()
Pointer accessor for direct copying.
Definition: OgreVector2.h:115
virtual void setAsBaseValue(const Vector4 &val)
Internal method to set a value as base.
Definition: OgreAnimable.h:110
virtual void setAsBaseValue(const Degree &val)
Internal method to set a value as base.
Definition: OgreAnimable.h:131
virtual void setValue(int)
Set value.
Definition: OgreAnimable.h:148