#include <C:/Work/specialnumbers_svn/NumberLib/NumbersLib/DifferentiableNumber.h>
These are calculated every time the number's value is set.
The maximum order of differentiation that will be required is set as one of the template parameters. The intitial value with which the DifferentiableNumber is initialised is returned for any differential requested that was not computed for this differentiable number.
For example:
DifferentiableNumber<3, float> n(0); ... //set the value a few times ... float m = n.getValue(4); //m is 0
This class is to be used in simulations. For example, if position was declared as follows:
Differentiable<2, Vector2> position (Vector2(0, 0));
and the position is updated every frame, then
position.getValue(0)
position.getValue(1)
position.getValue(2)
The advantage of using this class instead of the usual logic is that it saves a lot of code, and related updates are done in one place. Of course there is some overhead involved.
Definition at line 57 of file DifferentiableNumber.h.
Public Member Functions | |
DifferentiableNumber (T initialValue) | |
Constructs a new DifferentiableNumber with the initialValue. | |
void | forceValue (T value) |
Force this number to the given value. | |
T | getValue (unsigned int order=1) const |
Gets the value of the mth derivative of this DifferentiableNumber. | |
void | setValue (T value, float elapsedTime=1.0f) |
Sets the value for this DifferentiableNumber. | |
Private Attributes | |
DifferentiableNumber< T, maxOrder-1 > | mDifference |
The difference between the current and previous values is maintained as a DifferentiableNumber<n - 1, T>. | |
T | mInitialValue |
T | mPreviousValue |
T | mValue |
DifferentiableNumber | ( | T | initialValue | ) | [inline] |
Constructs a new DifferentiableNumber with the initialValue.
Note that this should be a form of 0. If T is a Vector2 type, the initialValue should be (0, 0).
Definition at line 126 of file DifferentiableNumber.h.
void forceValue | ( | T | value | ) | [inline] |
Force this number to the given value.
Internal derivative are forced to 0.
Definition at line 117 of file DifferentiableNumber.h.
References DifferentiableNumber::mDifference, DifferentiableNumber::mInitialValue, DifferentiableNumber::mPreviousValue, and DifferentiableNumber::mValue.
Referenced by PIDBufferedNumber::forceValue().
T getValue | ( | unsigned int | order = 1 |
) | const [inline, virtual] |
Gets the value of the mth derivative of this DifferentiableNumber.
m | The order of the derivative for this DifferentiableNumber to get the value of. If m == 0, the current value is returned. |
Implements AbstractFilteredNumber< T, 2, maxOrder >.
Definition at line 135 of file DifferentiableNumber.h.
References DifferentiableNumber::mDifference, DifferentiableNumber::mInitialValue, and DifferentiableNumber::mValue.
Referenced by PIDBufferedNumber::getValue().
void setValue | ( | T | value, | |
float | elapsedTime = 1.0f | |||
) | [inline, virtual] |
Sets the value for this DifferentiableNumber.
elapsedTime | The amount of thime passed since the last update. |
Implements UpdateableNumber.
Definition at line 108 of file DifferentiableNumber.h.
References luma::numbers::frameRate, DifferentiableNumber::mDifference, DifferentiableNumber::mPreviousValue, and DifferentiableNumber::mValue.
Referenced by PIDBufferedNumber::setValue().
DifferentiableNumber<T, maxOrder - 1> mDifference [private] |
The difference between the current and previous values is maintained as a DifferentiableNumber<n - 1, T>.
It will keep track of its own derivatives.
Definition at line 69 of file DifferentiableNumber.h.
Referenced by DifferentiableNumber< T, 1 >::forceValue(), DifferentiableNumber::forceValue(), DifferentiableNumber< T, 1 >::getValue(), DifferentiableNumber::getValue(), DifferentiableNumber< T, 1 >::setValue(), and DifferentiableNumber::setValue().
T mInitialValue [private] |
Definition at line 62 of file DifferentiableNumber.h.
Referenced by DifferentiableNumber< T, 1 >::forceValue(), DifferentiableNumber::forceValue(), DifferentiableNumber< T, 1 >::getValue(), and DifferentiableNumber::getValue().
T mPreviousValue [private] |
Definition at line 61 of file DifferentiableNumber.h.
Referenced by DifferentiableNumber< T, 1 >::forceValue(), DifferentiableNumber::forceValue(), DifferentiableNumber< T, 1 >::setValue(), and DifferentiableNumber::setValue().
T mValue [private] |
Definition at line 60 of file DifferentiableNumber.h.
Referenced by DifferentiableNumber< T, 1 >::forceValue(), DifferentiableNumber::forceValue(), DifferentiableNumber< T, 1 >::getValue(), DifferentiableNumber::getValue(), DifferentiableNumber< T, 1 >::setValue(), and DifferentiableNumber::setValue().