diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-02-01 14:32:34 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-02-01 19:24:47 +0400 |
commit | 5fce3457b79bccbbcfe9fad0ed6f1a04643cf71b (patch) | |
tree | 3893f68e5eac87ad03df3fb0c7041eaaab55c7e0 /source/blender/blenlib/intern/math_rotation.c | |
parent | a9e7c7b8488637cb1afa9394263c537547ff87c4 (diff) |
Math lib: add axis_angle_normalized_to_quat, use when length is known
Diffstat (limited to 'source/blender/blenlib/intern/math_rotation.c')
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 6559c3723bb..0392598769f 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -677,19 +677,22 @@ void print_qt(const char *str, const float q[4]) /******************************** Axis Angle *********************************/ -/* Axis angle to Quaternions */ +void axis_angle_normalized_to_quat(float q[4], const float axis[3], const float angle) +{ + const float phi = 0.5f * angle; + const float si = sinf(phi); + const float co = cosf(phi); + BLI_ASSERT_UNIT_V3(axis); + q[0] = co; + mul_v3_v3fl(q + 1, axis, si); +} + void axis_angle_to_quat(float q[4], const float axis[3], const float angle) { float nor[3]; if (LIKELY(normalize_v3_v3(nor, axis) != 0.0f)) { - const float phi = angle / 2.0f; - float si; - si = sinf(phi); - q[0] = cosf(phi); - q[1] = nor[0] * si; - q[2] = nor[1] * si; - q[3] = nor[2] * si; + axis_angle_normalized_to_quat(q, nor, angle); } else { unit_qt(q); |