diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-03-16 19:31:19 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-03-16 19:31:19 +0400 |
commit | 0e9084d5ece71185884d7a63b3e0617254430a29 (patch) | |
tree | 0d4571651cb6ce55f921f6194218568c17441d4e /source/blender/blenlib/intern/math_rotation.c | |
parent | caf8684b5066720d4f4124092e23857dd462cb8b (diff) |
Fix T39210: Grid Fill is generating mesh that's inconsistent with selected edge loops
Issue was in BLI's rotation_between_vecs_to_quat(), which did not handled correctly cases where both vectors are colinear.
Patch by Campbell Barton and me.
Issue originaly tracked down by Yan Shi, many thanks!
Diffstat (limited to 'source/blender/blenlib/intern/math_rotation.c')
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index c7c0626019f..d1753a77f7f 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -404,13 +404,29 @@ float normalize_qt_qt(float r[4], const float q[4]) void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3]) { float axis[3]; - float angle; cross_v3_v3v3(axis, v1, v2); - angle = angle_normalized_v3v3(v1, v2); + if (normalize_v3(axis) > FLT_EPSILON) { + float angle; - axis_angle_to_quat(q, axis, angle); + angle = angle_normalized_v3v3(v1, v2); + + axis_angle_normalized_to_quat(q, axis, angle); + } + else { + /* degenerate case */ + + if (dot_v3v3(v1, v2) > 0.0f) { + /* Same vectors, zero rotation... */ + unit_qt(q); + } + else { + /* Colinear but opposed vectors, 180 rotation... */ + ortho_v3_v3(axis, v1); + axis_angle_to_quat(q, axis, (float)M_PI); + } + } } void rotation_between_quats_to_quat(float q[4], const float q1[4], const float q2[4]) |