From 14fe55d4b83a3488c775371576407e45bf7848f4 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 29 Jan 2019 11:26:35 +0100 Subject: [PATCH] Fix of rotations using sidebar fields --- src/libslic3r/Geometry.cpp | 2 -- src/libslic3r/libslic3r.h | 6 ++++++ src/slic3r/GUI/GLCanvas3D.cpp | 6 +++--- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 18 +++++++++++++----- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index 58324893d..a9d3be539 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -1182,8 +1182,6 @@ Vec3d extract_euler_angles(const Eigen::Matrix& { #if ENABLE_NEW_EULER_ANGLES // reference: http://www.gregslabaugh.net/publications/euler.pdf - auto is_approx = [](double value, double test_value) -> bool { return std::abs(value - test_value) < EPSILON; }; - Vec3d angles1 = Vec3d::Zero(); Vec3d angles2 = Vec3d::Zero(); if (is_approx(std::abs(rotation_matrix(2, 0)), 1.0)) diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index 19c6d3065..5fd2fafc1 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -164,6 +164,12 @@ static inline T lerp(const T& a, const T& b, Number t) return (Number(1) - t) * a + t * b; } +template +static inline bool is_approx(Number value, Number test_value) +{ + return std::abs(double(value) - double(test_value)) < double(EPSILON); +}; + } // namespace Slic3r #endif diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 107e763c6..3de7d67fa 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1820,7 +1820,7 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local) if (rot_axis_max != 2 && first_volume_idx != -1) { // Generic rotation, but no rotation around the Z axis. // Always do a local rotation (do not consider the selection to be a rigid body). - assert(rotation.z() == 0); + assert(is_approx(rotation.z(), 0.0)); const GLVolume &first_volume = *(*m_volumes)[first_volume_idx]; const Vec3d &rotation = first_volume.get_instance_rotation(); double z_diff = rotation_diff_z(m_cache.volumes_data[first_volume_idx].get_instance_rotation(), m_cache.volumes_data[i].get_instance_rotation()); @@ -1845,7 +1845,7 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local) else if (is_single_volume() || is_single_modifier()) { if (local) - volume.set_volume_rotation(rotation); + volume.set_volume_rotation(volume.get_volume_rotation() + rotation); else { Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation); @@ -2262,7 +2262,7 @@ void GLCanvas3D::Selection::render_sidebar_hints(const std::string& sidebar_fiel } else if (is_single_volume() || is_single_modifier()) { - Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); + Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true) * (*m_volumes)[*m_list.begin()]->get_volume_transformation().get_matrix(true, false, true, true); ::glTranslated(center(0), center(1), center(2)); ::glMultMatrixd(orient_matrix.data()); } diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index b4480f7e6..08829be93 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -345,16 +345,22 @@ void ObjectManipulation::update_if_dirty() m_cache.size = m_new_size; + Vec3d deg_rotation; + for (size_t i = 0; i < 3; ++i) + { + deg_rotation(i) = Geometry::rad2deg(m_new_rotation(i)); + } + if (m_cache.rotation(0) != m_new_rotation(0)) - m_og->set_value("rotation_x", double_to_string(Geometry::rad2deg(m_new_rotation(0)), 2)); + m_og->set_value("rotation_x", double_to_string(deg_rotation(0), 2)); if (m_cache.rotation(1) != m_new_rotation(1)) - m_og->set_value("rotation_y", double_to_string(Geometry::rad2deg(m_new_rotation(1)), 2)); + m_og->set_value("rotation_y", double_to_string(deg_rotation(1), 2)); if (m_cache.rotation(2) != m_new_rotation(2)) - m_og->set_value("rotation_z", double_to_string(Geometry::rad2deg(m_new_rotation(2)), 2)); + m_og->set_value("rotation_z", double_to_string(deg_rotation(2), 2)); - m_cache.rotation = m_new_rotation; + m_cache.rotation = deg_rotation; if (wxGetApp().plater()->canvas3D()->get_selection().requires_uniform_scale()) { m_lock_bnt->SetLock(true); @@ -400,10 +406,12 @@ void ObjectManipulation::change_rotation_value(const Vec3d& rotation) GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); const GLCanvas3D::Selection& selection = canvas->get_selection(); + Vec3d delta_rotation = rotation - m_cache.rotation; + Vec3d rad_rotation; for (size_t i = 0; i < 3; ++i) { - rad_rotation(i) = Geometry::deg2rad(rotation(i)); + rad_rotation(i) = Geometry::deg2rad(delta_rotation(i)); } canvas->get_selection().start_dragging();