inline function for "Newell's Method" used for normal calc.

This commit is contained in:
Campbell Barton
2012-04-16 16:49:37 +00:00
parent e889fa4678
commit 67f8e3a3a7
5 changed files with 20 additions and 15 deletions

View File

@@ -124,6 +124,8 @@ MINLINE float dot_v3v3(const float a[3], const float b[3]);
MINLINE float cross_v2v2(const float a[2], const float b[2]);
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]);
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3]);
MINLINE void star_m3_v3(float rmat[3][3],float a[3]);
/*********************************** Length **********************************/

View File

@@ -92,7 +92,7 @@ MINLINE float saasinf(float fac)
MINLINE float sasqrtf(float fac)
{
if (fac <= 0.0f) return 0.0f;
return (float)sqrtf(fac);
return sqrtf(fac);
}
MINLINE float interpf(float target, float origin, float fac)

View File

@@ -480,6 +480,17 @@ MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
r[2] = a[0] * b[1] - a[1] * b[0];
}
/* Newell's Method */
/* excuse this fairly spesific function,
* its used for polygon normals all over the place
* could use a better name */
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
{
n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
}
MINLINE void star_m3_v3(float rmat[][3], float a[3])
{
rmat[0][0] = rmat[1][1] = rmat[2][2] = 0.0;
@@ -505,7 +516,7 @@ MINLINE float len_squared_v3(const float v[3])
MINLINE float len_v2(const float v[2])
{
return (float)sqrtf(v[0] * v[0] + v[1] * v[1]);
return sqrtf(v[0] * v[0] + v[1] * v[1]);
}
MINLINE float len_v2v2(const float v1[2], const float v2[2])
@@ -514,7 +525,7 @@ MINLINE float len_v2v2(const float v1[2], const float v2[2])
x = v1[0] - v2[0];
y = v1[1] - v2[1];
return (float)sqrtf(x * x + y * y);
return sqrtf(x * x + y * y);
}
MINLINE float len_v3(const float a[3])

View File

@@ -864,9 +864,7 @@ int BLI_edgefill(ScanFillContext *sf_ctx, const short do_quad_tri_speedup)
for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) {
if (LIKELY(!compare_v3v3(v_prev, eve->co, COMPLIMIT))) {
n[0] += (v_prev[1] - eve->co[1]) * (v_prev[2] + eve->co[2]);
n[1] += (v_prev[2] - eve->co[2]) * (v_prev[0] + eve->co[0]);
n[2] += (v_prev[0] - eve->co[0]) * (v_prev[1] + eve->co[1]);
add_newell_cross_v3_v3v3(n, v_prev, eve->co);
}
v_prev = eve->co;
}

View File

@@ -84,9 +84,7 @@ static void compute_poly_normal(float normal[3], float verts[][3], int nverts)
/* Newell's Method */
for (i = 0; i < nverts; v_prev = v_curr, v_curr = verts[++i]) {
n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
add_newell_cross_v3_v3v3(n, v_prev, v_curr);
}
if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) {
@@ -109,9 +107,7 @@ static void bm_face_compute_poly_normal(BMFace *f)
/* Newell's Method */
do {
n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
add_newell_cross_v3_v3v3(n, v_prev, v_curr);
l_iter = l_iter->next;
v_prev = v_curr;
@@ -142,9 +138,7 @@ static void bm_face_compute_poly_normal_vertex_cos(BMFace *f, float n[3],
/* Newell's Method */
do {
n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
add_newell_cross_v3_v3v3(n, v_prev, v_curr);
l_iter = l_iter->next;
v_prev = v_curr;