diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-05 06:57:30 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-05 06:57:30 +0400 |
commit | f4eb64b840acbf0428f29d71849946d479b925ae (patch) | |
tree | 16821a766d45eb6459bd413286510802ab4125e9 /source/blender/blenlib/intern | |
parent | f1989793e76335105ad7083fdc8109a5c9d5afdf (diff) |
make use of axis_dominant_v3() function for is_quad_convex_v3()
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index e3ce31bd508..67be7519729 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -3055,34 +3055,21 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl int is_quad_convex_v3(const float *v1, const float *v2, const float *v3, const float *v4) { float nor[3], nor1[3], nor2[3], vec[4][2]; + int axis_a, axis_b; /* define projection, do both trias apart, quad is undefined! */ - normal_tri_v3( nor1,v1, v2, v3); - normal_tri_v3( nor2,v1, v3, v4); - nor[0]= ABS(nor1[0]) + ABS(nor2[0]); - nor[1]= ABS(nor1[1]) + ABS(nor2[1]); - nor[2]= ABS(nor1[2]) + ABS(nor2[2]); - - if(nor[2] >= 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]; - } + normal_tri_v3(nor1, v1, v2, v3); + normal_tri_v3(nor2, v1, v3, v4); + add_v3_v3v3(nor, nor1, nor2); + + axis_dominant_v3(&axis_a, &axis_b, nor); + + vec[0][0]= v1[axis_a]; vec[0][1]= v1[axis_b]; + vec[1][0]= v2[axis_a]; vec[1][1]= v2[axis_b]; + + vec[2][0]= v3[axis_a]; vec[2][1]= v3[axis_b]; + vec[3][0]= v4[axis_a]; vec[3][1]= v4[axis_b]; /* 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; + return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0) ? 1 : 0; } |