Keep fixed radius of rotate gizmo

This commit is contained in:
Enrico Turri 2018-07-12 11:26:13 +02:00
parent 1356a9977e
commit 0e9ac1679f
5 changed files with 72 additions and 2 deletions

View file

@ -1291,6 +1291,16 @@ void GLCanvas3D::Gizmos::update(const Pointf& mouse_pos)
curr->update(mouse_pos);
}
void GLCanvas3D::Gizmos::refresh()
{
if (!m_enabled)
return;
GLGizmoBase* curr = _get_current();
if (curr != nullptr)
curr->refresh();
}
GLCanvas3D::Gizmos::EType GLCanvas3D::Gizmos::get_current_type() const
{
return m_current;
@ -1321,6 +1331,9 @@ void GLCanvas3D::Gizmos::start_dragging()
void GLCanvas3D::Gizmos::stop_dragging()
{
m_dragging = false;
GLGizmoBase* curr = _get_current();
if (curr != nullptr)
curr->stop_dragging();
}
float GLCanvas3D::Gizmos::get_scale() const
@ -2853,6 +2866,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
}
update_gizmos_data();
m_gizmos.refresh();
m_dirty = true;
}
}
@ -2942,6 +2956,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
}
m_mouse.drag.start_position_3D = cur_pos;
m_gizmos.refresh();
m_dirty = true;
}
@ -3002,6 +3017,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
m_on_update_geometry_info_callback.call(size.x, size.y, size.z, m_gizmos.get_scale());
}
if (volumes.size() > 1)
m_gizmos.refresh();
m_dirty = true;
}
else if (evt.Dragging() && !gizmos_overlay_contains_mouse)

View file

@ -365,6 +365,7 @@ public:
bool overlay_contains_mouse(const GLCanvas3D& canvas, const Pointf& mouse_pos) const;
bool grabber_contains_mouse() const;
void update(const Pointf& mouse_pos);
void refresh();
EType get_current_type() const;

View file

@ -100,6 +100,7 @@ std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool exten
for (GLint i = 0; i < num_extensions; ++i)
{
const char* e = (const char*)::glGetStringi(GL_EXTENSIONS, i);
if (e != nullptr)
extensions_list.push_back(e);
}

View file

@ -90,6 +90,7 @@ GLGizmoBase::EState GLGizmoBase::get_state() const
void GLGizmoBase::set_state(GLGizmoBase::EState state)
{
m_state = state;
on_set_state();
}
unsigned int GLGizmoBase::get_texture_id() const
@ -118,12 +119,22 @@ void GLGizmoBase::start_dragging()
on_start_dragging();
}
void GLGizmoBase::stop_dragging()
{
on_stop_dragging();
}
void GLGizmoBase::update(const Pointf& mouse_pos)
{
if (m_hover_id != -1)
on_update(mouse_pos);
}
void GLGizmoBase::refresh()
{
on_refresh();
}
void GLGizmoBase::render(const BoundingBoxf3& box) const
{
on_render(box);
@ -134,8 +145,24 @@ void GLGizmoBase::render_for_picking(const BoundingBoxf3& box) const
on_render_for_picking(box);
}
void GLGizmoBase::on_set_state()
{
// do nothing
}
void GLGizmoBase::on_start_dragging()
{
// do nothing
}
void GLGizmoBase::on_stop_dragging()
{
// do nothing
}
void GLGizmoBase::on_refresh()
{
// do nothing
}
void GLGizmoBase::render_grabbers() const
@ -162,6 +189,7 @@ GLGizmoRotate::GLGizmoRotate()
, m_angle_z(0.0f)
, m_center(Pointf(0.0, 0.0))
, m_radius(0.0f)
, m_keep_radius(false)
{
}
@ -199,6 +227,11 @@ bool GLGizmoRotate::on_init()
return true;
}
void GLGizmoRotate::on_set_state()
{
m_keep_radius = (m_state == On) ? false : true;
}
void GLGizmoRotate::on_update(const Pointf& mouse_pos)
{
Vectorf orig_dir(1.0, 0.0);
@ -220,13 +253,22 @@ void GLGizmoRotate::on_update(const Pointf& mouse_pos)
m_angle_z = (float)theta;
}
void GLGizmoRotate::on_refresh()
{
m_keep_radius = false;
}
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
{
::glDisable(GL_DEPTH_TEST);
const Pointf3& size = box.size();
m_center = box.center();
if (!m_keep_radius)
{
m_radius = Offset + ::sqrt(sqr(0.5f * size.x) + sqr(0.5f * size.y));
m_keep_radius = true;
}
::glLineWidth(2.0f);
::glColor3fv(BaseColor);

View file

@ -64,15 +64,20 @@ public:
void set_hover_id(int id);
void start_dragging();
void stop_dragging();
void update(const Pointf& mouse_pos);
void refresh();
void render(const BoundingBoxf3& box) const;
void render_for_picking(const BoundingBoxf3& box) const;
protected:
virtual bool on_init() = 0;
virtual void on_set_state();
virtual void on_start_dragging();
virtual void on_stop_dragging();
virtual void on_update(const Pointf& mouse_pos) = 0;
virtual void on_refresh();
virtual void on_render(const BoundingBoxf3& box) const = 0;
virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0;
@ -96,6 +101,7 @@ class GLGizmoRotate : public GLGizmoBase
mutable Pointf m_center;
mutable float m_radius;
mutable bool m_keep_radius;
public:
GLGizmoRotate();
@ -105,7 +111,9 @@ public:
protected:
virtual bool on_init();
virtual void on_set_state();
virtual void on_update(const Pointf& mouse_pos);
virtual void on_refresh();
virtual void on_render(const BoundingBoxf3& box) const;
virtual void on_render_for_picking(const BoundingBoxf3& box) const;