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-2013 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 #include "OgreHeaderPrefix.h" 00042 00043 namespace Ogre { 00072 class _OgreExport AnimableValue : public AnimableAlloc 00073 { 00074 public: 00076 enum ValueType 00077 { 00078 INT, 00079 REAL, 00080 VECTOR2, 00081 VECTOR3, 00082 VECTOR4, 00083 QUATERNION, 00084 COLOUR, 00085 RADIAN, 00086 DEGREE 00087 }; 00088 protected: 00090 ValueType mType; 00091 00093 union 00094 { 00095 int mBaseValueInt; 00096 Real mBaseValueReal[4]; 00097 }; 00098 00100 virtual void setAsBaseValue(int val) { mBaseValueInt = val; } 00102 virtual void setAsBaseValue(Real val) { mBaseValueReal[0] = val; } 00104 virtual void setAsBaseValue(const Vector2& val) 00105 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*2); } 00107 virtual void setAsBaseValue(const Vector3& val) 00108 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*3); } 00110 virtual void setAsBaseValue(const Vector4& val) 00111 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); } 00113 virtual void setAsBaseValue(const Quaternion& val) 00114 { memcpy(mBaseValueReal, val.ptr(), sizeof(Real)*4); } 00116 virtual void setAsBaseValue(const Any& val); 00118 virtual void setAsBaseValue(const ColourValue& val) 00119 { 00120 mBaseValueReal[0] = val.r; 00121 mBaseValueReal[1] = val.g; 00122 mBaseValueReal[2] = val.b; 00123 mBaseValueReal[3] = val.a; 00124 } 00126 virtual void setAsBaseValue(const Radian& val) 00127 { 00128 mBaseValueReal[0] = val.valueRadians(); 00129 } 00131 virtual void setAsBaseValue(const Degree& val) 00132 { 00133 mBaseValueReal[0] = val.valueRadians(); 00134 } 00135 00136 00137 public: 00138 AnimableValue(ValueType t) : mType(t) {} 00139 virtual ~AnimableValue() {} 00140 00142 ValueType getType(void) const { return mType; } 00143 00145 virtual void setCurrentStateAsBaseValue(void) = 0; 00146 00148 virtual void setValue(int) { 00149 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00150 } 00152 virtual void setValue(Real) { 00153 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00154 } 00156 virtual void setValue(const Vector2&) { 00157 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00158 } 00160 virtual void setValue(const Vector3&) { 00161 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00162 } 00164 virtual void setValue(const Vector4&) { 00165 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00166 } 00168 virtual void setValue(const Quaternion&) { 00169 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00170 } 00172 virtual void setValue(const ColourValue&) { 00173 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00174 } 00176 virtual void setValue(const Radian&) { 00177 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00178 } 00180 virtual void setValue(const Degree&) { 00181 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00182 } 00184 virtual void setValue(const Any& val); 00185 00186 // reset to base value 00187 virtual void resetToBaseValue(void); 00188 00190 virtual void applyDeltaValue(int) { 00191 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00192 } 00194 virtual void applyDeltaValue(Real) { 00195 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00196 } 00198 virtual void applyDeltaValue(const Vector2&) { 00199 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00200 } 00202 virtual void applyDeltaValue(const Vector3&) { 00203 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00204 } 00206 virtual void applyDeltaValue(const Vector4&) { 00207 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00208 } 00210 virtual void applyDeltaValue(const Quaternion&) { 00211 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00212 } 00214 virtual void applyDeltaValue(const ColourValue&) { 00215 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00216 } 00218 virtual void applyDeltaValue(const Degree&) { 00219 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00220 } 00222 virtual void applyDeltaValue(const Radian&) { 00223 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "", ""); 00224 } 00226 virtual void applyDeltaValue(const Any& val); 00227 00228 00229 }; 00230 00231 typedef SharedPtr<AnimableValue> AnimableValuePtr; 00232 00233 00234 00238 class _OgreExport AnimableObject 00239 { 00240 protected: 00241 typedef map<String, StringVector>::type AnimableDictionaryMap; 00243 static AnimableDictionaryMap msAnimableDictionary; 00249 virtual const String& getAnimableDictionaryName(void) const 00250 { return StringUtil::BLANK; } 00254 void createAnimableDictionary(void) const 00255 { 00256 if (msAnimableDictionary.find(getAnimableDictionaryName()) 00257 == msAnimableDictionary.end()) 00258 { 00259 StringVector vec; 00260 initialiseAnimableDictionary(vec); 00261 msAnimableDictionary[getAnimableDictionaryName()] = vec; 00262 } 00263 00264 } 00265 00267 StringVector& _getAnimableValueNames(void) 00268 { 00269 AnimableDictionaryMap::iterator i = 00270 msAnimableDictionary.find(getAnimableDictionaryName()); 00271 if (i != msAnimableDictionary.end()) 00272 { 00273 return i->second; 00274 } 00275 else 00276 { 00277 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 00278 "Animable value list not found for " + getAnimableDictionaryName(), 00279 "AnimableObject::getAnimableValueNames"); 00280 } 00281 00282 } 00283 00287 virtual void initialiseAnimableDictionary(StringVector&) const {} 00288 00289 00290 public: 00291 AnimableObject() {} 00292 virtual ~AnimableObject() {} 00293 00295 const StringVector& getAnimableValueNames(void) const 00296 { 00297 createAnimableDictionary(); 00298 00299 AnimableDictionaryMap::iterator i = 00300 msAnimableDictionary.find(getAnimableDictionaryName()); 00301 if (i != msAnimableDictionary.end()) 00302 { 00303 return i->second; 00304 } 00305 else 00306 { 00307 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 00308 "Animable value list not found for " + getAnimableDictionaryName(), 00309 "AnimableObject::getAnimableValueNames"); 00310 } 00311 00312 } 00313 00320 virtual AnimableValuePtr createAnimableValue(const String& valueName) 00321 { 00322 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 00323 "No animable value named '" + valueName + "' present.", 00324 "AnimableObject::createAnimableValue"); 00325 } 00326 00327 00328 00329 }; 00330 00334 } 00335 00336 #include "OgreHeaderSuffix.h" 00337 00338 #endif 00339
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:40