OgreController.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Controller_H__
#define __Controller_H__
#include "OgrePrerequisites.h"
#include "OgreSharedPtr.h"
namespace Ogre {
template <typename T>
class ControllerFunction : public ControllerAlloc
{
protected:
bool mDeltaInput;
T mDeltaCount;
T getAdjustedInput(T input)
{
if (mDeltaInput)
{
mDeltaCount += input;
// Wrap
while (mDeltaCount >= 1.0)
mDeltaCount -= 1.0;
while (mDeltaCount < 0.0)
mDeltaCount += 1.0;
return mDeltaCount;
}
else
{
return input;
}
}
public:
ControllerFunction(bool deltaInput)
{
mDeltaInput = deltaInput;
mDeltaCount = 0;
}
virtual ~ControllerFunction() {}
virtual T calculate(T sourceValue) = 0;
};
template <typename T>
class ControllerValue : public ControllerAlloc
{
public:
virtual ~ControllerValue() { }
virtual T getValue(void) const = 0;
virtual void setValue(T value) = 0;
};
template <typename T>
class Controller : public ControllerAlloc
{
protected:
SharedPtr< ControllerValue<T> > mSource;
SharedPtr< ControllerValue<T> > mDest;
SharedPtr< ControllerFunction<T> > mFunc;
bool mEnabled;
public:
Controller(const SharedPtr< ControllerValue<T> >& src,
const SharedPtr< ControllerValue<T> >& dest, const SharedPtr< ControllerFunction<T> >& func)
: mSource(src), mDest(dest), mFunc(func)
{
mEnabled = true;
}
virtual ~Controller() {}
void setSource(const SharedPtr< ControllerValue<T> >& src)
{
mSource = src;
}
const SharedPtr< ControllerValue<T> >& getSource(void) const
{
return mSource;
}
void setDestination(const SharedPtr< ControllerValue<T> >& dest)
{
mDest = dest;
}
const SharedPtr< ControllerValue<T> >& getDestination(void) const
{
return mDest;
}
bool getEnabled(void) const
{
return mEnabled;
}
void setEnabled(bool enabled)
{
mEnabled = enabled;
}
void setFunction(const SharedPtr< ControllerFunction<T> >& func)
{
mFunc = func;
}
const SharedPtr< ControllerFunction<T> >& getFunction(void) const
{
return mFunc;
}
void update(void)
{
if(mEnabled)
mDest->setValue(mFunc->calculate(mSource->getValue()));
}
};
}
#endif
Ogre::Controller::~Controller
virtual ~Controller()
Default d-tor.
Definition: OgreController.h:164
Ogre::Controller::mFunc
SharedPtr< ControllerFunction< T > > mFunc
Function.
Definition: OgreController.h:143
Ogre::ControllerFunction::mDeltaCount
T mDeltaCount
Definition: OgreController.h:60
OgreSharedPtr.h
Ogre::ControllerFunction
Subclasses of this class are responsible for performing a function on an input value for a Controller...
Definition: OgreController.h:55
Ogre::Controller::mEnabled
bool mEnabled
Controller is enabled or not.
Definition: OgreController.h:145
Ogre::ControllerValue
Can either be used as an input or output value.
Definition: OgreController.h:104
Ogre::Controller::setSource
void setSource(const SharedPtr< ControllerValue< T > > &src)
Sets the input controller value.
Definition: OgreController.h:168
Ogre::Controller
Instances of this class &#39;control&#39; the value of another object in the system.
Definition: OgreController.h:135
Ogre::Controller::update
void update(void)
Tells this controller to map it&#39;s input controller value to it&#39;s output controller value...
Definition: OgreController.h:220
OgrePrerequisites.h
Ogre::Controller::getEnabled
bool getEnabled(void) const
Returns true if this controller is currently enabled.
Definition: OgreController.h:190
Ogre::Controller::getFunction
const SharedPtr< ControllerFunction< T > > & getFunction(void) const
Returns a pointer to the function object used by this controller.
Definition: OgreController.h:210
Ogre::ControllerFunction::mDeltaInput
bool mDeltaInput
If true, function will add input values together and wrap at 1.0 before evaluating.
Definition: OgreController.h:59
Ogre::Controller::mDest
SharedPtr< ControllerValue< T > > mDest
Destination value.
Definition: OgreController.h:141
Ogre::Controller::setDestination
void setDestination(const SharedPtr< ControllerValue< T > > &dest)
Sets the output controller value.
Definition: OgreController.h:178
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::ControllerFunction::getAdjustedInput
T getAdjustedInput(T input)
Gets the input value as adjusted by any delta.
Definition: OgreController.h:64
Ogre::SharedPtr
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgrePrerequisites.h:310
Ogre::Controller::getDestination
const SharedPtr< ControllerValue< T > > & getDestination(void) const
Gets the output controller value.
Definition: OgreController.h:184
Ogre::ControllerFunction::calculate
virtual T calculate(T sourceValue)=0
Ogre::Controller::Controller
Controller(const SharedPtr< ControllerValue< T > > &src, const SharedPtr< ControllerValue< T > > &dest, const SharedPtr< ControllerFunction< T > > &func)
Usual constructor.
Definition: OgreController.h:155
Ogre::Controller::setFunction
void setFunction(const SharedPtr< ControllerFunction< T > > &func)
Sets the function object to be used by this controller.
Definition: OgreController.h:203
Ogre::ControllerValue::~ControllerValue
virtual ~ControllerValue()
Definition: OgreController.h:108
Ogre::Controller::setEnabled
void setEnabled(bool enabled)
Sets whether this controller is enabled.
Definition: OgreController.h:196
Ogre::Controller::getSource
const SharedPtr< ControllerValue< T > > & getSource(void) const
Gets the input controller value.
Definition: OgreController.h:173
Ogre::ControllerFunction::ControllerFunction
ControllerFunction(bool deltaInput)
Constructor.
Definition: OgreController.h:89
Ogre::ControllerFunction::~ControllerFunction
virtual ~ControllerFunction()
Definition: OgreController.h:95
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::Controller::mSource
SharedPtr< ControllerValue< T > > mSource
Source value.
Definition: OgreController.h:139

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