spline.inl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /// @ref gtx_spline
  2. namespace glm
  3. {
  4. template<typename genType>
  5. GLM_FUNC_QUALIFIER genType catmullRom
  6. (
  7. genType const& v1,
  8. genType const& v2,
  9. genType const& v3,
  10. genType const& v4,
  11. typename genType::value_type const& s
  12. )
  13. {
  14. typename genType::value_type s2 = pow2(s);
  15. typename genType::value_type s3 = pow3(s);
  16. typename genType::value_type f1 = -s3 + typename genType::value_type(2) * s2 - s;
  17. typename genType::value_type f2 = typename genType::value_type(3) * s3 - typename genType::value_type(5) * s2 + typename genType::value_type(2);
  18. typename genType::value_type f3 = typename genType::value_type(-3) * s3 + typename genType::value_type(4) * s2 + s;
  19. typename genType::value_type f4 = s3 - s2;
  20. return (f1 * v1 + f2 * v2 + f3 * v3 + f4 * v4) / typename genType::value_type(2);
  21. }
  22. template<typename genType>
  23. GLM_FUNC_QUALIFIER genType hermite
  24. (
  25. genType const& v1,
  26. genType const& t1,
  27. genType const& v2,
  28. genType const& t2,
  29. typename genType::value_type const& s
  30. )
  31. {
  32. typename genType::value_type s2 = pow2(s);
  33. typename genType::value_type s3 = pow3(s);
  34. typename genType::value_type f1 = typename genType::value_type(2) * s3 - typename genType::value_type(3) * s2 + typename genType::value_type(1);
  35. typename genType::value_type f2 = typename genType::value_type(-2) * s3 + typename genType::value_type(3) * s2;
  36. typename genType::value_type f3 = s3 - typename genType::value_type(2) * s2 + s;
  37. typename genType::value_type f4 = s3 - s2;
  38. return f1 * v1 + f2 * v2 + f3 * t1 + f4 * t2;
  39. }
  40. template<typename genType>
  41. GLM_FUNC_QUALIFIER genType cubic
  42. (
  43. genType const& v1,
  44. genType const& v2,
  45. genType const& v3,
  46. genType const& v4,
  47. typename genType::value_type const& s
  48. )
  49. {
  50. return ((v1 * s + v2) * s + v3) * s + v4;
  51. }
  52. }//namespace glm