4#include "Interpolation.hpp"
6#include "../Platform/Timer.h"
9#include <glm/ext/quaternion_float.hpp>
10#include <glm/ext/quaternion_common.hpp>
13 template<
typename T>
inline T interpolateFn(
const T& s,
const T& d,
float t) {
14 return Interpolation::linear(s, d, t);
17 template<>
inline glm::quat interpolateFn<glm::quat>(
const glm::quat& s,
const glm::quat& d,
float t) {
18 return glm::slerp(s, d, t);
23 Interpolator(T& destination) : mDestination(destination), mTarget(destination) {
27 setTarget(target, fn, duration);
30 void setTarget(
const T& target, EasingFn::Ptr fn,
float duration) {
31 if (fn && (duration > 0.0f)) {
32 mStart = mDestination;
39 mDestination = target;
47 mDestination = mTarget;
54 float t =
static_cast<float>(mTimer.elapsedSeconds()) / mDuration;
57 mDestination = interpolateFn(mStart, mTarget, mFunction(t));
60 mDestination = mTarget;
68 void cancel() { mFunction =
nullptr; }
69 bool isProcessing()
const {
return mFunction; }
71 float getTime() {
return isProcessing() ?
static_cast<float>(mTimer.elapsedSeconds()) : 1.0f; }
72 T getTarget()
const {
return mTarget; }
73 T getValue()
const {
return mDestination; }
80 EasingFn::Ptr mFunction =
nullptr;
81 float mDuration = 0.0f;
Contains all Cogs related functionality.