X-Git-Url: https://git.blender.org/gitweb/gitweb.cgi/blender-staging.git/blobdiff_plain/acf30220c9d63e0f060ee69115fe82016de025d4..3c8d86e117b54914524cbc49a8678ecaad8671cf:/source/blender/blenlib/intern/math_geom.c diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 1170e44b27b..eecaed10bcc 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -2343,6 +2343,39 @@ void accumulate_vertex_normals(float n1[3], float n2[3], float n3[3], } } +/* Add weighted face normal component into normals of the face vertices. + Caller must pass pre-allocated vdiffs of nverts length. */ +#define VERT_BUF_SIZE 100 +void accumulate_vertex_normals_poly(float **vertnos, float polyno[3], + float **vertcos, float vdiffs[][3], int nverts) +{ + int i; + + /* calculate normalized edge directions for each edge in the poly */ + for (i = 0; i < nverts; i++) { + sub_v3_v3v3(vdiffs[i], vertcos[(i+1) % nverts], vertcos[i]); + normalize_v3(vdiffs[i]); + } + + /* accumulate angle weighted face normal */ + { + const float *prev_edge = vdiffs[nverts-1]; + int i; + + for(i=0; i= nor[0] && nor[2] >= nor[1]) { + vec[0][0]= v1[0]; vec[0][1]= v1[1]; + vec[1][0]= v2[0]; vec[1][1]= v2[1]; + vec[2][0]= v3[0]; vec[2][1]= v3[1]; + vec[3][0]= v4[0]; vec[3][1]= v4[1]; + } + else if(nor[1] >= nor[0] && nor[1]>= nor[2]) { + vec[0][0]= v1[0]; vec[0][1]= v1[2]; + vec[1][0]= v2[0]; vec[1][1]= v2[2]; + vec[2][0]= v3[0]; vec[2][1]= v3[2]; + vec[3][0]= v4[0]; vec[3][1]= v4[2]; + } + else { + vec[0][0]= v1[1]; vec[0][1]= v1[2]; + vec[1][0]= v2[1]; vec[1][1]= v2[2]; + vec[2][0]= v3[1]; vec[2][1]= v3[2]; + vec[3][0]= v4[1]; vec[3][1]= v4[2]; + } + + /* linetests, the 2 diagonals have to instersect to be convex */ + if( isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0 ) return 1; + return 0; +}