From 56f794fce60f6e3681b8445403d4826371b3b365 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 7 Mar 2015 00:25:27 +1100 Subject: Cleanup: de-duplicate view3d clipping --- source/blender/editors/include/ED_view3d.h | 1 + source/blender/editors/space_view3d/view3d_edit.c | 16 +-------------- source/blender/editors/space_view3d/view3d_view.c | 25 ++++++++++++++--------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 5bf077b6293..30f8fb4f922 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -241,6 +241,7 @@ void ED_view3d_calc_camera_border_size(struct Scene *scene, struct ARegion *ar, bool ED_view3d_calc_render_border(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, struct rcti *rect); +void ED_view3d_clipping_calc_from_boundbox(float clip[6][4], const struct BoundBox *clipbb, const bool is_flip); void ED_view3d_clipping_calc(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, const struct rcti *rect); void ED_view3d_clipping_local(struct RegionView3D *rv3d, float mat[4][4]); bool ED_view3d_clipping_test(struct RegionView3D *rv3d, const float co[3], const bool is_local); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 7169fa95763..233a0bd03cd 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -4429,20 +4429,6 @@ void VIEW3D_OT_background_image_remove(wmOperatorType *ot) /* ********************* set clipping operator ****************** */ -static void calc_clipping_plane(float clip[6][4], const BoundBox *clipbb, const bool is_flip) -{ - int val; - - for (val = 0; val < 4; val++) { - normal_tri_v3(clip[val], clipbb->vec[val], clipbb->vec[val == 3 ? 0 : val + 1], clipbb->vec[val + 4]); - if (UNLIKELY(is_flip)) { - negate_v3(clip[val]); - } - - clip[val][3] = -dot_v3v3(clip[val], clipbb->vec[val]); - } -} - static void calc_local_clipping(float clip_local[6][4], BoundBox *clipbb, float mat[4][4]) { BoundBox clipbb_local; @@ -4455,7 +4441,7 @@ static void calc_local_clipping(float clip_local[6][4], BoundBox *clipbb, float mul_v3_m4v3(clipbb_local.vec[i], imat, clipbb->vec[i]); } - calc_clipping_plane(clip_local, &clipbb_local, is_negative_m4(mat)); + ED_view3d_clipping_calc_from_boundbox(clip_local, &clipbb_local, is_negative_m4(mat)); } void ED_view3d_clipping_local(RegionView3D *rv3d, float mat[4][4]) diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 5a3893f733f..76d9762ab09 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -609,6 +609,20 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot) /* ********************************** */ +void ED_view3d_clipping_calc_from_boundbox(float clip[4][4], const BoundBox *bb, const bool is_flip) +{ + int val; + + for (val = 0; val < 4; val++) { + normal_tri_v3(clip[val], bb->vec[val], bb->vec[val == 3 ? 0 : val + 1], bb->vec[val + 4]); + if (UNLIKELY(is_flip)) { + negate_v3(clip[val]); + } + + clip[val][3] = -dot_v3v3(clip[val], bb->vec[val]); + } +} + void ED_view3d_clipping_calc(BoundBox *bb, float planes[4][4], bglMats *mats, const rcti *rect) { float modelview[4][4]; @@ -644,16 +658,7 @@ void ED_view3d_clipping_calc(BoundBox *bb, float planes[4][4], bglMats *mats, co ((float *)modelview)[a] = mats->modelview[a]; flip_sign = is_negative_m4(modelview); - /* then plane equations */ - for (val = 0; val < 4; val++) { - - normal_tri_v3(planes[val], bb->vec[val], bb->vec[val == 3 ? 0 : val + 1], bb->vec[val + 4]); - - if (flip_sign) - negate_v3(planes[val]); - - planes[val][3] = -dot_v3v3(planes[val], bb->vec[val]); - } + ED_view3d_clipping_calc_from_boundbox(planes, bb, flip_sign); } static bool view3d_boundbox_clip_m4(const BoundBox *bb, float persmatob[4][4]) -- cgit v1.2.3