Commit: 5fce3457b79bccbbcfe9fad0ed6f1a04643cf71b
Author: Campbell Barton
Date:   Sat Feb 1 21:32:34 2014 +1100
https://developer.blender.org/rB5fce3457b79bccbbcfe9fad0ed6f1a04643cf71b

Math lib: add axis_angle_normalized_to_quat, use when length is known

===================================================================

M       source/blender/blenlib/BLI_math_rotation.h
M       source/blender/blenlib/intern/math_rotation.c
M       source/blender/editors/space_view3d/view3d_edit.c
M       source/blender/editors/space_view3d/view3d_walk.c
M       source/blender/editors/transform/transform_manipulator.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_rotation.h 
b/source/blender/blenlib/BLI_math_rotation.h
index 4216127..c9f553c 100644
--- a/source/blender/blenlib/BLI_math_rotation.h
+++ b/source/blender/blenlib/BLI_math_rotation.h
@@ -95,6 +95,7 @@ void print_qt(const char *str, const float q[4]);
 /******************************** Axis Angle *********************************/
 
 /* conversion */
+void axis_angle_normalized_to_quat(float r[4], const float axis[3], const 
float angle);
 void axis_angle_to_quat(float r[4], const float axis[3], const float angle);
 void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle);
 void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], const 
float angle);
diff --git a/source/blender/blenlib/intern/math_rotation.c 
b/source/blender/blenlib/intern/math_rotation.c
index 6559c37..0392598 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);
diff --git a/source/blender/editors/space_view3d/view3d_edit.c 
b/source/blender/editors/space_view3d/view3d_edit.c
index 323bc6b..7d37326 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -834,7 +834,7 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y)
                }
 
                /* Perform the orbital rotation */
-               axis_angle_to_quat(q1, zvec_global, sensitivity * vod->reverse 
* (x - vod->oldx));
+               axis_angle_normalized_to_quat(q1, zvec_global, sensitivity * 
vod->reverse * (x - vod->oldx));
                mul_qt_qtqt(vod->viewquat, vod->viewquat, q1);
 
                if (vod->use_dyn_ofs) {
@@ -3562,7 +3562,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
                                }
 
                                /* z-axis */
-                               axis_angle_to_quat(quat_mul, zvec, angle);
+                               axis_angle_normalized_to_quat(quat_mul, zvec, 
angle);
                        }
                        else {
 
@@ -3615,7 +3615,7 @@ static void view_roll_angle(ARegion *ar, float quat[4], 
const float orig_quat[4]
        float quat_mul[4];
 
        /* camera axis */
-       axis_angle_to_quat(quat_mul, dvec, angle);
+       axis_angle_normalized_to_quat(quat_mul, dvec, angle);
 
        mul_qt_qtqt(quat, orig_quat, quat_mul);
        rv3d->view = RV3D_VIEW_USER;
diff --git a/source/blender/editors/space_view3d/view3d_walk.c 
b/source/blender/editors/space_view3d/view3d_walk.c
index 26f942b..31bb37e 100644
--- a/source/blender/editors/space_view3d/view3d_walk.c
+++ b/source/blender/editors/space_view3d/view3d_walk.c
@@ -973,7 +973,7 @@ static int walkApply(bContext *C, WalkInfo *walk)
                                        copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f);
 
                                        /* Rotate about the relative up vec */
-                                       axis_angle_to_quat(tmp_quat, upvec, x);
+                                       axis_angle_normalized_to_quat(tmp_quat, 
upvec, x);
                                        mul_qt_qtqt(rv3d->viewquat, 
rv3d->viewquat, tmp_quat);
                                }
                        }
diff --git a/source/blender/editors/transform/transform_manipulator.c 
b/source/blender/editors/transform/transform_manipulator.c
index fc4e5fc..98afa2a 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -162,7 +162,7 @@ static void stats_editbone(RegionView3D *rv3d, EditBone 
*ebo)
 }
 
 /* could move into BLI_math however this is only useful for display/editing 
purposes */
-static void axis_angle_to_gimbal_axis(float gmat[3][3], float axis[3], float 
angle)
+static void axis_angle_to_gimbal_axis(float gmat[3][3], const float axis[3], 
const float angle)
 {
        /* X/Y are arbitrary axies, most importantly Z is the axis of rotation 
*/

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to