Temporary remove not yet supported transformations from 3D gizmos

This commit is contained in:
Enrico Turri 2018-09-11 12:40:42 +02:00
parent 4479c5444a
commit a97df55592
3 changed files with 86 additions and 17 deletions

View File

@ -1140,6 +1140,9 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
if (!gizmo->init()) if (!gizmo->init())
return false; return false;
// temporary disable z grabber
gizmo->disable_grabber(2);
m_gizmos.insert(GizmosMap::value_type(Move, gizmo)); m_gizmos.insert(GizmosMap::value_type(Move, gizmo));
gizmo = new GLGizmoScale3D(parent); gizmo = new GLGizmoScale3D(parent);
@ -1149,6 +1152,16 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
if (!gizmo->init()) if (!gizmo->init())
return false; return false;
// temporary disable x grabbers
gizmo->disable_grabber(0);
gizmo->disable_grabber(1);
// temporary disable y grabbers
gizmo->disable_grabber(2);
gizmo->disable_grabber(3);
// temporary disable z grabbers
gizmo->disable_grabber(4);
gizmo->disable_grabber(5);
m_gizmos.insert(GizmosMap::value_type(Scale, gizmo)); m_gizmos.insert(GizmosMap::value_type(Scale, gizmo));
gizmo = new GLGizmoRotate3D(parent); gizmo = new GLGizmoRotate3D(parent);
@ -1164,6 +1177,10 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
return false; return false;
} }
// temporary disable x and y grabbers
gizmo->disable_grabber(0);
gizmo->disable_grabber(1);
m_gizmos.insert(GizmosMap::value_type(Rotate, gizmo)); m_gizmos.insert(GizmosMap::value_type(Rotate, gizmo));
gizmo = new GLGizmoFlatten(parent); gizmo = new GLGizmoFlatten(parent);

View File

