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 | |
parent | a9e7c7b8488637cb1afa9394263c537547ff87c4 (diff) |
Math lib: add axis_angle_normalized_to_quat, use when length is known
Diffstat (limited to 'source')
5 files changed, 17 insertions, 13 deletions
diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h index 42161279bfd..c9f553c6fa5 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 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); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 323bc6bc436..7d37326740c 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 26f942b3ecd..31bb37e98f6 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 fc4e5fcb8e5..98afa2a3c46 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 */ |