mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
Merge pull request #132 from Uwila/ray-tests
* tests: 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_plane.h"
|
||||||
#include "test_affine.h"
|
#include "test_affine.h"
|
||||||
#include "test_affine_mat.h"
|
#include "test_affine_mat.h"
|
||||||
|
#include "test_ray.h"
|
||||||
|
|
||||||
#undef GLM
|
#undef GLM
|
||||||
#undef GLM_PREFIX
|
#undef GLM_PREFIX
|
||||||
@@ -44,6 +45,7 @@
|
|||||||
#include "test_plane.h"
|
#include "test_plane.h"
|
||||||
#include "test_affine.h"
|
#include "test_affine.h"
|
||||||
#include "test_affine_mat.h"
|
#include "test_affine_mat.h"
|
||||||
|
#include "test_ray.h"
|
||||||
|
|
||||||
#undef GLM
|
#undef GLM
|
||||||
#undef GLM_PREFIX
|
#undef GLM_PREFIX
|
||||||
|
|||||||
@@ -218,6 +218,10 @@ TEST_DECLARE(clamp)
|
|||||||
/* euler */
|
/* euler */
|
||||||
TEST_DECLARE(euler)
|
TEST_DECLARE(euler)
|
||||||
|
|
||||||
|
/* ray */
|
||||||
|
TEST_DECLARE(glm_ray_triangle)
|
||||||
|
TEST_DECLARE(glmc_ray_triangle)
|
||||||
|
|
||||||
/* quat */
|
/* quat */
|
||||||
TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY_INIT)
|
TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY_INIT)
|
||||||
TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY)
|
TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY)
|
||||||
@@ -905,6 +909,10 @@ TEST_LIST {
|
|||||||
/* euler */
|
/* euler */
|
||||||
TEST_ENTRY(euler)
|
TEST_ENTRY(euler)
|
||||||
|
|
||||||
|
/* ray */
|
||||||
|
TEST_ENTRY(glm_ray_triangle)
|
||||||
|
TEST_ENTRY(glmc_ray_triangle)
|
||||||
|
|
||||||
/* quat */
|
/* quat */
|
||||||
TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY_INIT)
|
TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY_INIT)
|
||||||
TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY)
|
TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
<ClInclude Include="..\test\src\test_vec2.h" />
|
<ClInclude Include="..\test\src\test_vec2.h" />
|
||||||
<ClInclude Include="..\test\src\test_vec3.h" />
|
<ClInclude Include="..\test\src\test_vec3.h" />
|
||||||
<ClInclude Include="..\test\src\test_vec4.h" />
|
<ClInclude Include="..\test\src\test_vec4.h" />
|
||||||
|
<ClInclude Include="..\test\src\test_ray.h" />
|
||||||
<ClInclude Include="..\test\tests.h" />
|
<ClInclude Include="..\test\tests.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -79,5 +79,8 @@
|
|||||||
<ClInclude Include="..\test\src\test_vec2.h">
|
<ClInclude Include="..\test\src\test_vec2.h">
|
||||||
<Filter>src</Filter>
|
<Filter>src</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\test\src\test_ray.h">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user