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-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __ANIMABLE_H__ 00029 #define __ANIMABLE_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreVector2.h" 00033 #include "OgreVector3.h" 00034 #include "OgreVector4.h" 00035 #include "OgreQuaternion.h" 00036 #include "OgreColourValue.h" 00037 #include "OgreSharedPtr.h" 00038 #include "OgreStringVector.h" 00039 #include "OgreException.h" 00040 #include "OgreAny.h" 00041 00042 namespace Ogre { 00071 class _OgreExport AnimableValue : public AnimableAlloc 00072 { 00073 public: 00075 enum ValueType 00076 { 00077 INT, 00078 REAL, 00079 VECTOR2, 00080 VECTOR3, 00081 VECTOR4, 00082 QUATERNION, 00083 COLOUR, 00084 RADIAN, 00085 DEGREE 00086 }; 00087 protected: 00089 ValueType mType; 00090 00092 union 00093 { 00094 int mBaseValueInt; 00095 Real mBaseValueReal[4]; 00096 }; 00097 00099 virtual void setAsBaseValue(int val) { mBaseValueInt = val; } 00101 virtual void setAsBaseValue(Real val) { mBaseValueReal[0] = val; } 00103 virtual void setAsBaseValue(const Vector2& val) 00104 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*2); } 00106 virtual void setAsBaseValue(const Vector3& val) 00107 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*3); } 00109 virtual void setAsBaseValue(const Vector4& val) 00110 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); } 00112 virtual void setAsBaseValue(const Quaternion& val) 00113 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); } 00115 virtual void setAsBaseValue(const Any& val); 00117 virtual void setAsBaseValue(const ColourValue& val) 00118 { 00119 mBaseValueReal[0] = val.r; 00120 mBaseValueReal[1] = val.g; 00121 mBaseValueReal[2] = val.b; 00122 mBaseValueReal[3] = val.a; 00123 } 00125 virtual void setAsBaseValue(const Radian& val) 00126 { 00127 mBaseValueReal[0] = val.valueRadians(); 00128 } 00130 virtual void setAsBaseValue(const Degree& val) 00131 { 00132 mBaseValueReal[0] = val.valueRadians(); 00133 } 00134 00135 00136 public: 00137 AnimableValue(ValueType t) : mType(t) {} 00138 virtual ~AnimableValue() {} 00139 00141 ValueType getType(void) const { return mType; } 00142 00144 virtual void setCurrentStateAsBaseValue(void) = 0; 00145 00147 virtual void setValue(int) { 00148 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00149 } 00151 virtual void setValue(Real) { 00152 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00153 } 00155 virtual void setValue(const Vector2&) { 00156 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00157 } 00159 virtual void setValue(const Vector3&) { 00160 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00161 } 00163 virtual void setValue(const Vector4&) { 00164 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00165 } 00167 virtual void setValue(const Quaternion&) { 00168 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00169 } 00171 virtual void setValue(const ColourValue&) { 00172 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00173 } 00175 virtual void setValue(const Radian&) { 00176 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00177 } 00179 virtual void setValue(const Degree&) { 00180 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00181 } 00183 virtual void setValue(const Any& val); 00184 00185 // reset to base value 00186 virtual void resetToBaseValue(void); 00187 00189 virtual void applyDeltaValue(int) { 00190 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00191 } 00193 virtual void applyDeltaValue(Real) { 00194 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00195 } 00197 virtual void applyDeltaValue(const Vector2&) { 00198 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00199 } 00201 virtual void applyDeltaValue(const Vector3&) { 00202 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00203 } 00205 virtual void applyDeltaValue(const Vector4&) { 00206 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00207 } 00209 virtual void applyDeltaValue(const Quaternion&) { 00210 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00211 } 00213 virtual void applyDeltaValue(const ColourValue&) { 00214 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00215 } 00217 virtual void applyDeltaValue(const Degree&) { 00218 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00219 } 00221 virtual void applyDeltaValue(const Radian&) { 00222 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00223 } 00225 virtual void applyDeltaValue(const Any& val); 00226 00227 00228 }; 00229 00230 typedef SharedPtr<AnimableValue> AnimableValuePtr; 00231 00232 00233 00237 class _OgreExport AnimableObject 00238 { 00239 protected: 00240 typedef map<String, StringVector>::type AnimableDictionaryMap; 00242 static AnimableDictionaryMap msAnimableDictionary; 00248 virtual const String& getAnimableDictionaryName(void) const 00249 { return StringUtil::BLANK; } 00253 void createAnimableDictionary(void) const 00254 { 00255 if (msAnimableDictionary.find(getAnimableDictionaryName()) 00256 == msAnimableDictionary.end()) 00257 { 00258 StringVector vec; 00259 initialiseAnimableDictionary(vec); 00260 msAnimableDictionary[getAnimableDictionaryName()] = vec; 00261 } 00262 00263 } 00264 00266 StringVector& _getAnimableValueNames(void) 00267 { 00268 AnimableDictionaryMap::iterator i = 00269 msAnimableDictionary.find(getAnimableDictionaryName()); 00270 if (i != msAnimableDictionary.end()) 00271 { 00272 return i->second; 00273 } 00274 else 00275 { 00276 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 00277 "Animable value list not found for " + getAnimableDictionaryName(), 00278 "AnimableObject::getAnimableValueNames"); 00279 } 00280 00281 } 00282 00286 virtual void initialiseAnimableDictionary(StringVector&) const {} 00287 00288 00289 public: 00290 AnimableObject() {} 00291 virtual ~AnimableObject() {} 00292 00294 const StringVector& getAnimableValueNames(void) const 00295 { 00296 createAnimableDictionary(); 00297 00298 AnimableDictionaryMap::iterator i = 00299 msAnimableDictionary.find(getAnimableDictionaryName()); 00300 if (i != msAnimableDictionary.end()) 00301 { 00302 return i->second; 00303 } 00304 else 00305 { 00306 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 00307 "Animable value list not found for " + getAnimableDictionaryName(), 00308 "AnimableObject::getAnimableValueNames"); 00309 } 00310 00311 } 00312 00319 virtual AnimableValuePtr createAnimableValue(const String& valueName) 00320 { 00321 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 00322 "No animable value named '" + valueName + "' present.", 00323 "AnimableObject::createAnimableValue"); 00324 } 00325 00326 00327 00328 }; 00329 00333 } 00334 #endif 00335
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:23 2012