commit e7275459ca0c03c57410e4cf23a1687b00875c05
parent 1fbc15f650cadeae12233771f95a8d10ba6fc2da
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 27 Sep 2022 12:14:46 +0200
Add the rngrd_trace_ray function
Diffstat:
2 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/src/rngrd.h b/src/rngrd.h
@@ -71,9 +71,9 @@ static const struct rngrd_create_args RNDGR_CREATE_ARGS_DEFAULT =
RNGRD_CREATE_ARGS_DEFAULT__;
struct rngrd_trace_ray_args {
- double org[3]; /* Ray origin */
- double dir[3]; /* Ray direction */
- double range[2]; /* Ray range */
+ double ray_org[3]; /* Ray origin */
+ double ray_dir[3]; /* Ray direction */
+ double ray_range[2]; /* Ray range */
/* Intersection from which the ray starts. Used to avoid self intersection */
struct s3d_hit hit_from;
@@ -123,6 +123,12 @@ RNGRD_API res_T
rngrd_validate
(const struct rngrd* ground);
+RNGRD_API res_T
+rngrd_trace_ray
+ (const struct rngrd* ground,
+ struct rngrd_trace_ray_args* args,
+ struct s3d_hit* hit);
+
END_DECLS
#endif /* RNGRD_H */
diff --git a/src/rngrd_mesh.c b/src/rngrd_mesh.c
@@ -258,6 +258,46 @@ error:
}
/*******************************************************************************
+ * Exported functions
+ ******************************************************************************/
+res_T
+rngrd_trace_ray
+ (const struct rngrd* ground,
+ struct rngrd_trace_ray_args* args,
+ struct s3d_hit* hit)
+{
+ float org[3];
+ float dir[3];
+ float range[2];
+ res_T res = RES_OK;
+
+ if(!ground || !args || !hit) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ f3_set_d3(org, args->ray_org);
+ f3_set_d3(dir, args->ray_dir);
+ f3_set_d3(range, args->ray_range);
+
+ *hit = S3D_HIT_NULL;
+
+ res = s3d_scene_view_trace_ray(ground->s3d_view, org, dir, range, args, hit);
+ if(res != RES_OK) {
+ log_err(ground,
+ "%s: error tracing ray "
+ "(origin = %g, %g, %g; direction = %g, %g ,%g; range = %g, %g)\n",
+ FUNC_NAME, SPLIT3(org), SPLIT3(dir), SPLIT2(range));
+ goto error;
+ }
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+/*******************************************************************************
* Local function
******************************************************************************/
res_T