# OgreAnimable.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __ANIMABLE_H__
    00030 #define __ANIMABLE_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreVector2.h"
    00034 #include "OgreVector3.h"
    00035 #include "OgreVector4.h"
    00036 #include "OgreQuaternion.h"
    00037 #include "OgreColourValue.h"
    00038 #include "OgreSharedPtr.h"
    00039 #include "OgreStringVector.h"
    00040 #include "OgreException.h"
    00041 #include "OgreAny.h"
    00042
    00043 namespace Ogre {
    00044
    00065     class _OgreExport AnimableValue : public AnimableAlloc
    00066     {
    00067     public:
    00069         enum ValueType
    00070         {
    00071             INT,
    00072             REAL,
    00073             VECTOR2,
    00074             VECTOR3,
    00075             VECTOR4,
    00076             QUATERNION,
    00077             COLOUR,
    00078             RADIAN,
    00079             DEGREE
    00080         };
    00081     protected:
    00083         ValueType mType;
    00084
    00086         union
    00087         {
    00088             int mBaseValueInt;
    00089             Real mBaseValueReal[4];
    00090         };
    00091
    00093         virtual void setAsBaseValue(int val) { mBaseValueInt = val; }
    00095         virtual void setAsBaseValue(Real val) { mBaseValueReal[0] = val; }
    00097         virtual void setAsBaseValue(const Vector2& val)
    00098         { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*2); }
    00100         virtual void setAsBaseValue(const Vector3& val)
    00101         { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*3); }
    00103         virtual void setAsBaseValue(const Vector4& val)
    00104         { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); }
    00106         virtual void setAsBaseValue(const Quaternion& val)
    00107         { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); }
    00109         virtual void setAsBaseValue(const Any& val);
    00111         virtual void setAsBaseValue(const ColourValue& val)
    00112         {
    00113             mBaseValueReal[0] = val.r;
    00114             mBaseValueReal[1] = val.g;
    00115             mBaseValueReal[2] = val.b;
    00116             mBaseValueReal[3] = val.a;
    00117         }
    00119         virtual void setAsBaseValue(const Radian& val)
    00120         {
    00121             mBaseValueReal[0] = val.valueRadians();
    00122         }
    00124         virtual void setAsBaseValue(const Degree& val)
    00125         {
    00126             mBaseValueReal[0] = val.valueRadians();
    00127         }
    00128
    00129
    00130     public:
    00131         AnimableValue(ValueType t) : mType(t) {}
    00132         virtual ~AnimableValue() {}
    00133
    00135         ValueType getType(void) const { return mType; }
    00136
    00138         virtual void setCurrentStateAsBaseValue(void) = 0;
    00139
    00141         virtual void setValue(int) {
    00142             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00143         }
    00145         virtual void setValue(Real) {
    00146             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00147         }
    00149         virtual void setValue(const Vector2&) {
    00150             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00151         }
    00153         virtual void setValue(const Vector3&) {
    00154             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00155         }
    00157         virtual void setValue(const Vector4&) {
    00158             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00159         }
    00161         virtual void setValue(const Quaternion&) {
    00162             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00163         }
    00165         virtual void setValue(const ColourValue&) {
    00166             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00167         }
    00169         virtual void setValue(const Radian&) {
    00170             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00171         }
    00173         virtual void setValue(const Degree&) {
    00174             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00175         }
    00177         virtual void setValue(const Any& val);
    00178
    00179         // reset to base value
    00180         virtual void resetToBaseValue(void);
    00181
    00183         virtual void applyDeltaValue(int) {
    00184             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00185         }
    00187         virtual void applyDeltaValue(Real) {
    00188             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00189         }
    00191         virtual void applyDeltaValue(const Vector2&) {
    00192             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00193         }
    00195         virtual void applyDeltaValue(const Vector3&) {
    00196             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00197         }
    00199         virtual void applyDeltaValue(const Vector4&) {
    00200             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00201         }
    00203         virtual void applyDeltaValue(const Quaternion&) {
    00204             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00205         }
    00207         virtual void applyDeltaValue(const ColourValue&) {
    00208             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00209         }
    00211         virtual void applyDeltaValue(const Degree&) {
    00212             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00213         }
    00215         virtual void applyDeltaValue(const Radian&) {
    00216             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
    00217         }
    00219         virtual void applyDeltaValue(const Any& val);
    00220
    00221
    00222     };
    00223
    00224     typedef SharedPtr<AnimableValue> AnimableValuePtr;
    00225
    00226
    00227
    00231     class _OgreExport AnimableObject
    00232     {
    00233     protected:
    00234         typedef std::map<String, StringVector> AnimableDictionaryMap;
    00236         static AnimableDictionaryMap msAnimableDictionary;
    00242         virtual const String& getAnimableDictionaryName(void) const
    00243         { return StringUtil::BLANK; }
    00247         void createAnimableDictionary(void) const
    00248         {
    00249             if (msAnimableDictionary.find(getAnimableDictionaryName())
    00250                 == msAnimableDictionary.end())
    00251             {
    00252                 StringVector vec;
    00253                 initialiseAnimableDictionary(vec);
    00254                 msAnimableDictionary[getAnimableDictionaryName()] = vec;
    00255             }
    00256
    00257         }
    00258
    00260         StringVector& _getAnimableValueNames(void)
    00261         {
    00262             AnimableDictionaryMap::iterator i =
    00263                 msAnimableDictionary.find(getAnimableDictionaryName());
    00264             if (i != msAnimableDictionary.end())
    00265             {
    00266                 return i->second;
    00267             }
    00268             else
    00269             {
    00270                 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
    00271                     "Animable value list not found for " + getAnimableDictionaryName(),
    00272                     "AnimableObject::getAnimableValueNames");
    00273             }
    00274
    00275         }
    00276
    00280         virtual void initialiseAnimableDictionary(StringVector&) const {}
    00281
    00282
    00283     public:
    00284         AnimableObject() {}
    00285         virtual ~AnimableObject() {}
    00286
    00288         const StringVector& getAnimableValueNames(void) const
    00289         {
    00290             createAnimableDictionary();
    00291
    00292             AnimableDictionaryMap::iterator i =
    00293                 msAnimableDictionary.find(getAnimableDictionaryName());
    00294             if (i != msAnimableDictionary.end())
    00295             {
    00296                 return i->second;
    00297             }
    00298             else
    00299             {
    00300                 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
    00301                     "Animable value list not found for " + getAnimableDictionaryName(),
    00302                     "AnimableObject::getAnimableValueNames");
    00303             }
    00304
    00305         }
    00306
    00313         virtual AnimableValuePtr createAnimableValue(const String& valueName)
    00314         {
    00315             OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
    00316                 "No animable value named '" + valueName + "' present.",
    00317                 "AnimableObject::createAnimableValue");
    00318         }
    00319
    00320
    00321
    00322     };
    00323
    00324
    00325 }
    00326 #endif
    00327

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 14:26:36 2009