From d16547ab73e7086d5358bba67093173827d12afe Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 5 Jan 2010 14:26:38 +0000 Subject: Alt+B view clipping is now taken into account properly for sculpt, particle edit and snapping, by clipping the view ray. --- source/blender/blenlib/BLI_math_geom.h | 2 ++ source/blender/blenlib/intern/math_geom.c | 49 +++++++++++++++++++++++++++++++ source/blender/blenlib/intern/pbvh.c | 5 ++++ 3 files changed, 56 insertions(+) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 0bbe8fac976..f650a55d8ad 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -111,6 +111,8 @@ int isect_axial_line_tri_v3(int axis, float co1[3], float co2[3], int isect_aabb_aabb_v3(float min1[3], float max1[3], float min2[3], float max2[3]); +int clip_line_plane(float clipco[3], float plane[4], float co[3]); + /****************************** Interpolation ********************************/ /* tri or quad, d can be NULL */ diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 2b94227099c..a80f999cdbb 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -1246,6 +1246,55 @@ int isect_point_tri_prism_v3(float p[3], float v1[3], float v2[3], float v3[3]) return 1; } +int clip_line_plane(float p1[3], float p2[3], float plane[4]) +{ + float dp[3], n[3], div, t, pc[3]; + + copy_v3_v3(n, plane); + sub_v3_v3v3(dp, p2, p1); + div= dot_v3v3(dp, n); + + if(div == 0.0f) /* parallel */ + return 1; + + t= -(dot_v3v3(p1, n) + plane[3])/div; + + if(div > 0.0f) { + /* behind plane, completely clipped */ + if(t >= 1.0f) { + zero_v3(p1); + zero_v3(p2); + return 0; + } + + /* intersect plane */ + if(t > 0.0f) { + madd_v3_v3v3fl(pc, p1, dp, t); + copy_v3_v3(p1, pc); + return 1; + } + + return 1; + } + else { + /* behind plane, completely clipped */ + if(t <= 0.0f) { + zero_v3(p1); + zero_v3(p2); + return 0; + } + + /* intersect plane */ + if(t < 1.0f) { + madd_v3_v3v3fl(pc, p1, dp, t); + copy_v3_v3(p2, pc); + return 1; + } + + return 1; + } +} + /****************************** Interpolation ********************************/ static float tri_signed_area(float *v1, float *v2, float *v3, int i, int j) diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 6f33fab2571..c1bdbf32fac 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -694,6 +694,11 @@ void BLI_pbvh_search_gather(PBVH *bvh, pbvh_iter_end(&iter); + if(tot == 0 && array) { + MEM_freeN(array); + array= NULL; + } + *r_array= array; *r_tot= tot; } -- cgit v1.2.3