7 #ifndef LIBALMATH_ALMATH_SCENEGRAPH_QIANIM_BEZIERAUTOTANGENT_H
8 #define LIBALMATH_ALMATH_SCENEGRAPH_QIANIM_BEZIERAUTOTANGENT_H
10 #include <almath/api.h>
14 #include <type_traits>
32 template <
typename Scalar,
33 typename std::enable_if<std::is_floating_point<Scalar>::value,
int>::type = 0 >
34 std::pair<std::pair<Scalar, Scalar>, std::pair<Scalar, Scalar>>
36 Scalar pDeltaAngle1, Scalar pDeltaAngle2) {
37 assert(pDeltaTime1 > -1e-5f);
38 assert(pDeltaTime2 > -1e-5f);
40 const auto alpha = Scalar(1) / 3;
41 auto beta = Scalar(0);
43 if (pDeltaAngle1 * pDeltaAngle2 > 0) {
45 assert(pDeltaTime1 + pDeltaTime2 > 0);
46 beta = (pDeltaAngle1 + pDeltaAngle2) / (pDeltaTime1 + pDeltaTime2);
49 auto tgtHeight = std::abs(alpha * pDeltaTime2 * beta);
50 auto absDeltaAngle = std::abs(pDeltaAngle2);
51 if (tgtHeight > absDeltaAngle) {
52 beta *= absDeltaAngle / tgtHeight;
54 tgtHeight = std::abs(alpha * pDeltaTime1 * beta);
55 absDeltaAngle = std::abs(pDeltaAngle1);
56 if (tgtHeight > absDeltaAngle) {
57 beta *= absDeltaAngle / tgtHeight;
60 return std::make_pair(std::make_pair(-alpha * pDeltaTime1,
61 -alpha * beta * pDeltaTime1),
62 std::make_pair(alpha * pDeltaTime2,
63 alpha * beta * pDeltaTime2));
std::pair< std::pair< Scalar, Scalar >, std::pair< Scalar, Scalar > > computeBezierAutoTangents(Scalar pDeltaTime1, Scalar pDeltaTime2, Scalar pDeltaAngle1, Scalar pDeltaAngle2)