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 __Controller_H__ 00026 #define __Controller_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 00030 #include "OgreSharedPtr.h" 00031 00032 namespace Ogre { 00033 00034 00035 00036 00046 template <typename T> 00047 class ControllerFunction 00048 { 00049 protected: 00051 bool mDeltaInput; 00052 T mDeltaCount; 00053 00056 T getAdjustedInput(T input) 00057 { 00058 if (mDeltaInput) 00059 { 00060 mDeltaCount += input; 00061 // Wrap 00062 while (mDeltaCount >= 1.0) 00063 mDeltaCount -= 1.0; 00064 while (mDeltaCount < 0.0) 00065 mDeltaCount += 1.0; 00066 00067 return mDeltaCount; 00068 } 00069 else 00070 { 00071 return input; 00072 } 00073 } 00074 00075 public: 00081 ControllerFunction(bool deltaInput) 00082 { 00083 mDeltaInput = deltaInput; 00084 mDeltaCount = 0; 00085 } 00086 00087 virtual T calculate(T sourceValue) = 0; 00088 }; 00089 00090 00093 template <typename T> 00094 class ControllerValue 00095 { 00096 00097 public: 00098 virtual ~ControllerValue() { } 00099 virtual T getValue(void) const = 0; 00100 virtual void setValue(T value) = 0; 00101 00102 }; 00103 00124 template <typename T> 00125 class Controller 00126 { 00127 protected: 00129 SharedPtr< ControllerValue<T> > mSource; 00131 SharedPtr< ControllerValue<T> > mDest; 00133 SharedPtr< ControllerFunction<T> > mFunc; 00135 bool mEnabled; 00136 00137 00138 public: 00139 00145 Controller(const SharedPtr< ControllerValue<T> >& src, 00146 const SharedPtr< ControllerValue<T> >& dest, const SharedPtr< ControllerFunction<T> >& func) 00147 : mSource(src), mDest(dest), mFunc(func) 00148 { 00149 mEnabled = true; 00150 } 00151 00154 virtual ~Controller() {} 00155 00156 00158 void setSource(const SharedPtr< ControllerValue<T> >& src) 00159 { 00160 mSource = src; 00161 } 00163 const SharedPtr< ControllerValue<T> >& getSource(void) const 00164 { 00165 return mSource; 00166 } 00168 void setDestination(const SharedPtr< ControllerValue<T> >& dest) 00169 { 00170 mDest = dest; 00171 } 00172 00174 const SharedPtr< ControllerValue<T> >& getDestination(void) const 00175 { 00176 return mDest; 00177 } 00178 00180 bool getEnabled(void) const 00181 { 00182 return mEnabled; 00183 } 00184 00186 void setEnabled(bool enabled) 00187 { 00188 mEnabled = enabled; 00189 } 00190 00193 void setFunction(const SharedPtr< ControllerFunction<T> >& func) 00194 { 00195 mFunc = func; 00196 } 00197 00200 const SharedPtr< ControllerFunction<T> >& getFunction(void) const 00201 { 00202 return mFunc; 00203 } 00204 00210 void update(void) 00211 { 00212 if(mEnabled) 00213 mDest->setValue(mFunc->calculate(mSource->getValue())); 00214 } 00215 00216 }; 00217 00218 00219 } 00220 00221 #endif
Copyright © 2000-2005 by The OGRE Team
Last modified Sun Nov 20 12:35:57 2005