Fix cubic glTF animation

This commit is contained in:
Nikita Lisitsa 2023-03-27 11:32:21 +03:00
parent 063e8e43ba
commit fcd86fb359

View file

@ -30,6 +30,11 @@ namespace psemek::gfx
{
return geom::lerp(v1, v2, t);
}
static output_type normalize(output_type const & v)
{
return v;
}
};
template <>
@ -46,6 +51,11 @@ namespace psemek::gfx
{
return geom::slerp(v1, v2, t);
}
static output_type normalize(output_type const & v)
{
return geom::normalized(v);
}
};
template <>
@ -62,6 +72,11 @@ namespace psemek::gfx
{
return geom::lerp(v1, v2, t);
}
static output_type normalize(output_type const & v)
{
return v;
}
};
}
@ -116,12 +131,12 @@ namespace psemek::gfx
// see https://github.khronos.org/glTF-Tutorials/gltfTutorial/gltfTutorial_007_Animations.html#cubic-spline-interpolation
float t2 = t * t;
float t3 = t * t2;
return traits::default_value()
return traits::normalize(output_type::zero()
+ output_[3 * (i - 1) + 1] * ( 2.f * t3 - 3.f * t2 + 1.f)
+ output_[3 * (i - 1) + 2] * ( t3 - 2.f * t2 + t )
+ output_[3 * (i + 0) + 1] * (- 2.f * t3 + 3.f * t2 )
+ output_[3 * (i + 0) + 0] * ( t3 - t2 )
;
);
}
default:
throw std::runtime_error("unsupported glTF animation interpolation type");