OGRE  1.9.0
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-2014 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 #include "OgreMath.h"
33 
34 #include "OgreSharedPtr.h"
35 
36 namespace Ogre {
37 
55  template <typename T>
57  {
58  protected:
62 
65  T getAdjustedInput(T input)
66  {
67  if (mDeltaInput)
68  {
69  mDeltaCount += input;
70  // Wrap
71  while (mDeltaCount >= 1.0)
72  mDeltaCount -= 1.0;
73  while (mDeltaCount < 0.0)
74  mDeltaCount += 1.0;
75 
76  return mDeltaCount;
77  }
78  else
79  {
80  return input;
81  }
82  }
83 
84  public:
90  ControllerFunction(bool deltaInput)
91  {
92  mDeltaInput = deltaInput;
93  mDeltaCount = 0;
94  }
95 
96  virtual ~ControllerFunction() {}
97 
98  virtual T calculate(T sourceValue) = 0;
99  };
100 
101 
104  template <typename T>
106  {
107 
108  public:
109  virtual ~ControllerValue() { }
110  virtual T getValue(void) const = 0;
111  virtual void setValue(T value) = 0;
112 
113  };
114 
135  template <typename T>
137  {
138  protected:
146  bool mEnabled;
147 
148 
149  public:
150 
157  const SharedPtr< ControllerValue<T> >& dest, const SharedPtr< ControllerFunction<T> >& func)
158  : mSource(src), mDest(dest), mFunc(func)
159  {
160  mEnabled = true;
161  }
162 
165  virtual ~Controller() {}
166 
167 
170  {
171  mSource = src;
172  }
175  {
176  return mSource;
177  }
180  {
181  mDest = dest;
182  }
183 
186  {
187  return mDest;
188  }
189 
191  bool getEnabled(void) const
192  {
193  return mEnabled;
194  }
195 
197  void setEnabled(bool enabled)
198  {
199  mEnabled = enabled;
200  }
201 
205  {
206  mFunc = func;
207  }
208 
212  {
213  return mFunc;
214  }
215 
221  void update(void)
222  {
223  if(mEnabled)
224  mDest->setValue(mFunc->calculate(mSource->getValue()));
225  }
226 
227  };
228 
232 }
233 
234 #endif
virtual ~Controller()
Default d-tor.
SharedPtr< ControllerFunction< T > > mFunc
Function.
virtual void setValue(T value)=0
Subclasses of this class are responsible for performing a function on an input value for a Controller...
bool mEnabled
Controller is enabled or not.
Can either be used as an input or output value.
void setSource(const SharedPtr< ControllerValue< T > > &src)
Sets the input controller value.
Instances of this class 'control' the value of another object in the system.
void update(void)
Tells this controller to map it's input controller value to it's output controller value,...
bool getEnabled(void) const
Returns true if this controller is currently enabled.
const SharedPtr< ControllerFunction< T > > & getFunction(void) const
Returns a pointer to the function object used by this controller.
bool mDeltaInput
If true, function will add input values together and wrap at 1.0 before evaluating.
SharedPtr< ControllerValue< T > > mDest
Destination value.
void setDestination(const SharedPtr< ControllerValue< T > > &dest)
Sets the output controller value.
T getAdjustedInput(T input)
Gets the input value as adjusted by any delta.
Reference-counted shared pointer, used for objects where implicit destruction is required.
const SharedPtr< ControllerValue< T > > & getDestination(void) const
Gets the output controller value.
virtual T calculate(T sourceValue)=0
Controller(const SharedPtr< ControllerValue< T > > &src, const SharedPtr< ControllerValue< T > > &dest, const SharedPtr< ControllerFunction< T > > &func)
Usual constructor.
void setFunction(const SharedPtr< ControllerFunction< T > > &func)
Sets the function object to be used by this controller.
void setEnabled(bool enabled)
Sets whether this controller is enabled.
const SharedPtr< ControllerValue< T > > & getSource(void) const
Gets the input controller value.
virtual T getValue(void) const =0
ControllerFunction(bool deltaInput)
Constructor.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
SharedPtr< ControllerValue< T > > mSource
Source value.