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

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Oct 16 2013 14:35:42