Fix cubic glTF animation
This commit is contained in:
parent
063e8e43ba
commit
fcd86fb359
1 changed files with 17 additions and 2 deletions
|
|
@ -30,6 +30,11 @@ namespace psemek::gfx
|
||||||
{
|
{
|
||||||
return geom::lerp(v1, v2, t);
|
return geom::lerp(v1, v2, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static output_type normalize(output_type const & v)
|
||||||
|
{
|
||||||
|
return v;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|
@ -46,6 +51,11 @@ namespace psemek::gfx
|
||||||
{
|
{
|
||||||
return geom::slerp(v1, v2, t);
|
return geom::slerp(v1, v2, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static output_type normalize(output_type const & v)
|
||||||
|
{
|
||||||
|
return geom::normalized(v);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|
@ -62,6 +72,11 @@ namespace psemek::gfx
|
||||||
{
|
{
|
||||||
return geom::lerp(v1, v2, t);
|
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
|
// see https://github.khronos.org/glTF-Tutorials/gltfTutorial/gltfTutorial_007_Animations.html#cubic-spline-interpolation
|
||||||
float t2 = t * t;
|
float t2 = t * t;
|
||||||
float t3 = t * t2;
|
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) + 1] * ( 2.f * t3 - 3.f * t2 + 1.f)
|
||||||
+ output_[3 * (i - 1) + 2] * ( t3 - 2.f * t2 + t )
|
+ 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) + 1] * (- 2.f * t3 + 3.f * t2 )
|
||||||
+ output_[3 * (i + 0) + 0] * ( t3 - t2 )
|
+ output_[3 * (i + 0) + 0] * ( t3 - t2 )
|
||||||
;
|
);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("unsupported glTF animation interpolation type");
|
throw std::runtime_error("unsupported glTF animation interpolation type");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue