diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-09-25 04:20:42 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-09-25 04:20:42 +0400 |
commit | b0bf816ececfaf56281e1539577656df3c995aa0 (patch) | |
tree | 0e289fc19194472a88e08528efb9e8fb9947d9a1 /source/blender/blenlib | |
parent | 687cacfdd0aec599e56f7f5e2ed69f0bf6c61b4e (diff) |
fix [#32646] Duplifaces can have wrong orientation with ngons
concave ngons could flip the dupliface, now use the faces normal when calculating the dupli-face.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_rotation.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h index 8a439c7cf7a..8260331b808 100644 --- a/source/blender/blenlib/BLI_math_rotation.h +++ b/source/blender/blenlib/BLI_math_rotation.h @@ -78,6 +78,8 @@ void quat_to_mat4(float mat[4][4], const float q[4]); void mat3_to_quat(float q[4], float mat[3][3]); void mat4_to_quat(float q[4], float mat[4][4]); +void tri_to_quat_ex(float quat[4], const float v1[3], const float v2[3], const float v3[3], + const float no_orig[3]); void tri_to_quat(float q[4], const float a[3], const float b[3], const float c[3]); void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag); /* note: v1 and v2 must be normalized */ diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index e10b0b3298c..1392e88c168 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -613,13 +613,21 @@ void add_qt_qtqt(float result[4], const float quat1[4], const float quat2[4], co result[3] = quat1[3] + t * quat2[3]; } -void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const float v3[3]) +/* same as tri_to_quat() but takes pre-computed normal from the triangle + * used for ngons when we know their normal */ +void tri_to_quat_ex(float quat[4], const float v1[3], const float v2[3], const float v3[3], + const float no_orig[3]) { /* imaginary x-axis, y-axis triangle is being rotated */ float vec[3], q1[4], q2[4], n[3], si, co, angle, mat[3][3], imat[3][3]; /* move z-axis to face-normal */ +#if 0 normal_tri_v3(vec, v1, v2, v3); +#else + copy_v3_v3(vec, no_orig); + (void)v3; +#endif n[0] = vec[1]; n[1] = -vec[0]; @@ -659,6 +667,13 @@ void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const floa mul_qt_qtqt(quat, q1, q2); } +void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const float v3[3]) +{ + float vec[3]; + normal_tri_v3(vec, v1, v2, v3); + tri_to_quat_ex(quat, v1, v2, v3, vec); +} + void print_qt(const char *str, const float q[4]) { printf("%s: %.3f %.3f %.3f %.3f\n", str, q[0], q[1], q[2], q[3]); |