Rotate gizmo oriented in the current instance reference system for single volume rotations

This commit is contained in:
Enrico Turri 2019-01-10 13:13:11 +01:00
parent 107152b25e
commit 5f9d36e5b0
4 changed files with 37 additions and 28 deletions

View file

@ -2957,14 +2957,14 @@ bool GLCanvas3D::Gizmos::grabber_contains_mouse() const
return (curr != nullptr) ? (curr->get_hover_id() != -1) : false;
}
void GLCanvas3D::Gizmos::update(const Linef3& mouse_ray, bool shift_down, const Point* mouse_pos)
void GLCanvas3D::Gizmos::update(const Linef3& mouse_ray, const Selection& selection, bool shift_down, const Point* mouse_pos)
{
if (!m_enabled)
return;
GLGizmoBase* curr = _get_current();
if (curr != nullptr)
curr->update(GLGizmoBase::UpdateData(mouse_ray, mouse_pos, shift_down));
curr->update(GLGizmoBase::UpdateData(mouse_ray, mouse_pos, shift_down), selection);
}
GLCanvas3D::Gizmos::EType GLCanvas3D::Gizmos::get_current_type() const
@ -5168,7 +5168,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
m_canvas->CaptureMouse();
m_mouse.dragging = true;
m_gizmos.update(mouse_ray(pos), evt.ShiftDown(), &pos);
m_gizmos.update(mouse_ray(pos), m_selection, evt.ShiftDown(), &pos);
switch (m_gizmos.get_current_type())
{

View file

@ -675,7 +675,7 @@ private:
bool overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const;
bool grabber_contains_mouse() const;
void update(const Linef3& mouse_ray, bool shift_down, const Point* mouse_pos = nullptr);
void update(const Linef3& mouse_ray, const Selection& selection, bool shift_down, const Point* mouse_pos = nullptr);
Rect get_reset_rect_viewport(const GLCanvas3D& canvas) const;
EType get_current_type() const;

View file

@ -228,10 +228,10 @@ void GLGizmoBase::stop_dragging()
on_stop_dragging();
}
void GLGizmoBase::update(const UpdateData& data)
void GLGizmoBase::update(const UpdateData& data, const GLCanvas3D::Selection& selection)
{
if (m_hover_id != -1)
on_update(data);
on_update(data, selection);
}
float GLGizmoBase::picking_color_component(unsigned int id) const
@ -368,9 +368,9 @@ void GLGizmoRotate::on_start_dragging(const GLCanvas3D::Selection& selection)
m_snap_fine_out_radius = m_snap_fine_in_radius + m_radius * ScaleLongTooth;
}
void GLGizmoRotate::on_update(const UpdateData& data)
void GLGizmoRotate::on_update(const UpdateData& data, const GLCanvas3D::Selection& selection)
{
Vec2d mouse_pos = to_2d(mouse_position_in_local_plane(data.mouse_ray));
Vec2d mouse_pos = to_2d(mouse_position_in_local_plane(data.mouse_ray, selection));
Vec2d orig_dir = Vec2d::UnitX();
Vec2d new_dir = mouse_pos.normalized();
@ -442,7 +442,7 @@ void GLGizmoRotate::on_render(const GLCanvas3D::Selection& selection) const
::glEnable(GL_DEPTH_TEST);
::glPushMatrix();
transform_to_local();
transform_to_local(selection);
::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f);
::glColor3fv((m_hover_id != -1) ? m_drag_color : m_highlight_color);
@ -473,7 +473,7 @@ void GLGizmoRotate::on_render_for_picking(const GLCanvas3D::Selection& selection
::glPushMatrix();
transform_to_local();
transform_to_local(selection);
const BoundingBoxf3& box = selection.get_bounding_box();
render_grabbers_for_picking(box);
@ -635,10 +635,16 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
::glDisable(GL_LIGHTING);
}
void GLGizmoRotate::transform_to_local() const
void GLGizmoRotate::transform_to_local(const GLCanvas3D::Selection& selection) const
{
::glTranslated(m_center(0), m_center(1), m_center(2));
if (selection.is_single_volume() || selection.is_single_modifier())
{
Transform3d orient_matrix = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true);
::glMultMatrixd(orient_matrix.data());
}
switch (m_axis)
{
case X:
@ -662,7 +668,7 @@ void GLGizmoRotate::transform_to_local() const
}
}
Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) const
Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, const GLCanvas3D::Selection& selection) const
{
double half_pi = 0.5 * (double)PI;
@ -690,6 +696,9 @@ Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) cons
}
}
if (selection.is_single_volume() || selection.is_single_modifier())
m = m * selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true).inverse();
m.translate(-m_center);
return transform(mouse_ray, m).intersect_plane(0.0);
@ -841,7 +850,7 @@ void GLGizmoScale3D::on_start_dragging(const GLCanvas3D::Selection& selection)
}
}
void GLGizmoScale3D::on_update(const UpdateData& data)
void GLGizmoScale3D::on_update(const UpdateData& data, const GLCanvas3D::Selection& selection)
{
if ((m_hover_id == 0) || (m_hover_id == 1))
do_scale_x(data);
@ -1209,7 +1218,7 @@ void GLGizmoMove3D::on_stop_dragging()
m_displacement = Vec3d::Zero();
}
void GLGizmoMove3D::on_update(const UpdateData& data)
void GLGizmoMove3D::on_update(const UpdateData& data, const GLCanvas3D::Selection& selection)
{
if (m_hover_id == 0)
m_displacement(0) = calc_projection(data);
@ -2137,7 +2146,7 @@ void GLGizmoSlaSupports::delete_current_grabber(bool delete_all)
m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
}
void GLGizmoSlaSupports::on_update(const UpdateData& data)
void GLGizmoSlaSupports::on_update(const UpdateData& data, const GLCanvas3D::Selection& selection)
{
if (m_hover_id != -1 && data.mouse_pos) {
Vec3f new_pos;
@ -2379,7 +2388,7 @@ void GLGizmoCut::on_start_dragging(const GLCanvas3D::Selection& selection)
m_drag_center(2) = m_cut_z;
}
void GLGizmoCut::on_update(const UpdateData& data)
void GLGizmoCut::on_update(const UpdateData& data, const GLCanvas3D::Selection& selection)
{
if (m_hover_id != -1) {
set_cut_z(m_start_z + calc_projection(data.mouse_ray));

View file

@ -134,7 +134,7 @@ public:
void stop_dragging();
bool is_dragging() const { return m_dragging; }
void update(const UpdateData& data);
void update(const UpdateData& data, const GLCanvas3D::Selection& selection);
void render(const GLCanvas3D::Selection& selection) const { on_render(selection); }
void render_for_picking(const GLCanvas3D::Selection& selection) const { on_render_for_picking(selection); }
@ -158,7 +158,7 @@ protected:
virtual void on_disable_grabber(unsigned int id) {}
virtual void on_start_dragging(const GLCanvas3D::Selection& selection) {}
virtual void on_stop_dragging() {}
virtual void on_update(const UpdateData& data) = 0;
virtual void on_update(const UpdateData& data, const GLCanvas3D::Selection& selection) = 0;
virtual void on_render(const GLCanvas3D::Selection& selection) const = 0;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const = 0;
@ -221,7 +221,7 @@ protected:
virtual bool on_init();
virtual std::string on_get_name() const { return ""; }
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
virtual void on_update(const UpdateData& data);
virtual void on_update(const UpdateData& data, const GLCanvas3D::Selection& selection);
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
@ -234,9 +234,9 @@ private:
void render_grabber(const BoundingBoxf3& box) const;
void render_grabber_extension(const BoundingBoxf3& box, bool picking) const;
void transform_to_local() const;
void transform_to_local(const GLCanvas3D::Selection& selection) const;
// returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate
Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray) const;
Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray, const GLCanvas3D::Selection& selection) const;
};
class GLGizmoRotate3D : public GLGizmoBase
@ -279,11 +279,11 @@ protected:
}
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
virtual void on_stop_dragging();
virtual void on_update(const UpdateData& data)
virtual void on_update(const UpdateData& data, const GLCanvas3D::Selection& selection)
{
for (GLGizmoRotate& g : m_gizmos)
{
g.update(data);
g.update(data, selection);
}
}
virtual void on_render(const GLCanvas3D::Selection& selection) const;
@ -328,7 +328,7 @@ protected:
virtual std::string on_get_name() const;
virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const { return !selection.is_wipe_tower(); }
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
virtual void on_update(const UpdateData& data);
virtual void on_update(const UpdateData& data, const GLCanvas3D::Selection& selection);
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
@ -375,7 +375,7 @@ protected:
virtual std::string on_get_name() const;
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
virtual void on_stop_dragging();
virtual void on_update(const UpdateData& data);
virtual void on_update(const UpdateData& data, const GLCanvas3D::Selection& selection);
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
@ -425,7 +425,7 @@ protected:
virtual std::string on_get_name() const;
virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const;
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
virtual void on_update(const UpdateData& data) {}
virtual void on_update(const UpdateData& data, const GLCanvas3D::Selection& selection) {}
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
virtual void on_set_state()
@ -481,7 +481,7 @@ public:
private:
bool on_init();
void on_update(const UpdateData& data);
void on_update(const UpdateData& data, const GLCanvas3D::Selection& selection);
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
@ -553,7 +553,7 @@ protected:
virtual void on_set_state();
virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const;
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
virtual void on_update(const UpdateData& data);
virtual void on_update(const UpdateData& data, const GLCanvas3D::Selection& selection);
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;