mirror of
https://github.com/recp/cglm.git
synced 2025-10-04 09:08:53 +00:00
Add tests for glm_ray_triangle
This commit is contained in:
34
test/src/test_ray.h
Normal file
34
test/src/test_ray.h
Normal file
@@ -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
|
||||
}
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user