OgreController.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Controller_H__
29 #define __Controller_H__
30 
31 #include "OgrePrerequisites.h"
32 
33 #include "OgreSharedPtr.h"
34 
35 namespace Ogre {
36 
54  template <typename T>
56  {
57  protected:
61 
64  T getAdjustedInput(T input)
65  {
66  if (mDeltaInput)
67  {
68  mDeltaCount += input;
69  // Wrap
70  while (mDeltaCount >= 1.0)
71  mDeltaCount -= 1.0;
72  while (mDeltaCount < 0.0)
73  mDeltaCount += 1.0;
74 
75  return mDeltaCount;
76  }
77  else
78  {
79  return input;
80  }
81  }
82 
83  public:
89  ControllerFunction(bool deltaInput)
90  {
91  mDeltaInput = deltaInput;
92  mDeltaCount = 0;
93  }
94 
95  virtual ~ControllerFunction() {}
96 
97  virtual T calculate(T sourceValue) = 0;
98  };
99 
100 
103  template <typename T>
105  {
106 
107  public:
108  virtual ~ControllerValue() { }
109  virtual T getValue(void) const = 0;
110  virtual void setValue(T value) = 0;
111 
112  };
113 
134  template <typename T>
136  {
137  protected:
145  bool mEnabled;
146 
147 
148  public:
149 
156  const SharedPtr< ControllerValue<T> >& dest, const SharedPtr< ControllerFunction<T> >& func)
157  : mSource(src), mDest(dest), mFunc(func)
158  {
159  mEnabled = true;
160  }
161 
164  virtual ~Controller() {}
165 
166 
169  {
170  mSource = src;
171  }
174  {
175  return mSource;
176  }
179  {
180  mDest = dest;
181  }
182 
185  {
186  return mDest;
187  }
188 
190  bool getEnabled(void) const
191  {
192  return mEnabled;
193  }
194 
196  void setEnabled(bool enabled)
197  {
198  mEnabled = enabled;
199  }
200 
204  {
205  mFunc = func;
206  }
207 
211  {
212  return mFunc;
213  }
214 
220  void update(void)
221  {
222  if(mEnabled)
223  mDest->setValue(mFunc->calculate(mSource->getValue()));
224  }
225 
226  };
227 
231 }
232 
233 #endif
OgreSharedPtr.h
Ogre::ControllerValue
Can either be used as an input or output value.
Definition: OgreController.h:105
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:59
Ogre
Definition: OgreAndroidLogListener.h:35
Ogre::ControllerValue::~ControllerValue
virtual ~ControllerValue()
Definition: OgreController.h:108
Ogre::ControllerFunction::~ControllerFunction
virtual ~ControllerFunction()
Definition: OgreController.h:95
Ogre::Controller::getFunction
const SharedPtr< ControllerFunction< T > > & getFunction(void) const
Returns a pointer to the function object used by this controller.
Definition: OgreController.h:210
Ogre::Controller::mFunc
SharedPtr< ControllerFunction< T > > mFunc
Function.
Definition: OgreController.h:143
Ogre::ControllerFunction::mDeltaInput
bool mDeltaInput
If true, function will add input values together and wrap at 1.0 before evaluating.
Definition: OgreController.h:59
Ogre::Controller::mSource
SharedPtr< ControllerValue< T > > mSource
Source value.
Definition: OgreController.h:139
Ogre::ControllerValue::setValue
virtual void setValue(T value)=0
Ogre::Controller::update
void update(void)
Tells this controller to map it's input controller value to it's output controller value,...
Definition: OgreController.h:220
Ogre::Controller::setDestination
void setDestination(const SharedPtr< ControllerValue< T > > &dest)
Sets the output controller value.
Definition: OgreController.h:178
Ogre::Controller::mEnabled
bool mEnabled
Controller is enabled or not.
Definition: OgreController.h:145
Ogre::Controller::getDestination
const SharedPtr< ControllerValue< T > > & getDestination(void) const
Gets the output controller value.
Definition: OgreController.h:184
Ogre::Controller::setEnabled
void setEnabled(bool enabled)
Sets whether this controller is enabled.
Definition: OgreController.h:196
Ogre::Controller::getSource
const SharedPtr< ControllerValue< T > > & getSource(void) const
Gets the input controller value.
Definition: OgreController.h:173
Ogre::Controller::~Controller
virtual ~Controller()
Default d-tor.
Definition: OgreController.h:164
Ogre::Controller
Instances of this class 'control' the value of another object in the system.
Definition: OgreController.h:136
Ogre::Controller::setSource
void setSource(const SharedPtr< ControllerValue< T > > &src)
Sets the input controller value.
Definition: OgreController.h:168
OgrePrerequisites.h
Ogre::Controller::Controller
Controller(const SharedPtr< ControllerValue< T > > &src, const SharedPtr< ControllerValue< T > > &dest, const SharedPtr< ControllerFunction< T > > &func)
Usual constructor.
Definition: OgreController.h:155
Ogre::ControllerFunction::getAdjustedInput
T getAdjustedInput(T input)
Gets the input value as adjusted by any delta.
Definition: OgreController.h:64
Ogre::SharedPtr
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgreSharedPtr.h:112
Ogre::ControllerFunction
Subclasses of this class are responsible for performing a function on an input value for a Controller...
Definition: OgreController.h:56
Ogre::ControllerFunction::ControllerFunction
ControllerFunction(bool deltaInput)
Constructor.
Definition: OgreController.h:89
Ogre::Controller::mDest
SharedPtr< ControllerValue< T > > mDest
Destination value.
Definition: OgreController.h:141
Ogre::ControllerFunction::calculate
virtual T calculate(T sourceValue)=0
Ogre::ControllerValue::getValue
virtual T getValue(void) const =0
Ogre::ControllerFunction::mDeltaCount
T mDeltaCount
Definition: OgreController.h:60
Ogre::Controller::setFunction
void setFunction(const SharedPtr< ControllerFunction< T > > &func)
Sets the function object to be used by this controller.
Definition: OgreController.h:203
Ogre::Controller::getEnabled
bool getEnabled(void) const
Returns true if this controller is currently enabled.
Definition: OgreController.h:190

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.