From 2f48997a2201b793fab79e901df1910a8002a6bb Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 15 Jan 2019 12:24:32 +0100 Subject: [PATCH 1/2] Fixed rotation of single volumes inside a rotated instance using rotate gizmo --- src/libslic3r/Geometry.cpp | 20 +++++++++++--------- src/slic3r/GUI/GLCanvas3D.cpp | 3 +-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index 11a9955133..37484de613 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -1182,15 +1182,17 @@ Transform3d assemble_transform(const Vec3d& translation, const Vec3d& rotation, Vec3d extract_euler_angles(const Eigen::Matrix& rotation_matrix) { #if ENABLE_NEW_EULER_ANGLES - bool x_only = (rotation_matrix(0, 0) == 1.0) && (rotation_matrix(0, 1) == 0.0) && (rotation_matrix(0, 2) == 0.0) && (rotation_matrix(1, 0) == 0.0) && (rotation_matrix(2, 0) == 0.0); - bool y_only = (rotation_matrix(0, 1) == 0.0) && (rotation_matrix(1, 0) == 0.0) && (rotation_matrix(1, 1) == 1.0) && (rotation_matrix(1, 2) == 0.0) && (rotation_matrix(2, 1) == 0.0); - bool z_only = (rotation_matrix(0, 2) == 0.0) && (rotation_matrix(1, 2) == 0.0) && (rotation_matrix(2, 0) == 0.0) && (rotation_matrix(2, 1) == 0.0) && (rotation_matrix(2, 2) == 1.0); -// bool xy_only = (rotation_matrix(0, 1) == 0.0); // Rx * Ry - bool yx_only = (rotation_matrix(1, 0) == 0.0); // Ry * Rx -// bool xz_only = (rotation_matrix(0, 2) == 0.0); // Rx * Rz -// bool zx_only = (rotation_matrix(2, 0) == 0.0); // Rz * Rx -// bool yz_only = (rotation_matrix(1, 2) == 0.0); // Ry * Rz -// bool zy_only = (rotation_matrix(2, 1) == 0.0); // Rz * Ry + auto is_approx = [](double value, double test_value) -> bool { return std::abs(value - test_value) < EPSILON; }; + + bool x_only = is_approx(rotation_matrix(0, 0), 1.0) && is_approx(rotation_matrix(0, 1), 0.0) && is_approx(rotation_matrix(0, 2), 0.0) && is_approx(rotation_matrix(1, 0), 0.0) && is_approx(rotation_matrix(2, 0), 0.0); + bool y_only = is_approx(rotation_matrix(0, 1), 0.0) && is_approx(rotation_matrix(1, 0), 0.0) && is_approx(rotation_matrix(1, 1), 1.0) && is_approx(rotation_matrix(1, 2), 0.0) && is_approx(rotation_matrix(2, 1), 0.0); + bool z_only = is_approx(rotation_matrix(0, 2), 0.0) && is_approx(rotation_matrix(1, 2), 0.0) && is_approx(rotation_matrix(2, 0), 0.0) && is_approx(rotation_matrix(2, 1), 0.0) && is_approx(rotation_matrix(2, 2), 1.0); +// bool xy_only = is_approx(rotation_matrix(0, 1), 0.0); // Rx * Ry + bool yx_only = is_approx(rotation_matrix(1, 0), 0.0); // Ry * Rx +// bool xz_only = is_approx(rotation_matrix(0, 2), 0.0); // Rx * Rz +// bool zx_only = is_approx(rotation_matrix(2, 0), 0.0); // Rz * Rx +// bool yz_only = is_approx(rotation_matrix(1, 2), 0.0); // Ry * Rz +// bool zy_only = is_approx(rotation_matrix(2, 1), 0.0); // Rz * Ry Vec3d angles = Vec3d::Zero(); if (x_only || y_only || z_only) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 6ffd0b6211..d5f4808aaf 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1614,8 +1614,7 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local) else { Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation); - const Transform3d& inst_m = m_cache.volumes_data[i].get_instance_rotation_matrix(); - Vec3d new_rotation = Geometry::extract_euler_angles(inst_m.inverse() * m * inst_m * m_cache.volumes_data[i].get_volume_rotation_matrix()); + Vec3d new_rotation = Geometry::extract_euler_angles(m * m_cache.volumes_data[i].get_volume_rotation_matrix()); (*m_volumes)[i]->set_volume_rotation(new_rotation); } } From 4066df2db7cec9a4e1fafdcda9a95914c2e9d767 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 15 Jan 2019 12:59:28 +0100 Subject: [PATCH 2/2] Slightly increased limit for zoom out --- src/slic3r/GUI/GLCanvas3D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index d5f4808aaf..9a2ea4b44c 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5708,7 +5708,7 @@ void GLCanvas3D::set_camera_zoom(float zoom) // Don't allow to zoom too far outside the scene. float zoom_min = _get_zoom_to_bounding_box_factor(_max_bounding_box()); if (zoom_min > 0.0f) - zoom = std::max(zoom, zoom_min * 0.8f); + zoom = std::max(zoom, zoom_min * 0.7f); m_camera.zoom = zoom; viewport_changed();