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-2013 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
33#include "OgreSharedPtr.h"
34
35namespace Ogre {
36
54 template <typename T>
56 {
57 protected:
61
65 {
66 if (mDeltaInput)
67 {
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:
90 {
92 mDeltaCount = 0;
93 }
94
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:
146
147
148 public:
149
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
197 {
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
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.

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