Platformer in OpenGL
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.

54 lines
1.4 KiB

5 years ago
  1. #define GLM_ENABLE_EXPERIMENTAL
  2. #include <glm/glm.hpp>
  3. #include <glm/gtc/epsilon.hpp>
  4. #include <glm/gtx/intersect.hpp>
  5. int test_intersectRayTriangle()
  6. {
  7. int Error = 0;
  8. glm::vec3 const Orig(0, 0, 2);
  9. glm::vec3 const Dir(0, 0, -1);
  10. glm::vec3 const Vert0(0, 0, 0);
  11. glm::vec3 const Vert1(-1, -1, 0);
  12. glm::vec3 const Vert2(1, -1, 0);
  13. glm::vec2 BaryPosition(0);
  14. float Distance = 0;
  15. bool const Result = glm::intersectRayTriangle(Orig, Dir, Vert0, Vert1, Vert2, BaryPosition, Distance);
  16. Error += glm::all(glm::epsilonEqual(BaryPosition, glm::vec2(0), std::numeric_limits<float>::epsilon())) ? 0 : 1;
  17. Error += glm::abs(Distance - 2.f) <= std::numeric_limits<float>::epsilon() ? 0 : 1;
  18. Error += Result ? 0 : 1;
  19. return Error;
  20. }
  21. int test_intersectLineTriangle()
  22. {
  23. int Error = 0;
  24. glm::vec3 const Orig(0, 0, 2);
  25. glm::vec3 const Dir(0, 0, -1);
  26. glm::vec3 const Vert0(0, 0, 0);
  27. glm::vec3 const Vert1(-1, -1, 0);
  28. glm::vec3 const Vert2(1, -1, 0);
  29. glm::vec3 Position(2.0f, 0.0f, 0.0f);
  30. bool const Result = glm::intersectLineTriangle(Orig, Dir, Vert0, Vert1, Vert2, Position);
  31. Error += glm::all(glm::epsilonEqual(Position, glm::vec3(2.0f, 0.0f, 0.0f), std::numeric_limits<float>::epsilon())) ? 0 : 1;
  32. Error += Result ? 0 : 1;
  33. return Error;
  34. }
  35. int main()
  36. {
  37. int Error = 0;
  38. Error += test_intersectRayTriangle();
  39. Error += test_intersectLineTriangle();
  40. return Error;
  41. }