diff options
author | mano-wii <germano.costa@ig.com.br> | 2019-08-15 16:17:41 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2019-08-15 16:20:21 +0300 |
commit | 261a02fc596db0e91667d4e3af9204b165ec4006 (patch) | |
tree | d68304925e0a500b226d807fcfca5e1055750cec /source | |
parent | 78b56fa7d973dab8d11786115a87af57681a7dda (diff) |
DRW: New function DRW_culling_min_max_test
For testing intersection with frustrum planes without having to transform all bound box vertices into global space.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 1 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index a8f67e10a4d..3379aa28d0f 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -597,6 +597,7 @@ bool DRW_view_is_persp_get(const DRWView *view); bool DRW_culling_sphere_test(const DRWView *view, const BoundSphere *bsphere); bool DRW_culling_box_test(const DRWView *view, const BoundBox *bbox); bool DRW_culling_plane_test(const DRWView *view, const float plane[4]); +bool DRW_culling_min_max_test(const DRWView *view, float obmat[4][4], float min[3], float max[3]); void DRW_culling_frustum_corners_get(const DRWView *view, BoundBox *corners); void DRW_culling_frustum_planes_get(const DRWView *view, float planes[6][4]); diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 949d3e1d38b..3bf442b4f39 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -22,6 +22,7 @@ #include "draw_manager.h" +#include "BLI_math.h" #include "BLI_math_bits.h" #include "BLI_memblock.h" @@ -488,6 +489,26 @@ bool DRW_culling_plane_test(const DRWView *view, const float plane[4]) return draw_culling_plane_test(&view->frustum_corners, plane); } +/* Return True if the given box intersect the current view frustum. + * This function will have to be replaced when world space bb per objects is implemented. */ +bool DRW_culling_min_max_test(const DRWView *view, float obmat[4][4], float min[3], float max[3]) +{ + view = view ? view : DST.view_default; + float tobmat[4][4]; + transpose_m4_m4(tobmat, obmat); + for (int i = 6; i--;) { + float frustum_plane_local[4], bb_near[3], bb_far[3]; + mul_v4_m4v4(frustum_plane_local, tobmat, view->frustum_planes[i]); + aabb_get_near_far_from_plane(frustum_plane_local, min, max, bb_near, bb_far); + + if (plane_point_side_v3(frustum_plane_local, bb_far) < 0.0f) { + return false; + } + } + + return true; +} + void DRW_culling_frustum_corners_get(const DRWView *view, BoundBox *corners) { view = view ? view : DST.view_default; |