[Bf-blender-cvs] [421c42b] master: Math Lib: move barycentric_weights_v2_persp to into math_geom

Campbell Barton noreply at git.blender.org
Tue Apr 22 18:11:20 CEST 2014


Commit: 421c42bc161d7f2e87fcb6d48c57c0063e6bd5fb
Author: Campbell Barton
Date:   Wed Apr 23 02:09:50 2014 +1000
https://developer.blender.org/rB421c42bc161d7f2e87fcb6d48c57c0063e6bd5fb

Math Lib: move barycentric_weights_v2_persp to into math_geom

===================================================================

M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 5067cee..6000b8d 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 14f049c..85a2974 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 ac48bee..5ad3919 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])




More information about the Bf-blender-cvs mailing list