I am trying to interpolate between 4 points using a Hermite spline. However my spline seems to always start on the second point and only interpolate to the 3rd point. I have tried this with several differnt calculations and keep getting the same result.
Can anyone give me insight on this? Here is my code.
public ControlPoint Get(float t)
{
//speed multiplyer
//t = t * 10;
return new ControlPoint(
new Vector3(Hermite(points[0].pos.x, points[1].pos.x, points[2].pos.x, points[3].pos.x, t)
, Hermite(points[0].pos.y, points[1].pos.y, points[2].pos.y, points[3].pos.y, t)
, Hermite(points[0].pos.z, points[1].pos.z, points[2].pos.z, points[3].pos.z, t)
),
new Quaternion(Hermite(points[0].rot.x, points[1].rot.x, points[2].rot.x, points[3].rot.x, t)
, Hermite(points[0].rot.y, points[1].rot.y, points[2].rot.y, points[3].rot.y, t)
, Hermite(points[0].rot.z, points[1].rot.z, points[2].rot.z, points[3].rot.z, t)
, Hermite(points[0].rot.w, points[1].rot.w, points[2].rot.w, points[3].rot.w, t)
)
);
}
float Hermite(
float y0, float y1,
float y2, float y3,
float mu,
float tension = 0,
float bias = 0)
{
float m0, m1, mu2, mu3;
float a0, a1, a2, a3;
mu2 = mu * mu;
mu3 = mu2 * mu;
m0 = (y1 - y0) * (1 + bias) * (1 - tension) / 2;
m0 += (y2 - y1) * (1 - bias) * (1 - tension) / 2;
m1 = (y2 - y1) * (1 + bias) * (1 - tension) / 2;
m1 += (y3 - y2) * (1 - bias) * (1 - tension) / 2;
a0 = 2 * mu3 - 3 * mu2 + 1;
a1 = mu3 - 2 * mu2 + mu;
a2 = mu3 - mu2;
a3 = -2 * mu3 + 3 * mu2;
return (a0 * y1 + a1 * m0 + a2 * m1 + a3 * y2);
}