Fixed rendering of gizmo grabbers
This commit is contained in:
parent
e1d5d0804b
commit
8c560522a3
4 changed files with 28 additions and 12 deletions
|
@ -21,9 +21,6 @@ GLGizmoBase::Grabber::Grabber()
|
||||||
, enabled(true)
|
, enabled(true)
|
||||||
{
|
{
|
||||||
color = { 1.0f, 1.0f, 1.0f, 1.0f };
|
color = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
TriangleMesh mesh = make_cube(1., 1., 1.);
|
|
||||||
mesh.translate(Vec3f(-0.5, -0.5, -0.5));
|
|
||||||
cube.init_from(mesh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoBase::Grabber::render(bool hover, float size) const
|
void GLGizmoBase::Grabber::render(bool hover, float size) const
|
||||||
|
@ -53,6 +50,15 @@ float GLGizmoBase::Grabber::get_dragging_half_size(float size) const
|
||||||
|
|
||||||
void GLGizmoBase::Grabber::render(float size, const std::array<float, 4>& render_color, bool picking) const
|
void GLGizmoBase::Grabber::render(float size, const std::array<float, 4>& render_color, bool picking) const
|
||||||
{
|
{
|
||||||
|
if (! cube_initialized) {
|
||||||
|
// This cannot be done in constructor, OpenGL is not yet
|
||||||
|
// initialized at that point (on Linux at least).
|
||||||
|
TriangleMesh mesh = make_cube(1., 1., 1.);
|
||||||
|
mesh.translate(Vec3f(-0.5, -0.5, -0.5));
|
||||||
|
const_cast<GLModel&>(cube).init_from(mesh);
|
||||||
|
const_cast<bool&>(cube_initialized) = true;
|
||||||
|
}
|
||||||
|
|
||||||
float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size));
|
float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size));
|
||||||
|
|
||||||
GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_current_shader();
|
GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_current_shader();
|
||||||
|
|
|
@ -48,7 +48,6 @@ protected:
|
||||||
static const float MinHalfSize;
|
static const float MinHalfSize;
|
||||||
static const float DraggingScaleFactor;
|
static const float DraggingScaleFactor;
|
||||||
|
|
||||||
GLModel cube;
|
|
||||||
Vec3d center;
|
Vec3d center;
|
||||||
Vec3d angles;
|
Vec3d angles;
|
||||||
std::array<float, 4> color;
|
std::array<float, 4> color;
|
||||||
|
@ -65,6 +64,9 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void render(float size, const std::array<float, 4>& render_color, bool picking) const;
|
void render(float size, const std::array<float, 4>& render_color, bool picking) const;
|
||||||
|
|
||||||
|
GLModel cube;
|
||||||
|
bool cube_initialized = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -199,9 +199,12 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
|
||||||
if (shader == nullptr)
|
if (shader == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (! picking) {
|
||||||
shader->start_using();
|
shader->start_using();
|
||||||
shader->set_uniform("emission_factor", 0.1);
|
shader->set_uniform("emission_factor", 0.1);
|
||||||
shader->set_uniform("uniform_color", color);
|
shader->set_uniform("uniform_color", color);
|
||||||
|
} else
|
||||||
|
glsafe(::glColor4fv(color.data()));
|
||||||
|
|
||||||
glsafe(::glPushMatrix());
|
glsafe(::glPushMatrix());
|
||||||
glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z()));
|
glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z()));
|
||||||
|
@ -215,6 +218,7 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
|
||||||
m_vbo_cone.render();
|
m_vbo_cone.render();
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
|
|
||||||
|
if (! picking)
|
||||||
shader->stop_using();
|
shader->stop_using();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -336,9 +336,12 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
|
||||||
if (shader == nullptr)
|
if (shader == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (! picking) {
|
||||||
shader->start_using();
|
shader->start_using();
|
||||||
shader->set_uniform("emission_factor", 0.1);
|
shader->set_uniform("emission_factor", 0.1);
|
||||||
shader->set_uniform("uniform_color", color);
|
shader->set_uniform("uniform_color", color);
|
||||||
|
} else
|
||||||
|
glsafe(::glColor4fv(color.data()));
|
||||||
|
|
||||||
glsafe(::glPushMatrix());
|
glsafe(::glPushMatrix());
|
||||||
glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z()));
|
glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z()));
|
||||||
|
@ -357,6 +360,7 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
|
||||||
m_cone.render();
|
m_cone.render();
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
|
|
||||||
|
if (! picking)
|
||||||
shader->stop_using();
|
shader->stop_using();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue