diff --git a/test/src/test_ray.h b/test/src/test_ray.h new file mode 100644 index 0000000..a85ad8c --- /dev/null +++ b/test/src/test_ray.h @@ -0,0 +1,34 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, ray_triangle) { + // Check whether a simple hit is recognized with the right distance + vec3 origin = {0.0f, 0.0f, 0.0f}; + vec3 direction = {1.0f, 0.0f, 0.0f}; + vec3 opposite = {-1.0f, 0.0f, 0.0f}; + vec3 v0 = {5.0f, -1.0f, 1.0f}; + vec3 v1 = {5.0f, -1.0f, -1.0f}; + vec3 v2 = {5.0f, 1.0f, 0.0f}; + float d; + bool hit; + + hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, &d); + ASSERT(hit); + ASSERT(fabsf(d - 5.0f) <= 0.0000009); + + // Check whether a simple miss works + hit = GLM(ray_triangle)(origin, opposite, v0, v1, v2, &d); + ASSERT(!hit); + + // Check that we can disregard distance and pass NULL pointer instead + hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, NULL); + ASSERT(hit); + + TEST_SUCCESS +} diff --git a/test/src/tests.c b/test/src/tests.c index 669b33c..956823f 100644 --- a/test/src/tests.c +++ b/test/src/tests.c @@ -23,6 +23,7 @@ #include "test_plane.h" #include "test_affine.h" #include "test_affine_mat.h" +#include "test_ray.h" #undef GLM #undef GLM_PREFIX diff --git a/test/tests.h b/test/tests.h index 4c9a552..83351a5 100644 --- a/test/tests.h +++ b/test/tests.h @@ -218,6 +218,9 @@ TEST_DECLARE(clamp) /* euler */ TEST_DECLARE(euler) +/* ray */ +TEST_DECLARE(glm_ray_triangle) + /* quat */ TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY_INIT) TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY) @@ -905,6 +908,9 @@ TEST_LIST { /* euler */ TEST_ENTRY(euler) + /* ray */ + TEST_ENTRY(glm_ray_triangle) + /* quat */ TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY_INIT) TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY)