1#ifndef Math_PQUATFEEDBACKLOOP_H
2#define Math_PQUATFEEDBACKLOOP_H
14#include "math/quaternion.h"
29 void Reset(
Time time,
float stepSize,
float gain,
const quaternion& curState);
31 void SetGain(
float g);
33 float GetGain()
const;
35 void SetGoal(
const quaternion& c);
37 const quaternion& GetGoal()
const;
39 void SetState(
const quaternion& s);
41 const quaternion& GetState()
const;
57PQuatFeedbackLoop::PQuatFeedbackLoop() :
70PQuatFeedbackLoop::Reset(
Time t,
float s,
float g,
const quaternion& curState)
75 this->
state = curState;
83PQuatFeedbackLoop::SetGain(
float g)
94PQuatFeedbackLoop::GetGain()
const
104PQuatFeedbackLoop::SetGoal(
const quaternion& g)
114PQuatFeedbackLoop::GetGoal()
const
124PQuatFeedbackLoop::SetState(
const quaternion& s)
134PQuatFeedbackLoop::GetState()
const
144PQuatFeedbackLoop::Update(
Time curTime)
146 Time dt = curTime - this->time;
151 this->time = curTime;
155 this->time = curTime;
158 while (this->time < curTime)
161 vector stateVec = this->
state.rotate(vector(0.0f, 0.0f, 1.0f));
162 vector goalVec = this->goal.rotate(vector(0.0f, 0.0f, 1.0f));
163 float dot = stateVec % goalVec;
167 float error = (-
dot + 1.0f) * 0.5f;
170 float lerp = error * this->gain * this->stepSize;
172 res.slerp(this->state, this->goal, lerp);
175 this->time += this->stepSize;
A specialized proportional feedback loop for rotations, using a quaternion representation.
#define n_assert(exp)
Definition debug.h:50
Different curves.
Definition angularpfeedbackloop.h:17
__forceinline scalar dot(const plane &p, const vec4 &v1)
Definition plane.h:246
__forceinline float lerp(float x, float y, float l)
Linearly interpolate between 2 values: ret = x + l * (y - x)
Definition scalar.h:597
@ Update
Definition resourceloader.h:53
struct StaticUI::@7 state
These are the standard time source objects provided by Application layer:
Definition calendartimebase.h:19
Typedefs for the Timing subsystem.