You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2007-01-25
  5. // Updated : 2009-02-19
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/spline.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm{
  10. template <typename genType>
  11. GLM_FUNC_QUALIFIER genType catmullRom
  12. (
  13. genType const & v1,
  14. genType const & v2,
  15. genType const & v3,
  16. genType const & v4,
  17. typename genType::value_type const & s
  18. )
  19. {
  20. typename genType::value_type s1 = s;
  21. typename genType::value_type s2 = pow2(s);
  22. typename genType::value_type s3 = pow3(s);
  23. typename genType::value_type f1 = -s3 + typename genType::value_type(2) * s2 - s;
  24. typename genType::value_type f2 = typename genType::value_type(3) * s3 - typename genType::value_type(5) * s2 + typename genType::value_type(2);
  25. typename genType::value_type f3 = typename genType::value_type(-3) * s3 + typename genType::value_type(4) * s2 + s;
  26. typename genType::value_type f4 = s3 - s2;
  27. return (f1 * v1 + f2 * v2 + f3 * v3 + f4 * v4) / typename genType::value_type(2);
  28. }
  29. template <typename genType>
  30. GLM_FUNC_QUALIFIER genType hermite
  31. (
  32. genType const & v1,
  33. genType const & t1,
  34. genType const & v2,
  35. genType const & t2,
  36. typename genType::value_type const & s
  37. )
  38. {
  39. typename genType::value_type s1 = s;
  40. typename genType::value_type s2 = pow2(s);
  41. typename genType::value_type s3 = pow3(s);
  42. typename genType::value_type f1 = typename genType::value_type(2) * s3 - typename genType::value_type(3) * s2 + typename genType::value_type(1);
  43. typename genType::value_type f2 = typename genType::value_type(-2) * s3 + typename genType::value_type(3) * s2;
  44. typename genType::value_type f3 = s3 - typename genType::value_type(2) * s2 + s;
  45. typename genType::value_type f4 = s3 - s2;
  46. return f1 * v1 + f2 * v2 + f3 * t1 + f4 * t2;
  47. }
  48. template <typename genType>
  49. GLM_FUNC_QUALIFIER genType cubic
  50. (
  51. genType const & v1,
  52. genType const & v2,
  53. genType const & v3,
  54. genType const & v4,
  55. typename genType::value_type const & s
  56. )
  57. {
  58. return ((v1 * s + v2) * s + v3) * s + v4;
  59. }
  60. }//namespace glm