[Bf-blender-cvs] [046904e3fc6] master: Cleanup: split rotation_from_view
Campbell Barton
noreply at git.blender.org
Sun May 6 18:34:44 CEST 2018
Commit: 046904e3fc6d5a9b10215d97ffc71f08bce37a41
Author: Campbell Barton
Date: Sun May 6 18:32:18 2018 +0200
Branches: master
https://developer.blender.org/rB046904e3fc6d5a9b10215d97ffc71f08bce37a41
Cleanup: split rotation_from_view
Add a function that takes only a quat, instead of the 3D view.
Allows for using non-view orientations.
===================================================================
M source/blender/editors/include/ED_object.h
M source/blender/editors/object/object_add.c
===================================================================
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h
index 11dde2f5913..2087394b6f6 100644
--- a/source/blender/editors/include/ED_object.h
+++ b/source/blender/editors/include/ED_object.h
@@ -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(
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);
More information about the Bf-blender-cvs
mailing list