ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
QuaternionKalmanFilter.cpp
Go to the documentation of this file.
2
9
11 this->gain = gain;
12 this->memory = memory;
13
15}
16
20
22 for (int i = 0; i < memory; i++) {
23 arr[i] = arr[i + 1];
24 }
25
26 arr[memory - 1] = Quaternion();
27
28 return arr;
29}
30
32 if (currentAmount < memory) {
33 values[currentAmount++] = value;
34 } else {
35 values = ShiftArray(values); // pop first
36 values[memory - 1] = value;
37 }
38
39 Quaternion out = Quaternion(0, 0, 0, 0);
40
41 for (int i = 0; i < currentAmount; i++) {
42 out = out.Add(values[i].Divide(currentAmount));
43 }
44
45 out = out.UnitQuaternion();
46
47 return Quaternion::SphericalInterpolation(value, out, 1 - gain);
48}
Implements a Kalman filter for smoothing quaternion data.
int memory
The size of the internal buffer to store quaternion history.
Quaternion * ShiftArray(Quaternion arr[])
Shifts the array to remove the oldest quaternion and make room for a new one.
QuaternionKalmanFilter()
Default constructor for QuaternionKalmanFilter.
Quaternion Filter(Quaternion value)
Filters a quaternion value to reduce noise.
int currentAmount
Tracks the current number of quaternions stored in memory.
float gain
The filter gain, controls the weight of new data versus the estimated state.
Quaternion * values
Pointer to an array of quaternion values for the filter's memory.
~QuaternionKalmanFilter()
Destructor for QuaternionKalmanFilter.
A mathematical construct representing a rotation in 3D space.
Definition Quaternion.h:30
static Quaternion SphericalInterpolation(const Quaternion &q1, const Quaternion &q2, const float &ratio)
Performs spherical linear interpolation (slerp) between two quaternions.
Quaternion UnitQuaternion() const
Returns a unit quaternion (normalized) version of this quaternion.
Quaternion Add(const Quaternion &quaternion) const
Adds two quaternions component-wise.