star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit ea54aeabde131965518bf6355c82ddaa612ac2f4
parent 9a35b047ec21d095f54d05c744ece13105205cb5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 16 Oct 2019 12:27:57 +0200

Fix the closes_point routine for a sphere

There was a bug when the query point was the center of the sphere that
defines the closest surface wrt the query position.

Diffstat:
Msrc/s3d_scene_view_closest_point.c | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/s3d_scene_view_closest_point.c b/src/s3d_scene_view_closest_point.c @@ -306,7 +306,7 @@ closest_point_sphere flip_surface = inst->flip_surface; } - /* Compute the distance from the the query pos to the sphere center */ + /* Compute the distance from the query pos to the sphere center */ f3_sub(Ng, query_pos, sphere_pos); len = f3_len(Ng); @@ -317,8 +317,18 @@ closest_point_sphere if(dst >= args->query->radius) return 0; + /* Normalize the hit normal */ + if(len > 0) { + f3_divf(Ng, Ng, len); + } else { + /* The query position is equal to the sphere center. Arbitrarily choose the + * point along the +X axis as the closest point */ + Ng[0] = 1.f; + Ng[1] = 0.f; + Ng[2] = 0.f; + } + /* Compute the uv of the found point */ - f3_divf(Ng, Ng, len); /* Normalize the hit normal */ sphere_normal_to_uv(Ng, uv); /* Flip the geometric normal wrt the flip surface flag */