3D gizmos' grabber size as a function of selected objects size
This commit is contained in:
parent
a97df55592
commit
00b10c7f9d
2 changed files with 113 additions and 108 deletions
|
@ -103,7 +103,8 @@ namespace GUI {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float GLGizmoBase::Grabber::HalfSize = 2.0f;
|
const float GLGizmoBase::Grabber::SizeFactor = 0.025f;
|
||||||
|
const float GLGizmoBase::Grabber::MinHalfSize = 1.5f;
|
||||||
const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f;
|
const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f;
|
||||||
|
|
||||||
GLGizmoBase::Grabber::Grabber()
|
GLGizmoBase::Grabber::Grabber()
|
||||||
|
@ -117,7 +118,7 @@ GLGizmoBase::Grabber::Grabber()
|
||||||
color[2] = 1.0f;
|
color[2] = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoBase::Grabber::render(bool hover) const
|
void GLGizmoBase::Grabber::render(bool hover, const BoundingBoxf3& box) const
|
||||||
{
|
{
|
||||||
float render_color[3];
|
float render_color[3];
|
||||||
if (hover)
|
if (hover)
|
||||||
|
@ -129,12 +130,15 @@ void GLGizmoBase::Grabber::render(bool hover) const
|
||||||
else
|
else
|
||||||
::memcpy((void*)render_color, (const void*)color, 3 * sizeof(float));
|
::memcpy((void*)render_color, (const void*)color, 3 * sizeof(float));
|
||||||
|
|
||||||
render(render_color, true);
|
render(box, render_color, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoBase::Grabber::render(const float* render_color, bool use_lighting) const
|
void GLGizmoBase::Grabber::render(const BoundingBoxf3& box, const float* render_color, bool use_lighting) const
|
||||||
{
|
{
|
||||||
float half_size = dragging ? HalfSize * DraggingScaleFactor : HalfSize;
|
float max_size = (float)box.max_size();
|
||||||
|
float half_size = dragging ? max_size * SizeFactor * DraggingScaleFactor : max_size * SizeFactor;
|
||||||
|
half_size = std::max(half_size, MinHalfSize);
|
||||||
|
|
||||||
if (use_lighting)
|
if (use_lighting)
|
||||||
::glEnable(GL_LIGHTING);
|
::glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
|
@ -291,16 +295,16 @@ float GLGizmoBase::picking_color_component(unsigned int id) const
|
||||||
return (float)color / 255.0f;
|
return (float)color / 255.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoBase::render_grabbers() const
|
void GLGizmoBase::render_grabbers(const BoundingBoxf3& box) 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)
|
if (m_grabbers[i].enabled)
|
||||||
m_grabbers[i].render(m_hover_id == i);
|
m_grabbers[i].render((m_hover_id == i), box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoBase::render_grabbers_for_picking() const
|
void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) 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)
|
||||||
{
|
{
|
||||||
|
@ -309,7 +313,7 @@ void GLGizmoBase::render_grabbers_for_picking() const
|
||||||
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(box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -440,7 +444,7 @@ void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
|
||||||
if (m_hover_id != -1)
|
if (m_hover_id != -1)
|
||||||
render_angle();
|
render_angle();
|
||||||
|
|
||||||
render_grabber();
|
render_grabber(box);
|
||||||
|
|
||||||
::glPopMatrix();
|
::glPopMatrix();
|
||||||
}
|
}
|
||||||
|
@ -452,7 +456,7 @@ void GLGizmoRotate::on_render_for_picking(const BoundingBoxf3& box) const
|
||||||
::glPushMatrix();
|
::glPushMatrix();
|
||||||
|
|
||||||
transform_to_local();
|
transform_to_local();
|
||||||
render_grabbers_for_picking();
|
render_grabbers_for_picking(box);
|
||||||
|
|
||||||
::glPopMatrix();
|
::glPopMatrix();
|
||||||
}
|
}
|
||||||
|
@ -544,7 +548,7 @@ void GLGizmoRotate::render_angle() const
|
||||||
::glEnd();
|
::glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoRotate::render_grabber() const
|
void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const
|
||||||
{
|
{
|
||||||
double grabber_radius = (double)(m_radius + GrabberOffset);
|
double grabber_radius = (double)(m_radius + GrabberOffset);
|
||||||
m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0);
|
m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0);
|
||||||
|
@ -558,7 +562,7 @@ void GLGizmoRotate::render_grabber() const
|
||||||
::glEnd();
|
::glEnd();
|
||||||
|
|
||||||
::memcpy((void*)m_grabbers[0].color, (const void*)m_highlight_color, 3 * sizeof(float));
|
::memcpy((void*)m_grabbers[0].color, (const void*)m_highlight_color, 3 * sizeof(float));
|
||||||
render_grabbers();
|
render_grabbers(box);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoRotate::transform_to_local() const
|
void GLGizmoRotate::transform_to_local() const
|
||||||
|
@ -829,7 +833,7 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
||||||
render_grabbers_connection(4, 5);
|
render_grabbers_connection(4, 5);
|
||||||
}
|
}
|
||||||
// draw grabbers
|
// draw grabbers
|
||||||
render_grabbers();
|
render_grabbers(m_box);
|
||||||
}
|
}
|
||||||
else if ((m_hover_id == 0) || (m_hover_id == 1))
|
else if ((m_hover_id == 0) || (m_hover_id == 1))
|
||||||
{
|
{
|
||||||
|
@ -846,8 +850,8 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
||||||
::glColor3fv(m_grabbers[0].color);
|
::glColor3fv(m_grabbers[0].color);
|
||||||
render_grabbers_connection(0, 1);
|
render_grabbers_connection(0, 1);
|
||||||
// draw grabbers
|
// draw grabbers
|
||||||
m_grabbers[0].render(true);
|
m_grabbers[0].render(true, m_box);
|
||||||
m_grabbers[1].render(true);
|
m_grabbers[1].render(true, m_box);
|
||||||
}
|
}
|
||||||
else if ((m_hover_id == 2) || (m_hover_id == 3))
|
else if ((m_hover_id == 2) || (m_hover_id == 3))
|
||||||
{
|
{
|
||||||
|
@ -864,8 +868,8 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
||||||
::glColor3fv(m_grabbers[2].color);
|
::glColor3fv(m_grabbers[2].color);
|
||||||
render_grabbers_connection(2, 3);
|
render_grabbers_connection(2, 3);
|
||||||
// draw grabbers
|
// draw grabbers
|
||||||
m_grabbers[2].render(true);
|
m_grabbers[2].render(true, m_box);
|
||||||
m_grabbers[3].render(true);
|
m_grabbers[3].render(true, m_box);
|
||||||
}
|
}
|
||||||
else if ((m_hover_id == 4) || (m_hover_id == 5))
|
else if ((m_hover_id == 4) || (m_hover_id == 5))
|
||||||
{
|
{
|
||||||
|
@ -882,8 +886,8 @@ 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);
|
||||||
// draw grabbers
|
// draw grabbers
|
||||||
m_grabbers[4].render(true);
|
m_grabbers[4].render(true, m_box);
|
||||||
m_grabbers[5].render(true);
|
m_grabbers[5].render(true, m_box);
|
||||||
}
|
}
|
||||||
else if (m_hover_id >= 6)
|
else if (m_hover_id >= 6)
|
||||||
{
|
{
|
||||||
|
@ -899,7 +903,7 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
||||||
// draw grabbers
|
// draw grabbers
|
||||||
for (int i = 6; i < 10; ++i)
|
for (int i = 6; i < 10; ++i)
|
||||||
{
|
{
|
||||||
m_grabbers[i].render(true);
|
m_grabbers[i].render(true, m_box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -908,7 +912,7 @@ void GLGizmoScale3D::on_render_for_picking(const BoundingBoxf3& box) const
|
||||||
{
|
{
|
||||||
::glDisable(GL_DEPTH_TEST);
|
::glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
render_grabbers_for_picking();
|
render_grabbers_for_picking(box);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoScale3D::render_box(const BoundingBoxf3& box) const
|
void GLGizmoScale3D::render_box(const BoundingBoxf3& box) const
|
||||||
|
@ -1118,7 +1122,7 @@ void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw grabbers
|
// draw grabbers
|
||||||
render_grabbers();
|
render_grabbers(box);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1130,7 +1134,7 @@ void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const
|
||||||
::glEnd();
|
::glEnd();
|
||||||
|
|
||||||
// draw grabber
|
// draw grabber
|
||||||
m_grabbers[m_hover_id].render(true);
|
m_grabbers[m_hover_id].render(true, box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1138,7 +1142,7 @@ void GLGizmoMove3D::on_render_for_picking(const BoundingBoxf3& box) const
|
||||||
{
|
{
|
||||||
::glDisable(GL_DEPTH_TEST);
|
::glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
render_grabbers_for_picking();
|
render_grabbers_for_picking(box);
|
||||||
}
|
}
|
||||||
|
|
||||||
double GLGizmoMove3D::calc_displacement(unsigned int preferred_plane_id, const Linef3& mouse_ray) const
|
double GLGizmoMove3D::calc_displacement(unsigned int preferred_plane_id, const Linef3& mouse_ray) const
|
||||||
|
|
|
@ -22,7 +22,8 @@ class GLGizmoBase
|
||||||
protected:
|
protected:
|
||||||
struct Grabber
|
struct Grabber
|
||||||
{
|
{
|
||||||
static const float HalfSize;
|
static const float SizeFactor;
|
||||||
|
static const float MinHalfSize;
|
||||||
static const float DraggingScaleFactor;
|
static const float DraggingScaleFactor;
|
||||||
|
|
||||||
Vec3d center;
|
Vec3d center;
|
||||||
|
@ -33,11 +34,11 @@ protected:
|
||||||
|
|
||||||
Grabber();
|
Grabber();
|
||||||
|
|
||||||
void render(bool hover) const;
|
void render(bool hover, const BoundingBoxf3& box) const;
|
||||||
void render_for_picking() const { render(color, false); }
|
void render_for_picking(const BoundingBoxf3& box) const { render(box, color, false); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void render(const float* render_color, bool use_lighting) const;
|
void render(const BoundingBoxf3& box, const float* render_color, bool use_lighting) const;
|
||||||
void render_face(float half_size) const;
|
void render_face(float half_size) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -109,8 +110,8 @@ protected:
|
||||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0;
|
virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0;
|
||||||
|
|
||||||
float picking_color_component(unsigned int id) const;
|
float picking_color_component(unsigned int id) const;
|
||||||
void render_grabbers() const;
|
void render_grabbers(const BoundingBoxf3& box) const;
|
||||||
void render_grabbers_for_picking() const;
|
void render_grabbers_for_picking(const BoundingBoxf3& box) const;
|
||||||
|
|
||||||
void set_tooltip(const std::string& tooltip) const;
|
void set_tooltip(const std::string& tooltip) const;
|
||||||
std::string format(float value, unsigned int decimals) const;
|
std::string format(float value, unsigned int decimals) const;
|
||||||
|
@ -163,7 +164,7 @@ private:
|
||||||
void render_snap_radii() const;
|
void render_snap_radii() const;
|
||||||
void render_reference_radius() const;
|
void render_reference_radius() const;
|
||||||
void render_angle() const;
|
void render_angle() const;
|
||||||
void render_grabber() const;
|
void render_grabber(const BoundingBoxf3& box) const;
|
||||||
|
|
||||||
void transform_to_local() const;
|
void transform_to_local() const;
|
||||||
// returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate
|
// returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate
|
||||||
|
|
Loading…
Reference in a new issue