gtx_spline.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// Restrictions:
  16. /// By making use of the Software for military purposes, you choose to make
  17. /// a Bunny unhappy.
  18. ///
  19. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. /// THE SOFTWARE.
  26. ///
  27. /// @file test/gtx/gtx_spline.cpp
  28. /// @date 2013-10-25 / 2014-11-25
  29. /// @author Christophe Riccio
  30. ///////////////////////////////////////////////////////////////////////////////////
  31. #include <glm/vec2.hpp>
  32. #include <glm/vec3.hpp>
  33. #include <glm/vec4.hpp>
  34. #include <glm/gtx/spline.hpp>
  35. namespace catmullRom
  36. {
  37. int test()
  38. {
  39. int Error(0);
  40. glm::vec2 Result2 = glm::catmullRom(
  41. glm::vec2(0.0f, 0.0f),
  42. glm::vec2(1.0f, 0.0f),
  43. glm::vec2(1.0f, 1.0f),
  44. glm::vec2(0.0f, 1.0f), 0.5f);
  45. glm::vec3 Result3 = glm::catmullRom(
  46. glm::vec3(0.0f, 0.0f, 0.0f),
  47. glm::vec3(1.0f, 0.0f, 0.0f),
  48. glm::vec3(1.0f, 1.0f, 0.0f),
  49. glm::vec3(0.0f, 1.0f, 0.0f), 0.5f);
  50. glm::vec4 Result4 = glm::catmullRom(
  51. glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),
  52. glm::vec4(1.0f, 0.0f, 0.0f, 1.0f),
  53. glm::vec4(1.0f, 1.0f, 0.0f, 1.0f),
  54. glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), 0.5f);
  55. return Error;
  56. }
  57. }//catmullRom
  58. namespace hermite
  59. {
  60. int test()
  61. {
  62. int Error(0);
  63. glm::vec2 Result2 = glm::hermite(
  64. glm::vec2(0.0f, 0.0f),
  65. glm::vec2(1.0f, 0.0f),
  66. glm::vec2(1.0f, 1.0f),
  67. glm::vec2(0.0f, 1.0f), 0.5f);
  68. glm::vec3 Result3 = glm::hermite(
  69. glm::vec3(0.0f, 0.0f, 0.0f),
  70. glm::vec3(1.0f, 0.0f, 0.0f),
  71. glm::vec3(1.0f, 1.0f, 0.0f),
  72. glm::vec3(0.0f, 1.0f, 0.0f), 0.5f);
  73. glm::vec4 Result4 = glm::hermite(
  74. glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),
  75. glm::vec4(1.0f, 0.0f, 0.0f, 1.0f),
  76. glm::vec4(1.0f, 1.0f, 0.0f, 1.0f),
  77. glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), 0.5f);
  78. return Error;
  79. }
  80. }//catmullRom
  81. namespace cubic
  82. {
  83. int test()
  84. {
  85. int Error(0);
  86. glm::vec2 Result2 = glm::cubic(
  87. glm::vec2(0.0f, 0.0f),
  88. glm::vec2(1.0f, 0.0f),
  89. glm::vec2(1.0f, 1.0f),
  90. glm::vec2(0.0f, 1.0f), 0.5f);
  91. glm::vec3 Result3 = glm::cubic(
  92. glm::vec3(0.0f, 0.0f, 0.0f),
  93. glm::vec3(1.0f, 0.0f, 0.0f),
  94. glm::vec3(1.0f, 1.0f, 0.0f),
  95. glm::vec3(0.0f, 1.0f, 0.0f), 0.5f);
  96. glm::vec4 Result = glm::cubic(
  97. glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),
  98. glm::vec4(1.0f, 0.0f, 0.0f, 1.0f),
  99. glm::vec4(1.0f, 1.0f, 0.0f, 1.0f),
  100. glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), 0.5f);
  101. return Error;
  102. }
  103. }//catmullRom
  104. int main()
  105. {
  106. int Error(0);
  107. Error += catmullRom::test();
  108. Error += hermite::test();
  109. Error += cubic::test();
  110. return Error;
  111. }