Cleanup: split rotation_from_view
authorCampbell Barton <ideasman42@gmail.com>
Sun, 6 May 2018 16:32:18 +0000 (18:32 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 6 May 2018 16:32:18 +0000 (18:32 +0200)
Add a function that takes only a quat, instead of the 3D view.

Allows for using non-view orientations.

source/blender/editors/include/ED_object.h
source/blender/editors/object/object_add.c

index 11dde2f5913d00265168ca7262e64f1b5c4814aa..2087394b6f68d084d47d69cabc1bbcaa69447c54 100644 (file)
@@ -149,6 +149,7 @@ void ED_object_sculptmode_exit_ex(
 void ED_object_sculptmode_exit(struct bContext *C);
 
 void ED_object_location_from_view(struct bContext *C, float loc[3]);
+void ED_object_rotation_from_quat(float rot[3], const float quat[4], const char align_axis);
 void ED_object_rotation_from_view(struct bContext *C, float rot[3], const char align_axis);
 void ED_object_base_init_transform(struct bContext *C, struct Base *base, const float loc[3], const float rot[3]);
 float ED_object_new_primitive_matrix(
index 461b71a8a05533185fa91c4ef6bccd38e8b23e73..eeeb3c058d090eaa190455403db03fc9d8b37ac1 100644 (file)
@@ -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);