Cleanup: de-duplicate view3d clipping

This commit is contained in:
Campbell Barton
2015-03-07 00:25:27 +11:00
parent 17d96ca2aa
commit 56f794fce6
3 changed files with 17 additions and 25 deletions

View File

@@ -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);

View File

@@ -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])

View File

@@ -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])