Math Lib: move barycentric_weights_v2_persp to into math_geom

This commit is contained in:
Campbell Barton 2014-04-23 02:09:50 +10:00
parent 6974b69c61
commit 421c42bc16
3 changed files with 25 additions and 23 deletions

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

@ -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 */

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