From cc9cf7f39e2fed77b6b5f76c8225afee873e11ab Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 23 Jan 2019 11:08:18 +0100 Subject: [PATCH] Fixed unselected instance synchronization when rotating using rotate gizmo --- src/libslic3r/Geometry.cpp | 17 ++++++----------- src/slic3r/GUI/GLCanvas3D.cpp | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index c84169676..db64f97a7 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -1189,17 +1189,12 @@ Vec3d extract_euler_angles(const Eigen::Matrix& Vec3d angles2 = Vec3d::Zero(); if (is_approx(std::abs(rotation_matrix(2, 0)), 1.0)) { - angles1(2) = 0.0; - if (rotation_matrix(2, 0) > 0.0) // == +1.0 - { - angles1(1) = -0.5 * (double)PI; - angles1(0) = -angles1(2) + ::atan2(-rotation_matrix(0, 1), -rotation_matrix(0, 2)); - } - else // == -1.0 - { - angles1(1) = 0.5 * (double)PI; - angles1(0) = angles1(2) + ::atan2(rotation_matrix(0, 1), rotation_matrix(0, 2)); - } + // the handling of singular cases deviates from the cited paper + // the following code works better when rotating an object with the gizmo after having + // changed its orientation using the place on bed gizmo + angles1(0) = 0.0; + angles1(1) = 0.5 * (double)PI; + angles1(2) = angles1(0) + ::atan2(rotation_matrix(0, 1), rotation_matrix(0, 2)); angles2 = angles1; } else diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 42899b96b..47da5574a 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2408,7 +2408,7 @@ void GLCanvas3D::Selection::_update_type() void GLCanvas3D::Selection::_set_caches() { m_cache.volumes_data.clear(); - for (unsigned int i : m_list) + for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) { const GLVolume* v = (*m_volumes)[i]; m_cache.volumes_data.emplace(i, VolumeCache(v->get_volume_transformation(), v->get_instance_transformation())); @@ -2699,7 +2699,7 @@ void GLCanvas3D::Selection::_synchronize_unselected_instances(bool including_z) if ((v->object_idx() != object_idx) || (v->instance_idx() == instance_idx)) continue; - v->set_instance_rotation(Vec3d(rotation(0), rotation(1), including_z ? rotation(2) : v->get_instance_rotation()(2))); + v->set_instance_rotation(Vec3d(rotation(0), rotation(1), including_z ? rotation(2) : m_cache.volumes_data[j].get_instance_rotation()(2) + rotation(2))); v->set_instance_scaling_factor(scaling_factor); v->set_instance_mirror(mirror);