OGRE  1.9.0
OgreController.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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
36namespace Ogre {
37
55 template <typename T>
57 {
58 protected:
62
66 {
67 if (mDeltaInput)
68 {
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:
91 {
93 mDeltaCount = 0;
94 }
95
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:
147
148
149 public:
150
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
198 {
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
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Subclasses of this class are responsible for performing a function on an input value for a Controller...
virtual T calculate(T sourceValue)=0
bool mDeltaInput
If true, function will add input values together and wrap at 1.0 before evaluating.
T getAdjustedInput(T input)
Gets the input value as adjusted by any delta.
ControllerFunction(bool deltaInput)
Constructor.
Can either be used as an input or output value.
virtual T getValue(void) const =0
virtual void setValue(T value)=0
Instances of this class 'control' the value of another object in the system.
SharedPtr< ControllerFunction< T > > mFunc
Function.
Controller(const SharedPtr< ControllerValue< T > > &src, const SharedPtr< ControllerValue< T > > &dest, const SharedPtr< ControllerFunction< T > > &func)
Usual constructor.
void update(void)
Tells this controller to map it's input controller value to it's output controller value,...
SharedPtr< ControllerValue< T > > mSource
Source value.
void setSource(const SharedPtr< ControllerValue< T > > &src)
Sets the input controller value.
bool getEnabled(void) const
Returns true if this controller is currently enabled.
void setEnabled(bool enabled)
Sets whether this controller is enabled.
const SharedPtr< ControllerValue< T > > & getDestination(void) const
Gets the output controller value.
bool mEnabled
Controller is enabled or not.
virtual ~Controller()
Default d-tor.
const SharedPtr< ControllerValue< T > > & getSource(void) const
Gets the input controller value.
const SharedPtr< ControllerFunction< T > > & getFunction(void) const
Returns a pointer to the function object used by this controller.
void setDestination(const SharedPtr< ControllerValue< T > > &dest)
Sets the output controller value.
void setFunction(const SharedPtr< ControllerFunction< T > > &func)
Sets the function object to be used by this controller.
SharedPtr< ControllerValue< T > > mDest
Destination value.
Reference-counted shared pointer, used for objects where implicit destruction is required.