diff options
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_rotation.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 30 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 4 |
7 files changed, 42 insertions, 22 deletions
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index d747fb0cea2..02b95c89be4 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -1235,7 +1235,7 @@ static float dvar_eval_rotDiff(ChannelDriver *driver, DriverVar *dvar) mat4_to_quat(q1, pchan->pose_mat); mat4_to_quat(q2, pchan2->pose_mat); - invert_qt(q1); + invert_qt_normalized(q1); mul_qt_qtqt(quat, q1, q2); angle = 2.0f * (saacos(quat[0])); angle = ABS(angle); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index ffb614fdf11..61c4073a2fd 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1951,7 +1951,7 @@ void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat) float dquat[4]; mat3_to_quat(ob->quat, mat); normalize_qt_qt(dquat, ob->dquat); - invert_qt(dquat); + invert_qt_normalized(dquat); mul_qt_qtqt(ob->quat, dquat, ob->quat); break; } @@ -1963,7 +1963,7 @@ void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat) /* without drot we could apply 'mat' directly */ mat3_to_quat(quat, mat); axis_angle_to_quat(dquat, ob->drotAxis, ob->drotAngle); - invert_qt(dquat); + invert_qt_normalized(dquat); mul_qt_qtqt(quat, dquat, quat); quat_to_axis_angle(ob->rotAxis, &ob->rotAngle, quat); break; @@ -1977,7 +1977,7 @@ void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat) /* without drot we could apply 'mat' directly */ mat3_to_quat(quat, mat); eulO_to_quat(dquat, ob->drot, ob->rotmode); - invert_qt(dquat); + invert_qt_normalized(dquat); mul_qt_qtqt(quat, dquat, quat); quat_to_mat3(tmat, quat); /* end drot correction */ diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index a59a0b73b69..dc6249b6a15 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -894,7 +894,7 @@ void psys_get_birth_coords(ParticleSimulationData *sim, ParticleData *pa, Partic float q_imat[4]; mat4_to_quat(q_obmat, ob->obmat); - invert_qt_qt(q_imat, q_obmat); + invert_qt_qt_normalized(q_imat, q_obmat); if (part->rotmode != PART_ROT_NOR_TAN) { diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h index ac9295c9035..4c4e305c965 100644 --- a/source/blender/blenlib/BLI_math_rotation.h +++ b/source/blender/blenlib/BLI_math_rotation.h @@ -59,6 +59,8 @@ void sub_qt_qtqt(float q[4], const float a[4], const float b[4]); void invert_qt(float q[4]); void invert_qt_qt(float q1[4], const float q2[4]); +void invert_qt_normalized(float q[4]); +void invert_qt_qt_normalized(float q1[4], const float q2[4]); void conjugate_qt(float q[4]); void conjugate_qt_qt(float q1[4], const float q2[4]); float dot_qtqt(const float a[4], const float b[4]); diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 949473a8d86..0ef3f046202 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -154,6 +154,24 @@ void invert_qt_qt(float q1[4], const float q2[4]) invert_qt(q1); } +/** + * This is just conjugate_qt for cases we know \a q is unit-length. + * we could use #conjugate_qt directly, but use this function to show intent, + * and assert if its ever becomes non-unit-length. + */ +void invert_qt_normalized(float q[4]) +{ + BLI_ASSERT_UNIT_QUAT(q); + conjugate_qt(q); + +} + +void invert_qt_qt_normalized(float q1[4], const float q2[4]) +{ + copy_qt_qt(q1, q2); + invert_qt_normalized(q1); +} + /* simple mult */ void mul_qt_fl(float q[4], const float f) { diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 1fa865b585d..4665360d0b8 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -391,14 +391,14 @@ static void view3d_boxview_sync_axis(RegionView3D *rv3d_dst, RegionView3D *rv3d_ if (UNLIKELY(ED_view3d_quat_from_axis_view(rv3d_src->view, viewinv) == false)) { return; } - invert_qt(viewinv); + invert_qt_normalized(viewinv); mul_qt_v3(viewinv, view_src_x); mul_qt_v3(viewinv, view_src_y); if (UNLIKELY(ED_view3d_quat_from_axis_view(rv3d_dst->view, viewinv) == false)) { return; } - invert_qt(viewinv); + invert_qt_normalized(viewinv); mul_qt_v3(viewinv, view_dst_x); mul_qt_v3(viewinv, view_dst_y); @@ -614,10 +614,10 @@ static void view3d_orbit_apply_dyn_ofs( const float oldquat[4], const float viewquat[4]) { float q1[4]; - conjugate_qt_qt(q1, oldquat); + invert_qt_qt_normalized(q1, oldquat); mul_qt_qtqt(q1, q1, viewquat); - conjugate_qt(q1); /* conj == inv for unit quat */ + invert_qt_normalized(q1); sub_v3_v3(r_ofs, dyn_ofs); mul_qt_v3(q1, r_ofs); @@ -931,7 +931,7 @@ static void viewrotate_apply_snap(ViewOpsData *vod) int x, y, z; bool found = false; - invert_qt_qt(viewquat_inv, vod->viewquat); + invert_qt_qt_normalized(viewquat_inv, vod->viewquat); mul_qt_v3(viewquat_inv, zaxis); normalize_v3(zaxis); @@ -969,11 +969,11 @@ static void viewrotate_apply_snap(ViewOpsData *vod) normalize_qt(viewquat_align); mul_qt_qtqt(viewquat_align, vod->viewquat, viewquat_align); normalize_qt(viewquat_align); - invert_qt_qt(viewquat_align_inv, viewquat_align); + invert_qt_qt_normalized(viewquat_align_inv, viewquat_align); vec_to_quat(quat_snap, zaxis_best, OB_NEGZ, OB_POSY); - invert_qt(quat_snap); normalize_qt(quat_snap); + invert_qt_normalized(quat_snap); /* check if we can find the roll */ found = false; @@ -992,7 +992,7 @@ static void viewrotate_apply_snap(ViewOpsData *vod) normalize_qt(quat_final); /* compare 2 vector angles to find the least roll */ - invert_qt_qt(quat_final_inv, quat_final); + invert_qt_qt_normalized(quat_final_inv, quat_final); mul_qt_v3(viewquat_align_inv, xaxis1); mul_qt_v3(quat_final_inv, xaxis2); angle = angle_v3v3(xaxis1, xaxis2); @@ -1356,7 +1356,7 @@ static float view3d_ndof_pan_speed_calc_from_dist(RegionView3D *rv3d, const floa #if 0 mul_mat3_m4_v3(rv3d->viewinv, tvec); #else - invert_qt_qt(viewinv, rv3d->viewquat); + invert_qt_qt_normalized(viewinv, rv3d->viewquat); mul_qt_v3(viewinv, tvec); #endif @@ -1425,7 +1425,7 @@ static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, ScrArea *s mul_v3_fl(pan_vec, speed * ndof->dt); /* transform motion from view to world coordinates */ - invert_qt_qt(view_inv, rv3d->viewquat); + invert_qt_qt_normalized(view_inv, rv3d->viewquat); mul_qt_v3(view_inv, pan_vec); /* move center of view opposite of hand motion (this is camera mode, not object mode) */ @@ -1453,7 +1453,7 @@ static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof, ScrArea *sa, rv3d->view = RV3D_VIEW_USER; - invert_qt_qt(view_inv, rv3d->viewquat); + invert_qt_qt_normalized(view_inv, rv3d->viewquat); if (U.ndof_flag & NDOF_TURNTABLE) { float rot[3]; @@ -1522,7 +1522,7 @@ void view3d_ndof_fly( bool has_rotate = NDOF_HAS_ROTATE; float view_inv[4]; - invert_qt_qt(view_inv, rv3d->viewquat); + invert_qt_qt_normalized(view_inv, rv3d->viewquat); rv3d->rot_angle = 0.0f; /* disable onscreen rotation doo-dad */ @@ -1595,7 +1595,7 @@ void view3d_ndof_fly( float view_direction[3] = {0.0f, 0.0f, -1.0f}; /* view -z (into screen) */ /* find new inverse since viewquat has changed */ - invert_qt_qt(view_inv, rv3d->viewquat); + invert_qt_qt_normalized(view_inv, rv3d->viewquat); /* could apply reverse rotation to existing view_inv to save a few cycles */ /* transform view vectors to world coordinates */ @@ -3762,7 +3762,7 @@ static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar, ED_getTransformOrientationMatrix(C, twmat, V3D_ACTIVE); mat3_to_quat(obact_quat, twmat); - invert_qt(obact_quat); + invert_qt_normalized(obact_quat); mul_qt_qtqt(quat, quat, obact_quat); rv3d->view = view = RV3D_VIEW_USER; @@ -4999,7 +4999,7 @@ void ED_view3d_distance_set(RegionView3D *rv3d, const float dist) #if 0 mul_mat3_m4_v3(rv3d->viewinv, tvec); #else - invert_qt_qt(viewinv, rv3d->viewquat); + invert_qt_qt_normalized(viewinv, rv3d->viewquat); mul_qt_v3(viewinv, tvec); #endif sub_v3_v3(rv3d->ofs, tvec); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 0f05f4e52dd..e3736d90232 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -255,8 +255,8 @@ void ED_view3d_smooth_view_ex( float vec1[3] = {0, 0, 1}, vec2[3] = {0, 0, 1}; float q1[4], q2[4]; - invert_qt_qt(q1, sms.dst.quat); - invert_qt_qt(q2, sms.src.quat); + invert_qt_qt_normalized(q1, sms.dst.quat); + invert_qt_qt_normalized(q2, sms.src.quat); mul_qt_v3(q1, vec1); mul_qt_v3(q2, vec2); |