diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-02-25 16:58:35 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-02-25 17:37:49 +0300 |
commit | 86c0ee80209cdd52e4b360ffcf854144922ac2e6 (patch) | |
tree | 722f7ddcfaa702cf834d4fe2b8d63f1a2638398c /source/blender/blenkernel | |
parent | 213ac7b1aceea3b5a210e86a07402d4415c9a6b6 (diff) |
3D View: support for editing cursor rotation
Add buttons for editing the cursor rotation as well as rotation modes,
similar to object and pose bones.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_scene.h | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 99 |
2 files changed, 105 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index 7638f8c95d5..a0525a4e9f7 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -36,6 +36,7 @@ struct RenderData; struct Scene; struct TransformOrientation; struct UnitSettings; +struct View3DCursor; struct ViewLayer; struct ViewRender; struct WorkSpace; @@ -201,6 +202,12 @@ struct TransformOrientation *BKE_scene_transform_orientation_find( int BKE_scene_transform_orientation_get_index( const struct Scene *scene, const struct TransformOrientation *orientation); +void BKE_scene_cursor_rot_to_mat3(const struct View3DCursor *cursor, float mat[3][3]); +void BKE_scene_cursor_mat3_to_rot(struct View3DCursor *cursor, const float mat[3][3], bool use_compat); + +void BKE_scene_cursor_rot_to_quat(const struct View3DCursor *cursor, float quat[4]); +void BKE_scene_cursor_quat_to_rot(struct View3DCursor *cursor, const float quat[4], bool use_compat); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index b055c3695bc..c73c6ef6ac2 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -547,7 +547,10 @@ void BKE_scene_init(Scene *sce) BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(sce, id)); - unit_qt(sce->cursor.rotation); + + sce->cursor.rotation_mode = ROT_MODE_XYZ; + sce->cursor.rotation_quaternion[0] = 1.0f; + sce->cursor.rotation_axis[1] = 1.0f; sce->r.mode = R_OSA; sce->r.cfra = 1; @@ -2242,3 +2245,97 @@ int BKE_scene_transform_orientation_get_index( } /** \} */ + + +/* -------------------------------------------------------------------- */ +/** \name Scene Cursor Rotation + * + * Matches #BKE_object_rot_to_mat3 and #BKE_object_mat3_to_rot. + * \{ */ + +void BKE_scene_cursor_rot_to_mat3(const View3DCursor *cursor, float mat[3][3]) +{ + if (cursor->rotation_mode > 0) { + eulO_to_mat3(mat, cursor->rotation_euler, cursor->rotation_mode); + } + else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) { + axis_angle_to_mat3(mat, cursor->rotation_axis, cursor->rotation_angle); + } + else { + float tquat[4]; + normalize_qt_qt(tquat, cursor->rotation_quaternion); + quat_to_mat3(mat, tquat); + } +} + +void BKE_scene_cursor_rot_to_quat(const View3DCursor *cursor, float quat[4]) +{ + if (cursor->rotation_mode > 0) { + eulO_to_quat(quat, cursor->rotation_euler, cursor->rotation_mode); + } + else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) { + axis_angle_to_quat(quat, cursor->rotation_axis, cursor->rotation_angle); + } + else { + normalize_qt_qt(quat, cursor->rotation_quaternion); + } +} + +void BKE_scene_cursor_mat3_to_rot(View3DCursor *cursor, const float mat[3][3], bool use_compat) +{ + BLI_ASSERT_UNIT_M3(mat); + + switch (cursor->rotation_mode) { + case ROT_MODE_QUAT: + { + mat3_normalized_to_quat(cursor->rotation_quaternion, mat); + break; + } + case ROT_MODE_AXISANGLE: + { + mat3_to_axis_angle(cursor->rotation_axis, &cursor->rotation_angle, mat); + break; + } + default: + { + if (use_compat) { + mat3_to_compatible_eulO(cursor->rotation_euler, cursor->rotation_euler, cursor->rotation_mode, mat); + } + else { + mat3_to_eulO(cursor->rotation_euler, cursor->rotation_mode, mat); + } + break; + } + } +} + +void BKE_scene_cursor_quat_to_rot(View3DCursor *cursor, const float quat[4], bool use_compat) +{ + BLI_ASSERT_UNIT_QUAT(quat); + + switch (cursor->rotation_mode) { + case ROT_MODE_QUAT: + { + copy_qt_qt(cursor->rotation_quaternion, quat); + break; + } + case ROT_MODE_AXISANGLE: + { + quat_to_axis_angle(cursor->rotation_axis, &cursor->rotation_angle, quat); + break; + } + default: + { + if (use_compat) { + quat_to_compatible_eulO(cursor->rotation_euler, cursor->rotation_euler, cursor->rotation_mode, quat); + } + else { + quat_to_eulO(cursor->rotation_euler, cursor->rotation_mode, quat); + } + break; + } + } +} + + +/** \} */ |