Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / object / object_add.c
index 7327c5631049a8514e90747979fc93862f30ae58..c2934b916d0313a30004bac3854e2e57f795b431 100644 (file)
@@ -170,45 +170,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);