diff options
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 15 | ||||
-rw-r--r-- | source/blender/blenlib/intern/scanfill.c | 4 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.c | 12 |
5 files changed, 20 insertions, 15 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 7fba2699fc7..54c06616110 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -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 **********************************/ diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 58c882e894e..b2d5392c596 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -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) diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 62e582c89c4..ef8f26e3780 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -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]) diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index a303cadab85..1b60d58b154 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -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; } diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 67e3d24ade1..77e50b1ea3f 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -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; |