commit a7d2697f8a9e40cd7d42332594bd6cc261b2508e
parent 08ac4673a2335844c3b6a412ee5bf8ab3e6c3798
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 29 Jun 2016 15:10:44 +0200
Test the filter hit process
Diffstat:
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/src/test_s2d_trace_ray.c b/src/test_s2d_trace_ray.c
@@ -31,6 +31,21 @@
#include <rsys/float2.h>
+static int
+filter_hit
+ (const struct s2d_hit* hit,
+ const float org[2],
+ const float dir[2],
+ void* ray_data,
+ void* filter_data)
+{
+ (void)dir, (void)org;
+ NCHECK(hit, NULL);
+ CHECK((intptr_t)filter_data, 0xDEADBEEF);
+ if(!ray_data) return 0;
+ return S2D_PRIMITIVE_EQ((struct s2d_primitive*)ray_data, &hit->prim);
+}
+
int
main(int argc, char** argv)
{
@@ -39,6 +54,7 @@ main(int argc, char** argv)
struct s2d_scene* scn;
struct s2d_vertex_data vdata;
struct s2d_hit hit;
+ struct s2d_primitive prim, prim2;
struct mem_allocator allocator;
float org[2], dir[3], range[2];
float N[3] = {0.f, 0.f, 0.f};
@@ -54,9 +70,17 @@ main(int argc, char** argv)
vdata.usage = S2D_POSITION;
vdata.get = line_segments_get_position;
CHECK(s2d_line_segments_setup_indexed_vertices
- (shape, box_nsegs, line_segments_get_ids, box_nverts, &vdata, 1,
+ (shape, box_nsegs, line_segments_get_ids, box_nverts, &vdata, 1,
(void*)&box_desc), RES_OK);
+ #define SET_FILTER_FUNC s2d_line_segments_set_hit_filter_function
+ CHECK(SET_FILTER_FUNC(NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(SET_FILTER_FUNC(shape, NULL, NULL), RES_OK);
+ CHECK(SET_FILTER_FUNC(NULL, filter_hit, NULL), RES_BAD_ARG);
+ CHECK(SET_FILTER_FUNC(shape, filter_hit, NULL), RES_OK);
+ CHECK(SET_FILTER_FUNC(shape, filter_hit, (void*)0xDEADBEEF), RES_OK);
+ #undef SET_FILTER_FUNC
+
CHECK(s2d_scene_attach_shape(scn, shape), RES_OK);
f2(org, 0.f, 0.f);
@@ -106,6 +130,11 @@ main(int argc, char** argv)
CHECK(eq_epsf(hit.u, 0.5f, 1.e-6f), 1);
CHECK(eq_epsf(hit.distance, 1.0f, 1.e-6f), 1);
+ f2(dir, 0.f, -1.f);
+ prim = hit.prim;
+ CHECK(s2d_scene_trace_ray(scn, org, dir, range, &prim, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 1);
+
f2(dir, -1.f, 0.f);
CHECK(s2d_scene_trace_ray(scn, org, dir, range, NULL, &hit), RES_OK);
CHECK(S2D_HIT_NONE(&hit), 0);
@@ -124,6 +153,19 @@ main(int argc, char** argv)
CHECK(eq_epsf(hit.u, 0.5f, 1.e-6f), 1);
CHECK(eq_epsf(hit.distance, 1.0f, 1.e-6f), 1);
+ prim2 = hit.prim;
+
+ f2(org, 0.f, 2.f);
+ f2(dir, 0.f, -1.f);
+ CHECK(s2d_scene_trace_ray(scn, org, dir, range, NULL, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 0);
+ CHECK(S2D_PRIMITIVE_EQ(&hit.prim, &prim2), 1);
+
+ CHECK(s2d_scene_trace_ray(scn, org, dir, range, &prim2, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 0);
+ CHECK(S2D_PRIMITIVE_EQ(&hit.prim, &prim), 1);
+
+ f2_splat(org, 0.f);
f2(dir, 1.f, 0.f);
CHECK(s2d_scene_trace_ray(scn, org, dir, range, NULL, &hit), RES_OK);
CHECK(S2D_HIT_NONE(&hit), 0);