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 ~ControllerValue() { }
    00097         virtual T getValue(void) const = 0;
    00098         virtual void setValue(T value) = 0;
    00099
    00100     };
    00101
    00122     template <typename T>
    00123     class _OgreExport Controller
    00124     {
    00125     protected:
    00127         SharedPtr< ControllerValue<T> > mSource;
    00129         SharedPtr< ControllerValue<T> > mDest;
    00131         SharedPtr< ControllerFunction<T> > mFunc;
    00133         bool mEnabled;
    00134
    00135
    00136     public:
    00137
    00143         Controller(SharedPtr< ControllerValue<T> > src,
    00144             SharedPtr< ControllerValue<T> > dest, SharedPtr< ControllerFunction<T> > func)
    00145             : mSource(src), mDest(dest), mFunc(func)
    00146         {
    00147             mEnabled = true;
    00148         }
    00149
    00152         virtual ~Controller() {}
    00153
    00154
    00156         void setSource(SharedPtr< ControllerValue<T> > src)
    00157         {
    00158             mSource = src;
    00159         }
    00161         SharedPtr< ControllerValue<T> > getSource(void) const
    00162         {
    00163             return mSource;
    00164         }
    00166         void setDestination(SharedPtr< ControllerValue<T> > dest)
    00167         {
    00168             mDest = dest;
    00169         }
    00170
    00172         SharedPtr< ControllerValue<T> > getDestination(void) const
    00173         {
    00174             return mDest;
    00175         }
    00176
    00178         bool getEnabled(void) const
    00179         {
    00180             return mEnabled;
    00181         }
    00182
    00184         void setEnabled(bool enabled)
    00185         {
    00186             mEnabled = enabled;
    00187         }
    00188
    00191         void setFunction(SharedPtr< ControllerFunction<T> > func)
    00192         {
    00193             mFunc = func;
    00194         }
    00195
    00198         SharedPtr< ControllerFunction<T> > getFunction(void) const
    00199         {
    00200             return mFunc;
    00201         }
    00202
    00208         void update(void)
    00209         {
    00210             if(mEnabled)
    00211                 mDest->setValue(mFunc->calculate(mSource->getValue()));
    00212         }
    00213
    00214     };
    00215
    00216
    00217 }
    00218
    00219 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:18 2004