18 #ifndef __H__OCULAR_ENGINE_MATH_INTERPOLATION__H__
19 #define __H__OCULAR_ENGINE_MATH_INTERPOLATION__H__
21 #include "Definitions.hpp"
51 static float InterpolateLinear(
float const from,
float const to,
float const frac)
53 float boundFrac = (frac < 0.0f) ? 0.0f : (frac > 1.0f) ? 1.0f : frac;
55 return (from * (1.0f - boundFrac)) + (to * boundFrac);
71 static float InterpolateCosine(
float const from,
float const to,
float const frac)
73 float boundFrac = (frac < 0.0f) ? 0.0f : (frac > 1.0f) ? 1.0f : frac;
74 float x = (1.0f - cosf(boundFrac * static_cast<float>(PI))) * 0.5f;
76 return (from * (1.0f - x)) + (to * x);
93 static float InterpolateCubic(
float const before,
float const from,
float const to,
float const after,
float const frac)
95 float boundFrac = (frac < 0.0f) ? 0.0f : (frac > 1.0f) ? 1.0f : frac;
96 float frac2 = boundFrac * boundFrac;
97 float a0 = after - to - before + from;
98 float a1 = before - from - a0;
99 float a2 = to - before;
102 return (a0 * boundFrac * frac2) + (a2 * frac2) + (a2 * boundFrac) + a3;
115 static float InterpolateCatmullRom(
float const before,
float const from,
float const to,
float const after,
float const frac)
117 float boundFrac = (frac < 0.0f) ? 0.0f : (frac > 1.0f) ? 1.0f : frac;
118 float frac2 = boundFrac * boundFrac;
119 float a0 = (-0.5f * before) + (1.5f * from) - (1.5f * to) + (0.5f * after);
120 float a1 = before - (2.5f * from) + (2.0f * to) - (0.5f * after);
121 float a2 = (-0.5f * before) + (0.5f * to);
124 return (a0 * boundFrac * frac2) + (a2 * frac2) + (a2 * boundFrac) + a3;
149 static float InterpolateHermite(
float const before,
float const from,
float const to,
float const after,
150 float const frac,
float const tension = 0.0f,
float const bias = 0.0f)
152 float boundFrac = (frac < 0.0f) ? 0.0f : (frac > 1.0) ? 1.0f : frac;
153 float frac2 = boundFrac * boundFrac;
154 float frac3 = boundFrac * frac2;
155 float m0 = ((from - before) * (1.0f + bias) * (1.0f - tension) * 0.5f)
156 + ((to - from) * (1.0f - bias) * (1.0f - tension) * 0.5f);
157 float m1 = ((to - from) * (1.0f + bias) * (1.0f - tension) * 0.5f)
158 + ((after - to) * (1.0f - bias) * (1.0f - tension) * 0.5f);
159 float a0 = (2.0f * frac3) - (3.0f * frac2) + 1.0f;
160 float a1 = frac3 - (2.0f * frac2) + boundFrac;
161 float a2 = frac3 - frac2;
162 float a3 = (-2.0f * frac3) + (3.0f * frac2);
164 return (a0 * from) + (a1 * m0) + (a2 * m1) + (a3 * to);
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70