diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-03-13 05:11:08 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-03-13 05:11:08 +0400 |
commit | 8646bb446419592f8acc8ed0cdf8337bfc4a07eb (patch) | |
tree | 4ee959f06e2ffe18cb9dd1c91266c9e9ad81c686 /source/blender/blenlib | |
parent | b457c7fdbdf0b8cf7a4535574d9894d8850c55f4 (diff) |
workaround [#30480] Knife tool flicker
the problem was numeric precision when in ortho mode the start/end points for the view vector would be 2000 apart which caused trouble for the intersection test.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index b9f1e9a392a..9b5e3638609 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -73,6 +73,7 @@ void closest_to_plane_v3(float r[3], const float plane_co[3], const float plane float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3]); float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2]); +void limit_dist_v3(float v1[3], float v2[3], const float dist); /******************************* Intersection ********************************/ diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index fab6b7b1066..f491ea25075 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -1320,6 +1320,25 @@ float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2 return(dot_v2v2(u, h)/dot_v2v2(u, u)); } +/* ensyre the distance between these points is no greater then 'dist' + * if it is, scale then both into the center */ +void limit_dist_v3(float v1[3], float v2[3], const float dist) +{ + const float dist_old = len_v3v3(v1, v2); + + if (dist_old > dist) { + float v1_old[3]; + float v2_old[3]; + float fac = (dist / dist_old) * 0.5f; + + copy_v3_v3(v1_old, v1); + copy_v3_v3(v2_old, v2); + + interp_v3_v3v3(v1, v1_old, v2_old, 0.5f - fac); + interp_v3_v3v3(v2, v1_old, v2_old, 0.5f + fac); + } +} + /* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 2d, assumes point is in quad */ void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2[2], const float v3[2], const float pt[2], float r_uv[2]) { |