Fix of rotations using sidebar fields

This commit is contained in:
Enrico Turri 2019-01-29 11:26:35 +01:00
parent 8e4934d91d
commit 14fe55d4b8
4 changed files with 22 additions and 10 deletions

View file

@ -1182,8 +1182,6 @@ Vec3d extract_euler_angles(const Eigen::Matrix<double, 3, 3, Eigen::DontAlign>&
{ {
#if ENABLE_NEW_EULER_ANGLES #if ENABLE_NEW_EULER_ANGLES
// reference: http://www.gregslabaugh.net/publications/euler.pdf // 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 angles1 = Vec3d::Zero();
Vec3d angles2 = Vec3d::Zero(); Vec3d angles2 = Vec3d::Zero();
if (is_approx(std::abs(rotation_matrix(2, 0)), 1.0)) if (is_approx(std::abs(rotation_matrix(2, 0)), 1.0))

View file

@ -164,6 +164,12 @@ static inline T lerp(const T& a, const T& b, Number t)
return (Number(1) - t) * a + t * b; return (Number(1) - t) * a + t * b;
} }
template <typename Number>
static inline bool is_approx(Number value, Number test_value)
{
return std::abs(double(value) - double(test_value)) < double(EPSILON);
};
} // namespace Slic3r } // namespace Slic3r
#endif #endif

View file

@ -1820,7 +1820,7 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local)
if (rot_axis_max != 2 && first_volume_idx != -1) { if (rot_axis_max != 2 && first_volume_idx != -1) {
// Generic rotation, but no rotation around the Z axis. // Generic rotation, but no rotation around the Z axis.
// Always do a local rotation (do not consider the selection to be a rigid body). // 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 GLVolume &first_volume = *(*m_volumes)[first_volume_idx];
const Vec3d &rotation = first_volume.get_instance_rotation(); 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()); 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()) else if (is_single_volume() || is_single_modifier())
{ {
if (local) if (local)
volume.set_volume_rotation(rotation); volume.set_volume_rotation(volume.get_volume_rotation() + rotation);
else else
{ {
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation); 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()) 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)); ::glTranslated(center(0), center(1), center(2));
::glMultMatrixd(orient_matrix.data()); ::glMultMatrixd(orient_matrix.data());
} }

View file

@ -345,16 +345,22 @@ void ObjectManipulation::update_if_dirty()
m_cache.size = m_new_size; 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)) 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)) 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)) 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()) { if (wxGetApp().plater()->canvas3D()->get_selection().requires_uniform_scale()) {
m_lock_bnt->SetLock(true); m_lock_bnt->SetLock(true);
@ -400,10 +406,12 @@ void ObjectManipulation::change_rotation_value(const Vec3d& rotation)
GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); GLCanvas3D* canvas = wxGetApp().plater()->canvas3D();
const GLCanvas3D::Selection& selection = canvas->get_selection(); const GLCanvas3D::Selection& selection = canvas->get_selection();
Vec3d delta_rotation = rotation - m_cache.rotation;
Vec3d rad_rotation; Vec3d rad_rotation;
for (size_t i = 0; i < 3; ++i) 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(); canvas->get_selection().start_dragging();