SPE-1439 - Fixed move gizmo orientation when the volume is mirrored

This commit is contained in:
enricoturri1966 2023-05-09 11:14:50 +02:00
parent 03021c0734
commit 04e92cb409
2 changed files with 12 additions and 20 deletions

View File

@ -67,23 +67,10 @@ bool GLGizmoMove3D::on_is_activable() const
void GLGizmoMove3D::on_start_dragging()
{
assert(m_hover_id != -1);
m_displacement = Vec3d::Zero();
const Selection& selection = m_parent.get_selection();
const ECoordinatesType coordinates_type = wxGetApp().obj_manipul()->get_coordinates_type();
if (coordinates_type == ECoordinatesType::World)
m_starting_drag_position = m_center + m_grabbers[m_hover_id].center;
else if (coordinates_type == ECoordinatesType::Local && selection.is_single_volume_or_modifier()) {
const GLVolume& v = *selection.get_first_volume();
m_starting_drag_position = m_center + v.get_instance_transformation().get_rotation_matrix() * v.get_volume_transformation().get_rotation_matrix() * m_grabbers[m_hover_id].center;
}
else {
const GLVolume& v = *selection.get_first_volume();
m_starting_drag_position = m_center + v.get_instance_transformation().get_rotation_matrix() * m_grabbers[m_hover_id].center;
}
m_starting_drag_position = m_grabbers[m_hover_id].matrix * m_grabbers[m_hover_id].center;
m_starting_box_center = m_center;
m_starting_box_bottom_center = m_center;
m_starting_box_bottom_center.z() = m_bounding_box.min.z();
m_starting_box_bottom_center = Vec3d(m_center.x(), m_center.y(), m_bounding_box.min.z());
}
void GLGizmoMove3D::on_stop_dragging()
@ -122,7 +109,8 @@ void GLGizmoMove3D::on_render()
const auto& [box, box_trafo] = selection.get_bounding_box_in_current_reference_system();
m_bounding_box = box;
m_center = box_trafo.translation();
const Transform3d base_matrix = local_transform(m_parent.get_selection());
const Transform3d base_matrix = box_trafo;
for (int i = 0; i < 3; ++i) {
m_grabbers[i].matrix = base_matrix;
}
@ -230,10 +218,12 @@ void GLGizmoMove3D::on_render()
if (shader != nullptr) {
shader->start_using();
shader->set_uniform("emission_factor", 0.1f);
glsafe(::glDisable(GL_CULL_FACE));
// draw grabber
const Vec3d box_size = m_bounding_box.size();
const float mean_size = (float)((box_size.x() + box_size.y() + box_size.z()) / 3.0);
m_grabbers[m_hover_id].render(true, mean_size);
glsafe(::glEnable(GL_CULL_FACE));
shader->stop_using();
}
}

View File

@ -1593,6 +1593,7 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
shader->start_using();
glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glDisable(GL_CULL_FACE));
const Transform3d base_matrix = Geometry::translation_transform(get_bounding_box().center());
Transform3d orient_matrix = Transform3d::Identity();
@ -1603,15 +1604,15 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
if (!boost::starts_with(sidebar_field, "layer")) {
shader->set_uniform("emission_factor", 0.05f);
if (is_single_full_instance() && !wxGetApp().obj_manipul()->is_world_coordinates()) {
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation_matrix();
axes_center = (*m_volumes)[*m_list.begin()]->get_instance_offset();
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation_matrix();
axes_center = (*m_volumes)[*m_list.begin()]->get_instance_offset();
}
else if (is_single_volume_or_modifier()) {
if (!wxGetApp().obj_manipul()->is_world_coordinates()) {
if (wxGetApp().obj_manipul()->is_local_coordinates()) {
const GLVolume* v = (*m_volumes)[*m_list.begin()];
orient_matrix = v->get_instance_transformation().get_rotation_matrix() * v->get_volume_transformation().get_rotation_matrix();
axes_center = (*m_volumes)[*m_list.begin()]->world_matrix().translation();
orient_matrix = get_bounding_box_in_current_reference_system().second;
orient_matrix.translation() = Vec3d::Zero();
}
else {
orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation_matrix();
@ -1645,6 +1646,7 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field)
m_axes.render(Geometry::translation_transform(axes_center) * orient_matrix, 0.25f);
}
glsafe(::glEnable(GL_CULL_FACE));
shader->stop_using();
}