diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-22 20:09:50 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-22 20:10:40 +0400 |
commit | 421c42bc161d7f2e87fcb6d48c57c0063e6bd5fb (patch) | |
tree | 1106b7309e1520094f5e054928b0309b05859307 | |
parent | 6974b69c61729cc80a72d78f02eb137c5097b129 (diff) |
Math Lib: move barycentric_weights_v2_persp to into math_geom
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 25 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image_proj.c | 21 |
3 files changed, 25 insertions, 23 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 5067cee7352..6000b8d5f23 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -215,6 +215,8 @@ void barycentric_transform(float pt_tar[3], float const pt_src[3], void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3]); +void barycentric_weights_v2_persp(const float v1[4], const float v2[4], const float v3[4], + const float co[2], float w[3]); void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const float v3[2], const float v4[2], const float co[2], float w[4]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 14f049c2ee4..85a2974fa50 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -2272,8 +2272,9 @@ bool barycentric_coords_v2(const float v1[2], const float v2[2], const float v3[ return false; } -/* used by projection painting - * note: using area_tri_signed_v2 means locations outside the triangle are correctly weighted */ +/** + * \note: using #area_tri_signed_v2 means locations outside the triangle are correctly weighted + */ void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3]) { float wtot; @@ -2291,6 +2292,26 @@ void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3 } } +/** + * still use 2D X,Y space but this works for verts transformed by a perspective matrix, + * using their 4th component as a weight + */ +void barycentric_weights_v2_persp(const float v1[4], const float v2[4], const float v3[4], const float co[2], float w[3]) +{ + float wtot; + + w[0] = area_tri_signed_v2(v2, v3, co) / v1[3]; + w[1] = area_tri_signed_v2(v3, v1, co) / v2[3]; + w[2] = area_tri_signed_v2(v1, v2, co) / v3[3]; + wtot = w[0] + w[1] + w[2]; + + if (wtot != 0.0f) { + mul_v3_fl(w, 1.0f / wtot); + } + else /* dummy values for zero area face */ + w[0] = w[1] = w[2] = 1.0f / 3.0f; +} + /* same as #barycentric_weights_v2 but works with a quad, * note: untested for values outside the quad's bounds * this is #interp_weights_poly_v2 expanded for quads only */ diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index ac48bee404e..5ad391913cb 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -375,27 +375,6 @@ static int project_bucket_offset_safe(const ProjPaintState *ps, const float proj } } -/* still use 2D X,Y space but this works for verts transformed by a perspective matrix, using their 4th component as a weight */ -static void barycentric_weights_v2_persp(const float v1[4], const float v2[4], const float v3[4], const float co[2], float w[3]) -{ - float wtot_inv, wtot; - - w[0] = area_tri_signed_v2(v2, v3, co) / v1[3]; - w[1] = area_tri_signed_v2(v3, v1, co) / v2[3]; - w[2] = area_tri_signed_v2(v1, v2, co) / v3[3]; - wtot = w[0] + w[1] + w[2]; - - if (wtot != 0.0f) { - wtot_inv = 1.0f / wtot; - - w[0] = w[0] * wtot_inv; - w[1] = w[1] * wtot_inv; - w[2] = w[2] * wtot_inv; - } - else /* dummy values for zero area face */ - w[0] = w[1] = w[2] = 1.0f / 3.0f; -} - static float VecZDepthOrtho(const float pt[2], const float v1[3], const float v2[3], const float v3[3], float w[3]) |