diff options
author | sanine <sanine.not@pm.me> | 2022-06-14 00:06:42 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-06-14 00:06:42 -0500 |
commit | 2f518e5e28d35ae24a5ac0e31000835e43b01972 (patch) | |
tree | 47fdeb9fa5b04e267702acb06424d3f87b37dd84 /libs/cglm/test/src/test_ray.h | |
parent | 034d5c965ff34cfdf4b153af9f32360a02e35684 (diff) |
add cglm as 3rd-party library
Diffstat (limited to 'libs/cglm/test/src/test_ray.h')
-rw-r--r-- | libs/cglm/test/src/test_ray.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libs/cglm/test/src/test_ray.h b/libs/cglm/test/src/test_ray.h new file mode 100644 index 0000000..c1b0281 --- /dev/null +++ b/libs/cglm/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 +} |