From 046904e3fc6d5a9b10215d97ffc71f08bce37a41 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 6 May 2018 18:32:18 +0200 Subject: Cleanup: split rotation_from_view Add a function that takes only a quat, instead of the 3D view. Allows for using non-view orientations. --- source/blender/editors/object/object_add.c | 67 +++++++++++++++--------------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'source/blender/editors/object') diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 461b71a8a05..eeeb3c058d0 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -159,45 +159,44 @@ void ED_object_location_from_view(bContext *C, float loc[3]) copy_v3_v3(loc, cursor); } -void ED_object_rotation_from_view(bContext *C, float rot[3], const char align_axis) +void ED_object_rotation_from_quat(float rot[3], const float viewquat[4], const char align_axis) { - RegionView3D *rv3d = CTX_wm_region_view3d(C); - BLI_assert(align_axis >= 'X' && align_axis <= 'Z'); - if (rv3d) { - float quat[4]; - - switch (align_axis) { - case 'X': - { - float quat_y[4]; - axis_angle_to_quat(quat_y, rv3d->viewinv[1], -M_PI_2); - mul_qt_qtqt(quat, rv3d->viewquat, quat_y); - quat[0] = -quat[0]; - - quat_to_eul(rot, quat); - break; - } - case 'Y': - { - copy_qt_qt(quat, rv3d->viewquat); - quat[0] = -quat[0]; - - quat_to_eul(rot, quat); - rot[0] -= (float)M_PI_2; - break; - } - case 'Z': - { - copy_qt_qt(quat, rv3d->viewquat); - quat[0] = -quat[0]; - - quat_to_eul(rot, quat); - break; - } + switch (align_axis) { + case 'X': + { + /* Same as 'rv3d->viewinv[1]' */ + float axis_y[4] = {0.0f, 1.0f, 0.0f}; + float quat_y[4], quat[4]; + axis_angle_to_quat(quat_y, axis_y, M_PI_2); + mul_qt_qtqt(quat, viewquat, quat_y); + quat_to_eul(rot, quat); + break; + } + case 'Y': + { + quat_to_eul(rot, viewquat); + rot[0] -= (float)M_PI_2; + break; } + case 'Z': + { + quat_to_eul(rot, viewquat); + break; + } + } +} +void ED_object_rotation_from_view(bContext *C, float rot[3], const char align_axis) +{ + RegionView3D *rv3d = CTX_wm_region_view3d(C); + BLI_assert(align_axis >= 'X' && align_axis <= 'Z'); + if (rv3d) { + float viewquat[4]; + copy_qt_qt(viewquat, rv3d->viewquat); + viewquat[0] *= -1.0f; + ED_object_rotation_from_quat(rot, viewquat, align_axis); } else { zero_v3(rot); -- cgit v1.2.3