Modified rendering of gizmo scale 3D

This commit is contained in:
Enrico Turri 2018-10-12 14:23:34 +02:00
parent 9bb93cc4f4
commit 59208d79be
2 changed files with 14 additions and 74 deletions

View File

@ -709,7 +709,6 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent)
: GLGizmoBase(parent) : GLGizmoBase(parent)
, m_scale(Vec3d::Ones()) , m_scale(Vec3d::Ones())
, m_starting_scale(Vec3d::Ones()) , m_starting_scale(Vec3d::Ones())
, m_show_starting_box(false)
{ {
} }
@ -752,7 +751,6 @@ void GLGizmoScale3D::on_start_dragging(const BoundingBoxf3& box)
if (m_hover_id != -1) if (m_hover_id != -1)
{ {
m_starting_drag_position = m_grabbers[m_hover_id].center; m_starting_drag_position = m_grabbers[m_hover_id].center;
m_show_starting_box = true;
m_starting_box = BoundingBoxf3(box.min - OffsetVec, box.max + OffsetVec); m_starting_box = BoundingBoxf3(box.min - OffsetVec, box.max + OffsetVec);
} }
} }
@ -817,10 +815,10 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
::memcpy((void*)m_grabbers[5].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float)); ::memcpy((void*)m_grabbers[5].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float));
// uniform // uniform
m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(1), m_box.min(2)); m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(1), center(2));
m_grabbers[7].center = Vec3d(m_box.max(0), m_box.min(1), m_box.min(2)); m_grabbers[7].center = Vec3d(m_box.max(0), m_box.min(1), center(2));
m_grabbers[8].center = Vec3d(m_box.max(0), m_box.max(1), m_box.min(2)); m_grabbers[8].center = Vec3d(m_box.max(0), m_box.max(1), center(2));
m_grabbers[9].center = Vec3d(m_box.min(0), m_box.max(1), m_box.min(2)); m_grabbers[9].center = Vec3d(m_box.min(0), m_box.max(1), center(2));
for (int i = 6; i < 10; ++i) for (int i = 6; i < 10; ++i)
{ {
::memcpy((void*)m_grabbers[i].color, (const void*)m_highlight_color, 3 * sizeof(float)); ::memcpy((void*)m_grabbers[i].color, (const void*)m_highlight_color, 3 * sizeof(float));
@ -830,9 +828,6 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
if (m_hover_id == -1) if (m_hover_id == -1)
{ {
// draw box
::glColor3fv(m_base_color);
render_box(m_box);
// draw connections // draw connections
if (m_grabbers[0].enabled && m_grabbers[1].enabled) if (m_grabbers[0].enabled && m_grabbers[1].enabled)
{ {
@ -849,20 +844,16 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
::glColor3fv(m_grabbers[4].color); ::glColor3fv(m_grabbers[4].color);
render_grabbers_connection(4, 5); render_grabbers_connection(4, 5);
} }
::glColor3fv(m_base_color);
render_grabbers_connection(6, 7);
render_grabbers_connection(7, 8);
render_grabbers_connection(8, 9);
render_grabbers_connection(9, 6);
// draw grabbers // draw grabbers
render_grabbers(m_box); render_grabbers(m_box);
} }
else if ((m_hover_id == 0) || (m_hover_id == 1)) else if ((m_hover_id == 0) || (m_hover_id == 1))
{ {
// draw starting box
if (m_show_starting_box)
{
::glColor3fv(m_base_color);
render_box(m_starting_box);
}
// draw current box
::glColor3fv(m_drag_color);
render_box(m_box);
// draw connection // draw connection
::glColor3fv(m_grabbers[0].color); ::glColor3fv(m_grabbers[0].color);
render_grabbers_connection(0, 1); render_grabbers_connection(0, 1);
@ -872,15 +863,6 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
} }
else if ((m_hover_id == 2) || (m_hover_id == 3)) else if ((m_hover_id == 2) || (m_hover_id == 3))
{ {
// draw starting box
if (m_show_starting_box)
{
::glColor3fv(m_base_color);
render_box(m_starting_box);
}
// draw current box
::glColor3fv(m_drag_color);
render_box(m_box);
// draw connection // draw connection
::glColor3fv(m_grabbers[2].color); ::glColor3fv(m_grabbers[2].color);
render_grabbers_connection(2, 3); render_grabbers_connection(2, 3);
@ -890,15 +872,6 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
} }
else if ((m_hover_id == 4) || (m_hover_id == 5)) else if ((m_hover_id == 4) || (m_hover_id == 5))
{ {
// draw starting box
if (m_show_starting_box)
{
::glColor3fv(m_base_color);
render_box(m_starting_box);
}
// draw current box
::glColor3fv(m_drag_color);
render_box(m_box);
// draw connection // draw connection
::glColor3fv(m_grabbers[4].color); ::glColor3fv(m_grabbers[4].color);
render_grabbers_connection(4, 5); render_grabbers_connection(4, 5);
@ -908,15 +881,12 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
} }
else if (m_hover_id >= 6) else if (m_hover_id >= 6)
{ {
// draw starting box // draw connection
if (m_show_starting_box)
{
::glColor3fv(m_base_color);
render_box(m_starting_box);
}
// draw current box
::glColor3fv(m_drag_color); ::glColor3fv(m_drag_color);
render_box(m_box); render_grabbers_connection(6, 7);
render_grabbers_connection(7, 8);
render_grabbers_connection(8, 9);
render_grabbers_connection(9, 6);
// draw grabbers // draw grabbers
for (int i = 6; i < 10; ++i) for (int i = 6; i < 10; ++i)
{ {
@ -932,33 +902,6 @@ void GLGizmoScale3D::on_render_for_picking(const BoundingBoxf3& box) const
render_grabbers_for_picking(box); render_grabbers_for_picking(box);
} }
void GLGizmoScale3D::render_box(const BoundingBoxf3& box) const
{
// bottom face
::glBegin(GL_LINE_LOOP);
::glVertex3f((GLfloat)box.min(0), (GLfloat)box.min(1), (GLfloat)box.min(2));
::glVertex3f((GLfloat)box.min(0), (GLfloat)box.max(1), (GLfloat)box.min(2));
::glVertex3f((GLfloat)box.max(0), (GLfloat)box.max(1), (GLfloat)box.min(2));
::glVertex3f((GLfloat)box.max(0), (GLfloat)box.min(1), (GLfloat)box.min(2));
::glEnd();
// top face
::glBegin(GL_LINE_LOOP);
::glVertex3f((GLfloat)box.min(0), (GLfloat)box.min(1), (GLfloat)box.max(2));
::glVertex3f((GLfloat)box.min(0), (GLfloat)box.max(1), (GLfloat)box.max(2));
::glVertex3f((GLfloat)box.max(0), (GLfloat)box.max(1), (GLfloat)box.max(2));
::glVertex3f((GLfloat)box.max(0), (GLfloat)box.min(1), (GLfloat)box.max(2));
::glEnd();
// vertical edges
::glBegin(GL_LINES);
::glVertex3f((GLfloat)box.min(0), (GLfloat)box.min(1), (GLfloat)box.min(2)); ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.min(1), (GLfloat)box.max(2));
::glVertex3f((GLfloat)box.min(0), (GLfloat)box.max(1), (GLfloat)box.min(2)); ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.max(1), (GLfloat)box.max(2));
::glVertex3f((GLfloat)box.max(0), (GLfloat)box.max(1), (GLfloat)box.min(2)); ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.max(1), (GLfloat)box.max(2));
::glVertex3f((GLfloat)box.max(0), (GLfloat)box.min(1), (GLfloat)box.min(2)); ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.min(1), (GLfloat)box.max(2));
::glEnd();
}
void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const
{ {
unsigned int grabbers_count = (unsigned int)m_grabbers.size(); unsigned int grabbers_count = (unsigned int)m_grabbers.size();

View File

@ -277,7 +277,6 @@ class GLGizmoScale3D : public GLGizmoBase
Vec3d m_starting_scale; Vec3d m_starting_scale;
Vec3d m_starting_drag_position; Vec3d m_starting_drag_position;
bool m_show_starting_box;
BoundingBoxf3 m_starting_box; BoundingBoxf3 m_starting_box;
public: public:
@ -302,7 +301,6 @@ public:
protected: protected:
virtual bool on_init(); virtual bool on_init();
virtual void on_start_dragging(const BoundingBoxf3& box); virtual void on_start_dragging(const BoundingBoxf3& box);
virtual void on_stop_dragging() { m_show_starting_box = false; }
virtual void on_update(const Linef3& mouse_ray); virtual void on_update(const Linef3& mouse_ray);
#if ENABLE_GIZMOS_RESET #if ENABLE_GIZMOS_RESET
virtual void on_process_double_click(); virtual void on_process_double_click();
@ -311,7 +309,6 @@ protected:
virtual void on_render_for_picking(const BoundingBoxf3& box) const; virtual void on_render_for_picking(const BoundingBoxf3& box) const;
private: private:
void render_box(const BoundingBoxf3& box) const;
void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const; void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const;
void do_scale_x(const Linef3& mouse_ray); void do_scale_x(const Linef3& mouse_ray);