diff --git a/test/src/test_ray.h b/test/src/test_ray.h new file mode 100644 index 0000000..c1b0281 --- /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..ea9f902 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 @@ -44,6 +45,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..1ed75d8 100644 --- a/test/tests.h +++ b/test/tests.h @@ -218,6 +218,10 @@ TEST_DECLARE(clamp) /* euler */ TEST_DECLARE(euler) +/* ray */ +TEST_DECLARE(glm_ray_triangle) +TEST_DECLARE(glmc_ray_triangle) + /* quat */ TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY_INIT) TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY) @@ -905,6 +909,10 @@ TEST_LIST { /* euler */ TEST_ENTRY(euler) + /* ray */ + TEST_ENTRY(glm_ray_triangle) + TEST_ENTRY(glmc_ray_triangle) + /* quat */ TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY_INIT) TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY) diff --git a/win/cglm-test.vcxproj b/win/cglm-test.vcxproj index 1c0916d..6599103 100644 --- a/win/cglm-test.vcxproj +++ b/win/cglm-test.vcxproj @@ -42,6 +42,7 @@ + diff --git a/win/cglm-test.vcxproj.filters b/win/cglm-test.vcxproj.filters index c81dc11..b8f7326 100644 --- a/win/cglm-test.vcxproj.filters +++ b/win/cglm-test.vcxproj.filters @@ -79,5 +79,8 @@ src + + src + \ No newline at end of file