Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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-2005 The OGRE Team
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 */
00025 #ifndef __ANIMABLE_H__
00026 #define __ANIMABLE_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 #include "OgreVector2.h"
00030 #include "OgreVector3.h"
00031 #include "OgreVector4.h"
00032 #include "OgreQuaternion.h"
00033 #include "OgreColourValue.h"
00034 #include "OgreSharedPtr.h"
00035 #include "OgreStringVector.h"
00036 #include "OgreException.h"
00037 #include "OgreAny.h"
00038 
00039 namespace Ogre {
00040 
00061     class _OgreExport AnimableValue
00062     {
00063     public:
00065         enum ValueType
00066         {
00067             INT,
00068             REAL,
00069             VECTOR2,
00070             VECTOR3,
00071             VECTOR4,
00072             QUATERNION,
00073             COLOUR
00074         };
00075     protected:
00077         ValueType mType;
00078 
00080         union
00081         {
00082             int mBaseValueInt;
00083             Real mBaseValueReal[4];
00084         };
00085 
00087         virtual void setAsBaseValue(int val) { mBaseValueInt = val; }
00089         virtual void setAsBaseValue(Real val) { mBaseValueReal[0] = val; }
00091         virtual void setAsBaseValue(const Vector2& val) 
00092         { memcpy(mBaseValueReal, val.val, sizeof(Real)*2); }
00094         virtual void setAsBaseValue(const Vector3& val) 
00095         { memcpy(mBaseValueReal, val.val, sizeof(Real)*3); }
00097         virtual void setAsBaseValue(const Vector4& val) 
00098         { memcpy(mBaseValueReal, val.val, sizeof(Real)*4); }
00100         virtual void setAsBaseValue(const Quaternion& val) 
00101         { memcpy(mBaseValueReal, val.val, sizeof(Real)*4); }
00103         virtual void setAsBaseValue(const Any& val);
00105         virtual void setAsBaseValue(const ColourValue& val)
00106         { 
00107             mBaseValueReal[0] = val.r;
00108             mBaseValueReal[1] = val.g;
00109             mBaseValueReal[2] = val.b;
00110             mBaseValueReal[3] = val.a;
00111         }
00112 
00113 
00114     public:
00115         AnimableValue(ValueType t) : mType(t) {}
00116         virtual ~AnimableValue() {}
00117 
00119         ValueType getType(void) const { return mType; }
00120 
00122         virtual void setCurrentStateAsBaseValue(void) = 0;
00123 
00125         virtual void setValue(int val) {
00126             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00127         }
00129         virtual void setValue(Real val) {
00130             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00131         }
00133         virtual void setValue(const Vector2& val) {
00134             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00135         }
00137         virtual void setValue(const Vector3& val) {
00138             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00139         }
00141         virtual void setValue(const Vector4& val) {
00142             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00143         }
00145         virtual void setValue(const Quaternion& val) {
00146             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00147         }
00149         virtual void setValue(const ColourValue& val) {
00150             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00151         }
00153         virtual void setValue(const Any& val);
00154 
00155         // reset to base value
00156         virtual void resetToBaseValue(void);
00157 
00159         virtual void applyDeltaValue(int val) {
00160             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00161         }
00163         virtual void applyDeltaValue(Real val) {
00164             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00165         }
00167         virtual void applyDeltaValue(const Vector2& val) {
00168             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00169         }
00171         virtual void applyDeltaValue(const Vector3& val) {
00172             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00173         }
00175         virtual void applyDeltaValue(const Vector4& val) {
00176             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00177         }
00179         virtual void applyDeltaValue(const Quaternion& val) {
00180             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00181         }
00183         virtual void applyDeltaValue(const ColourValue& val) {
00184             OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", "");
00185         }
00187         virtual void applyDeltaValue(const Any& val);
00188 
00189 
00190     };
00191 
00192     typedef SharedPtr<AnimableValue> AnimableValuePtr;
00193 
00194 
00195 
00199     class _OgreExport AnimableObject
00200     {
00201     protected:
00202         typedef std::map<String, StringVector> AnimableDictionaryMap;
00204         static AnimableDictionaryMap msAnimableDictionary;
00210         virtual const String& getAnimableDictionaryName(void) const 
00211         { return StringUtil::BLANK; }
00215         void createAnimableDictionary(void) const
00216         {
00217             if (msAnimableDictionary.find(getAnimableDictionaryName()) 
00218                 == msAnimableDictionary.end())
00219             {
00220                 StringVector vec;
00221                 initialiseAnimableDictionary(vec);
00222                 msAnimableDictionary[getAnimableDictionaryName()] = vec;
00223             }
00224 
00225         }
00226     
00228         StringVector& getAnimableValueNames(void)
00229         {
00230             AnimableDictionaryMap::iterator i = 
00231                 msAnimableDictionary.find(getAnimableDictionaryName());
00232             if (i != msAnimableDictionary.end())
00233             {
00234                 return i->second;
00235             }
00236             else
00237             {
00238                 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 
00239                     "Animable value list not found for " + getAnimableDictionaryName(), 
00240                     "AnimableObject::getAnimableValueNames");
00241             }
00242 
00243         }
00244 
00248         virtual void initialiseAnimableDictionary(StringVector& vec) const {}
00249 
00250 
00251     public:
00252         AnimableObject() {}
00253         virtual ~AnimableObject() {}
00254 
00256         const StringVector& getAnimableValueNames(void) const
00257         {
00258             createAnimableDictionary();
00259 
00260             AnimableDictionaryMap::iterator i = 
00261                 msAnimableDictionary.find(getAnimableDictionaryName());
00262             if (i != msAnimableDictionary.end())
00263             {
00264                 return i->second;
00265             }
00266             else
00267             {
00268                 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 
00269                     "Animable value list not found for " + getAnimableDictionaryName(), 
00270                     "AnimableObject::getAnimableValueNames");
00271             }
00272 
00273         }
00274 
00281         virtual AnimableValuePtr createAnimableValue(const String& valueName)
00282         {
00283             OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 
00284                 "No animable value named '" + valueName + "' present.", 
00285                 "AnimableObject::createAnimableValue");
00286         }
00287 
00288 
00289 
00290     };
00291 
00292 
00293 }
00294 #endif
00295 

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:36 2006