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

OgreController.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 © 2000-2002 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 _OgreExport 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 
00065                 return mDeltaCount;
00066             }
00067             else
00068             {
00069                 return input;
00070             }
00071         }
00072 
00073     public:
00079         ControllerFunction(bool deltaInput)
00080         {
00081             mDeltaInput = deltaInput;
00082             mDeltaCount = 0;
00083         }
00084 
00085         virtual T calculate(T sourceValue) = 0;
00086     };
00087 
00088 
00091     template <typename T>
00092     class _OgreExport ControllerValue
00093     {
00094 
00095     public:
00096         virtual T getValue(void) const = 0;
00097         virtual void setValue(T value) = 0;
00098 
00099     };
00100 
00121     template <typename T>
00122     class _OgreExport Controller
00123     {
00124     protected:
00126         SharedPtr< ControllerValue<T> > mSource;
00128         SharedPtr< ControllerValue<T> > mDest;
00130         SharedPtr< ControllerFunction<T> > mFunc;
00132         bool mEnabled;
00133 
00134 
00135     public:
00136 
00142         Controller(SharedPtr< ControllerValue<T> > src, 
00143             SharedPtr< ControllerValue<T> > dest, SharedPtr< ControllerFunction<T> > func)
00144             : mSource(src), mDest(dest), mFunc(func)
00145         {
00146             mEnabled = true;
00147         }
00148 
00151         virtual ~Controller() {}
00152 
00153 
00155         void setSource(SharedPtr< ControllerValue<T> > src)
00156         {
00157             mSource = src;
00158         }
00160         SharedPtr< ControllerValue<T> > getSource(void) const
00161         {
00162             return mSource;
00163         }
00165         void setDestination(SharedPtr< ControllerValue<T> > dest)
00166         {
00167             mDest = dest;
00168         }
00169 
00171         SharedPtr< ControllerValue<T> > getDestination(void) const
00172         {
00173             return mDest;
00174         }
00175 
00177         bool getEnabled(void) const
00178         {
00179             return mEnabled;
00180         }
00181 
00183         void setEnabled(bool enabled)
00184         {
00185             mEnabled = enabled;
00186         }
00187 
00190         void setFunction(SharedPtr< ControllerFunction<T> > func)
00191         {
00192             mFunc = func;
00193         }
00194 
00197         SharedPtr< ControllerFunction<T> > getFunction(void) const
00198         {
00199             return mFunc;
00200         }
00201 
00207         void update(void)
00208         {
00209             if(mEnabled)
00210                 mDest->setValue(mFunc->calculate(mSource->getValue()));
00211         }
00212 
00213     };
00214 
00215 
00216 }
00217 
00218 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:05 2004