@ -110,6 +110,7 @@ GLGizmoBase::Grabber::Grabber()
: center(Vec3d::Zero()) : center(Vec3d::Zero())
, angles(Vec3d::Zero()) , angles(Vec3d::Zero())
, dragging(false) , dragging(false)
, enabled(true)
{ {
color[0] = 1.0f; color[0] = 1.0f;
color[1] = 1.0f; color[1] = 1.0f;
@ -234,6 +235,22 @@ void GLGizmoBase::set_highlight_color(const float* color)
::memcpy((void*)m_highlight_color, (const void*)color, 3 * sizeof(float)); ::memcpy((void*)m_highlight_color, (const void*)color, 3 * sizeof(float));
} }
void GLGizmoBase::enable_grabber(unsigned int id)
{
if ((0 <= id) && (id < (unsigned int)m_grabbers.size()))
m_grabbers[id].enabled = true;
on_enable_grabber(id);
}
void GLGizmoBase::disable_grabber(unsigned int id)
{
if ((0 <= id) && (id < (unsigned int)m_grabbers.size()))
m_grabbers[id].enabled = false;
on_disable_grabber(id);
}
void GLGizmoBase::start_dragging(const BoundingBoxf3& box) void GLGizmoBase::start_dragging(const BoundingBoxf3& box)
{ {
m_dragging = true; m_dragging = true;
@ -278,6 +295,7 @@ void GLGizmoBase::render_grabbers() const
{ {
for (int i = 0; i < (int)m_grabbers.size(); ++i) for (int i = 0; i < (int)m_grabbers.size(); ++i)
{ {
if (m_grabbers[i].enabled)
m_grabbers[i].render(m_hover_id == i); m_grabbers[i].render(m_hover_id == i);
} }
} }
@ -285,12 +303,15 @@ void GLGizmoBase::render_grabbers() const
void GLGizmoBase::render_grabbers_for_picking() const void GLGizmoBase::render_grabbers_for_picking() const
{ {
for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i)
{
if (m_grabbers[i].enabled)
{ {
m_grabbers[i].color[0] = 1.0f; m_grabbers[i].color[0] = 1.0f;
m_grabbers[i].color[1] = 1.0f; m_grabbers[i].color[1] = 1.0f;
m_grabbers[i].color[2] = picking_color_component(i); m_grabbers[i].color[2] = picking_color_component(i);
m_grabbers[i].render_for_picking(); m_grabbers[i].render_for_picking();
} }
}
} }
void GLGizmoBase::set_tooltip(const std::string& tooltip) const void GLGizmoBase::set_tooltip(const std::string& tooltip) const
@ -386,6 +407,9 @@ void GLGizmoRotate::on_update(const Linef3& mouse_ray)
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
{ {
if (!m_grabbers[0].enabled)
return;
if (m_dragging) if (m_dragging)
set_tooltip(format(m_angle * 180.0f / (float)PI, 4)); set_tooltip(format(m_angle * 180.0f / (float)PI, 4));
else else
@ -789,12 +813,21 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
::glColor3fv(m_base_color); ::glColor3fv(m_base_color);
render_box(m_box); render_box(m_box);
// draw connections // draw connections
if (m_grabbers[0].enabled && m_grabbers[1].enabled)
{
::glColor3fv(m_grabbers[0].color); ::glColor3fv(m_grabbers[0].color);
render_grabbers_connection(0, 1); render_grabbers_connection(0, 1);
}
if (m_grabbers[2].enabled && m_grabbers[3].enabled)
{
::glColor3fv(m_grabbers[2].color); ::glColor3fv(m_grabbers[2].color);
render_grabbers_connection(2, 3); render_grabbers_connection(2, 3);
}
if (m_grabbers[4].enabled && m_grabbers[5].enabled)
{
::glColor3fv(m_grabbers[4].color); ::glColor3fv(m_grabbers[4].color);
render_grabbers_connection(4, 5); render_grabbers_connection(4, 5);
}
// draw grabbers // draw grabbers
render_grabbers(); render_grabbers();
} }
@ -1073,6 +1106,8 @@ void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const
{ {
// draw axes // draw axes
for (unsigned int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i)
{
if (m_grabbers[i].enabled)
{ {
::glColor3fv(AXES_COLOR[i]); ::glColor3fv(AXES_COLOR[i]);
::glBegin(GL_LINES); ::glBegin(GL_LINES);
@ -1080,6 +1115,7 @@ void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const
::glVertex3f((GLfloat)m_grabbers[i].center(0), (GLfloat)m_grabbers[i].center(1), (GLfloat)m_grabbers[i].center(2)); ::glVertex3f((GLfloat)m_grabbers[i].center(0), (GLfloat)m_grabbers[i].center(1), (GLfloat)m_grabbers[i].center(2));
::glEnd(); ::glEnd();
} }
}
// draw grabbers // draw grabbers
render_grabbers(); render_grabbers();

View File

@ -28,6 +28,7 @@ protected:
Vec3d center; Vec3d center;
Vec3d angles; Vec3d angles;
float color[3]; float color[3];
bool enabled;
bool dragging; bool dragging;
Grabber(); Grabber();
@ -83,6 +84,9 @@ public:
void set_highlight_color(const float* color); void set_highlight_color(const float* color);
void enable_grabber(unsigned int id);
void disable_grabber(unsigned int id);
void start_dragging(const BoundingBoxf3& box); void start_dragging(const BoundingBoxf3& box);
void stop_dragging(); void stop_dragging();
bool is_dragging() const { return m_dragging; } bool is_dragging() const { return m_dragging; }
@ -96,6 +100,8 @@ protected:
virtual bool on_init() = 0; virtual bool on_init() = 0;
virtual void on_set_state() {} virtual void on_set_state() {}
virtual void on_set_hover_id() {} virtual void on_set_hover_id() {}
virtual void on_enable_grabber(unsigned int id) {}
virtual void on_disable_grabber(unsigned int id) {}
virtual void on_start_dragging(const BoundingBoxf3& box) {} virtual void on_start_dragging(const BoundingBoxf3& box) {}
virtual void on_stop_dragging() {} virtual void on_stop_dragging() {}
virtual void on_update(const Linef3& mouse_ray) = 0; virtual void on_update(const Linef3& mouse_ray) = 0;
@ -196,6 +202,16 @@ protected:
m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1); m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1);
} }
} }
virtual void on_enable_grabber(unsigned int id)
{
if ((0 <= id) && (id < 3))
m_gizmos[id].enable_grabber(0);
}
virtual void on_disable_grabber(unsigned int id)
{
if ((0 <= id) && (id < 3))
m_gizmos[id].disable_grabber(0);
}
virtual void on_start_dragging(const BoundingBoxf3& box); virtual void on_start_dragging(const BoundingBoxf3& box);
virtual void on_stop_dragging(); virtual void on_stop_dragging();
virtual void on_update(const Linef3& mouse_ray) virtual void on_update(const Linef3& mouse_ray)