Gizmo rotate operates always in world reference system

This commit is contained in:
Enrico Turri 2018-11-21 09:28:27 +01:00
parent 4cb5c2a21b
commit d8e7310d72
4 changed files with 47 additions and 0 deletions

View file

@ -29,6 +29,8 @@
#define ENABLE_GIZMOS_ON_TOP (1 && ENABLE_1_42_0)
// New menu layout (open/save/save as project + import/export)
#define ENABLE_NEW_MENU_LAYOUT (1 && ENABLE_1_42_0)
// All rotations made using the rotate gizmo are done with respect to the world reference system
#define ENABLE_WORLD_ROTATIONS (1 && ENABLE_1_42_0)
#endif // _technologies_h_

View file

@ -1461,14 +1461,30 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local)
for (unsigned int i : m_list)
{
if (is_single_full_instance())
#if ENABLE_WORLD_ROTATIONS
{
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation);
Vec3d new_rotation = Geometry::extract_euler_angles(m * m_cache.volumes_data[i].get_instance_rotation_matrix());
(*m_volumes)[i]->set_instance_rotation(new_rotation);
}
#else
#if ENABLE_MODELVOLUME_TRANSFORM
(*m_volumes)[i]->set_instance_rotation(rotation);
#else
(*m_volumes)[i]->set_rotation(rotation);
#endif // ENABLE_MODELVOLUME_TRANSFORM
#endif // ENABLE_WORLD_ROTATIONS
#if ENABLE_MODELVOLUME_TRANSFORM
else if (is_single_volume() || is_single_modifier())
#if ENABLE_WORLD_ROTATIONS
{
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation);
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);
}
#else
(*m_volumes)[i]->set_volume_rotation(rotation);
#endif // ENABLE_WORLD_ROTATIONS
#endif // ENABLE_MODELVOLUME_TRANSFORM
else
{
@ -4652,6 +4668,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
break;
}
m_gizmos.stop_dragging();
#if ENABLE_WORLD_ROTATIONS
_update_gizmos_data();
#endif // ENABLE_WORLD_ROTATIONS
wxGetApp().obj_manipul()->update_settings_value(m_selection);
}
@ -5443,7 +5462,11 @@ void GLCanvas3D::_update_gizmos_data()
// all volumes in the selection belongs to the same instance, any of them contains the needed data, so we take the first
const GLVolume* volume = m_volumes.volumes[*m_selection.get_volume_idxs().begin()];
m_gizmos.set_scale(volume->get_instance_scaling_factor());
#if ENABLE_WORLD_ROTATIONS
m_gizmos.set_rotation(Vec3d::Zero());
#else
m_gizmos.set_rotation(volume->get_instance_rotation());
#endif // ENABLE_WORLD_ROTATIONS
ModelObject* model_object = m_model->objects[m_selection.get_object_idx()];
m_gizmos.set_flattening_data(model_object);
m_gizmos.set_model_object_ptr(model_object);
@ -5451,7 +5474,11 @@ void GLCanvas3D::_update_gizmos_data()
ModelObject* model_object = m_model->objects[m_selection.get_object_idx()];
ModelInstance* model_instance = model_object->instances[m_selection.get_instance_idx()];
m_gizmos.set_scale(model_instance->get_scaling_factor());
#if ENABLE_WORLD_ROTATIONS
m_gizmos.set_rotation(Vec3d::Zero());
#else
m_gizmos.set_rotation(model_instance->get_rotation());
#endif // ENABLE_WORLD_ROTATIONS
m_gizmos.set_flattening_data(model_object);
m_gizmos.set_model_object_ptr(model_object);
#endif // ENABLE_MODELVOLUME_TRANSFORM
@ -5461,7 +5488,11 @@ void GLCanvas3D::_update_gizmos_data()
{
const GLVolume* volume = m_volumes.volumes[*m_selection.get_volume_idxs().begin()];
m_gizmos.set_scale(volume->get_volume_scaling_factor());
#if ENABLE_WORLD_ROTATIONS
m_gizmos.set_rotation(Vec3d::Zero());
#else
m_gizmos.set_rotation(volume->get_volume_rotation());
#endif // ENABLE_WORLD_ROTATIONS
m_gizmos.set_flattening_data(nullptr);
m_gizmos.set_model_object_ptr(nullptr);
}

View file

@ -367,7 +367,9 @@ void GLGizmoRotate::on_render(const GLCanvas3D::Selection& selection) const
return;
const BoundingBoxf3& box = selection.get_bounding_box();
#if !ENABLE_WORLD_ROTATIONS
bool single_selection = selection.is_single_full_instance() || selection.is_single_modifier() || selection.is_single_volume();
#endif // !ENABLE_WORLD_ROTATIONS
std::string axis;
switch (m_axis)
@ -377,7 +379,11 @@ void GLGizmoRotate::on_render(const GLCanvas3D::Selection& selection) const
case Z: { axis = "Z: "; break; }
}
#if ENABLE_WORLD_ROTATIONS
if (m_dragging)
#else
if ((single_selection && (m_hover_id == 0)) || m_dragging)
#endif // ENABLE_WORLD_ROTATIONS
set_tooltip(axis + format((float)Geometry::rad2deg(m_angle), 4) + "\u00B0");
else
{
@ -517,7 +523,11 @@ void GLGizmoRotate::render_angle() const
void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const
{
#if ENABLE_WORLD_ROTATIONS
double grabber_radius = (double)m_radius * (1.0 + (double)GrabberOffset);
#else
double grabber_radius = (double)m_radius * (1.0 + (double)GrabberOffset) + 2.0 * (double)m_axis * (double)m_grabbers[0].get_half_size((float)box.max_size());
#endif // ENABLE_WORLD_ROTATIONS
m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0);
m_grabbers[0].angles(2) = m_angle;

View file

@ -199,7 +199,9 @@ protected:
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
virtual void on_update(const UpdateData& data);
#if ENABLE_GIZMOS_RESET
#if !ENABLE_WORLD_ROTATIONS
virtual void on_process_double_click() { m_angle = 0.0; }
#endif // !ENABLE_WORLD_ROTATIONS
#endif // ENABLE_GIZMOS_RESET
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
@ -265,11 +267,13 @@ protected:
}
}
#if ENABLE_GIZMOS_RESET
#if !ENABLE_WORLD_ROTATIONS
virtual void on_process_double_click()
{
if (m_hover_id != -1)
m_gizmos[m_hover_id].process_double_click();
}
#endif // !ENABLE_WORLD_ROTATIONS
#endif // ENABLE_GIZMOS_RESET
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const