OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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
void setEnabled(bool enabled)
Sets whether this controller is enabled.
virtual T calculate(T sourceValue)=0
SharedPtr< ControllerValue< T > > mSource
Source value.
SharedPtr< ControllerFunction< T > > mFunc
Function.
bool mDeltaInput
If true, function will add input values together and wrap at 1.0 before evaluating.
virtual ~Controller()
Default d-tor.
Controller(const SharedPtr< ControllerValue< T > > &src, const SharedPtr< ControllerValue< T > > &dest, const SharedPtr< ControllerFunction< T > > &func)
Usual constructor.
bool mEnabled
Controller is enabled or not.
const SharedPtr< ControllerFunction< T > > & getFunction(void) const
Returns a pointer to the function object used by this controller.
ControllerFunction(bool deltaInput)
Constructor.
void setFunction(const SharedPtr< ControllerFunction< T > > &func)
Sets the function object to be used by this controller.
void setDestination(const SharedPtr< ControllerValue< T > > &dest)
Sets the output controller value.
Can either be used as an input or output value.
void update(void)
Tells this controller to map it's input controller value to it's output controller value...
Instances of this class 'control' the value of another object in the system.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
virtual void setValue(T value)=0
void setSource(const SharedPtr< ControllerValue< T > > &src)
Sets the input controller value.
T getAdjustedInput(T input)
Gets the input value as adjusted by any delta.
bool getEnabled(void) const
Returns true if this controller is currently enabled.
virtual T getValue(void) const =0
const SharedPtr< ControllerValue< T > > & getDestination(void) const
Gets the output controller value.
Subclasses of this class are responsible for performing a function on an input value for a Controller...
Reference-counted shared pointer, used for objects where implicit destruction is required.
const SharedPtr< ControllerValue< T > > & getSource(void) const
Gets the input controller value.
SharedPtr< ControllerValue< T > > mDest
Destination value.