diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2017-01-29 19:56:58 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2017-01-29 19:56:58 +0300 |
commit | cf6ca226fa58d7a03be6cebb73a88eeb57497cf4 (patch) | |
tree | 91d7988cddbcff26a63c5dcaab142701735e4ef5 /source/blender/blenlib | |
parent | dead79a16a8e307d6dc2de21380347460c6ddddb (diff) |
New math_geom function `isect_ray_aabb_v3_simple`
The new `isect_ray_aabb_v3_simple` function replaces the `BKE_boundbox_ray_hit_check` and can be used in BVHTree Root (first AABB). So it is much more efficient.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 28 |
2 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index e3635be671f..4a85e859c16 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -293,6 +293,10 @@ void isect_ray_aabb_v3_precalc( bool isect_ray_aabb_v3( const struct IsectRayAABB_Precalc *data, const float bb_min[3], const float bb_max[3], float *tmin); +bool isect_ray_aabb_v3_simple( + const float orig[3], const float dir[3], + const float bb_min[3], const float bb_max[3], + float *tmin, float *tmax); struct NearestRayToAABB_Precalc { float ray_origin[3]; diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 8f5d84dfa08..aeb6a550cd9 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -2309,6 +2309,34 @@ bool isect_ray_aabb_v3( return true; } +/* + * Test a bounding box (AABB) for ray intersection + * assumes the ray is already local to the boundbox space + */ +bool isect_ray_aabb_v3_simple( + const float orig[3], const float dir[3], + const float bb_min[3], const float bb_max[3], + float *tmin, float *tmax) +{ + double t[7]; + float hit_dist[2]; + t[1] = (double)(bb_min[0] - orig[0]) / dir[0]; + t[2] = (double)(bb_max[0] - orig[0]) / dir[0]; + t[3] = (double)(bb_min[1] - orig[1]) / dir[1]; + t[4] = (double)(bb_max[1] - orig[1]) / dir[1]; + t[5] = (double)(bb_min[2] - orig[2]) / dir[2]; + t[6] = (double)(bb_max[2] - orig[2]) / dir[2]; + hit_dist[0] = (float)fmax(fmax(fmin(t[1], t[2]), fmin(t[3], t[4])), fmin(t[5], t[6])); + hit_dist[1] = (float)fmin(fmin(fmax(t[1], t[2]), fmax(t[3], t[4])), fmax(t[5], t[6])); + if ((hit_dist[1] < 0 || hit_dist[0] > hit_dist[1])) + return false; + else { + if (tmin) *tmin = hit_dist[0]; + if (tmax) *tmax = hit_dist[1]; + return true; + } +} + void dist_squared_ray_to_aabb_v3_precalc( struct NearestRayToAABB_Precalc *data, const float ray_origin[3], const float ray_direction[3]) |