4#include "Interpolation.hpp"
6#include "../Platform/Timer.h"
9#include <glm/ext/quaternion_float.hpp>
10#include <glm/ext/quaternion_common.hpp>
11#include <glm/gtx/norm.hpp>
14 template<
typename T>
inline bool tooCloseFn(
const T& s,
const T& d) {
15 return glm::distance2(s, d) < 0.000001;
18 template<>
inline bool tooCloseFn<glm::quat>(
const glm::quat& s,
const glm::quat& d) {
19 return std::abs(glm::dot(s, d)) > 0.9999;
22 template<
typename T>
inline T interpolateFn(
const T& s,
const T& d,
float t) {
23 return Interpolation::linear(s, d, t);
26 template<>
inline glm::quat interpolateFn<glm::quat>(
const glm::quat& s,
const glm::quat& d,
float t) {
27 return glm::slerp(s, d, t);
32 Interpolator(T& destination) : mDestination(destination), mTarget(destination) {
36 setTarget(target, fn, duration);
39 void setTarget(
const T& target, EasingFn::Ptr fn,
float duration) {
40 if (fn && (duration > 0.0f) && !tooCloseFn(mDestination, target)) {
41 mStart = mDestination;
48 mDestination = target;
56 mDestination = mTarget;
63 float t =
static_cast<float>(mTimer.elapsedSeconds()) / mDuration;
66 mDestination = interpolateFn(mStart, mTarget, mFunction(t));
69 mDestination = mTarget;
77 void cancel() { mFunction =
nullptr; }
78 bool isProcessing()
const {
return mFunction; }
80 float getTime() {
return isProcessing() ?
static_cast<float>(mTimer.elapsedSeconds()) : 1.0f; }
81 T getTarget()
const {
return mTarget; }
82 T getValue()
const {
return mDestination; }
89 EasingFn::Ptr mFunction =
nullptr;
90 float mDuration = 0.0f;
High-resolution performance timer.
Contains all Cogs related functionality.