commit 370982f88a64f501edbdc7af4f357cccb23f022c
parent f52d7d20e5b977124eed59e9a71b5e0887b9cef6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 17 May 2016 15:39:47 +0200
Implement and test the s3d_shape_get_hit_filter_data function
Diffstat:
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/src/s3d.h b/src/s3d.h
@@ -421,6 +421,11 @@ s3d_shape_set_hit_filter_function
s3d_hit_filter_function_T func,
void* filter_data);
+S3D_API res_T
+s3d_shape_get_hit_filter_data
+ (struct s3d_shape* shape,
+ void** data);
+
/*******************************************************************************
* Primitive API - Define a geometric primitive of a shape
******************************************************************************/
diff --git a/src/s3d_shape.c b/src/s3d_shape.c
@@ -206,13 +206,21 @@ s3d_shape_set_hit_filter_function
s3d_hit_filter_function_T func,
void* data)
{
- if(!shape || !func) return RES_BAD_ARG;
+ if(!shape) return RES_BAD_ARG;
shape->filter = func;
shape->filter_data = data;
return RES_OK;
}
res_T
+s3d_shape_get_hit_filter_data(struct s3d_shape* shape, void** data)
+{
+ if(!shape || !data) return RES_BAD_ARG;
+ *data = shape->filter_data;
+ return RES_OK;
+}
+
+res_T
s3d_instance_set_position
(struct s3d_shape* shape, const float position[3])
{
diff --git a/src/test_s3d_shape.c b/src/test_s3d_shape.c
@@ -300,10 +300,24 @@ main(int argc, char** argv)
CHECK(s3d_shape_flip_surface(shape), RES_OK);
CHECK(s3d_shape_set_hit_filter_function(NULL, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_set_hit_filter_function(shape, NULL, NULL), RES_BAD_ARG);
+ CHECK(s3d_shape_set_hit_filter_function(shape, NULL, NULL), RES_OK);
CHECK(s3d_shape_set_hit_filter_function(NULL, filter_none, NULL), RES_BAD_ARG);
CHECK(s3d_shape_set_hit_filter_function(shape, filter_none, NULL), RES_OK);
+ CHECK(s3d_shape_get_hit_filter_data(NULL, NULL), RES_BAD_ARG);
+ CHECK(s3d_shape_get_hit_filter_data(shape, NULL), RES_BAD_ARG);
+ CHECK(s3d_shape_get_hit_filter_data(NULL, &data), RES_BAD_ARG);
+ CHECK(s3d_shape_get_hit_filter_data(shape, &data), RES_OK);
+ CHECK(data, NULL);
+
+ CHECK(s3d_shape_set_hit_filter_function(shape, NULL, NULL), RES_OK);
+ CHECK(s3d_shape_get_hit_filter_data(shape, &data), RES_OK);
+ CHECK(data, NULL);
+ CHECK(s3d_shape_set_hit_filter_function
+ (shape, filter_none, (void*)0xDEADBEEF), RES_OK);
+ CHECK(s3d_shape_get_hit_filter_data(shape, &data), RES_OK);
+ CHECK((uintptr_t)data, 0xDEADBEEF);
+
CHECK(s3d_scene_attach_shape(scn, shape), RES_OK);
CHECK(s3d_scene_instantiate(scn, &inst), RES_OK);