mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-15 02:37:51 -06:00
Scale gizmo rendering
This commit is contained in:
parent
099d59ad27
commit
3a19b81cef
4 changed files with 132 additions and 52 deletions
|
@ -1,6 +1,9 @@
|
|||
#include "GLGizmo.hpp"
|
||||
|
||||
#include "../../libslic3r/Utils.hpp"
|
||||
#include "../../libslic3r/BoundingBox.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -16,6 +19,11 @@ GLGizmoBase::~GLGizmoBase()
|
|||
{
|
||||
}
|
||||
|
||||
bool GLGizmoBase::init()
|
||||
{
|
||||
return on_init();
|
||||
}
|
||||
|
||||
GLGizmoBase::EState GLGizmoBase::get_state() const
|
||||
{
|
||||
return m_state;
|
||||
|
@ -36,9 +44,9 @@ int GLGizmoBase::get_textures_size() const
|
|||
return m_textures[Off].get_width();
|
||||
}
|
||||
|
||||
bool GLGizmoBase::init()
|
||||
void GLGizmoBase::render(const BoundingBoxf3& box) const
|
||||
{
|
||||
return on_init();
|
||||
on_render(box);
|
||||
}
|
||||
|
||||
GLGizmoRotate::GLGizmoRotate()
|
||||
|
@ -49,11 +57,6 @@ GLGizmoRotate::GLGizmoRotate()
|
|||
{
|
||||
}
|
||||
|
||||
void GLGizmoRotate::render() const
|
||||
{
|
||||
std::cout << "GLGizmoRotate::render()" << std::endl;
|
||||
}
|
||||
|
||||
bool GLGizmoRotate::on_init()
|
||||
{
|
||||
std::string path = resources_dir() + "/icons/overlay/";
|
||||
|
@ -73,6 +76,14 @@ bool GLGizmoRotate::on_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
std::cout << "GLGizmoRotate::render()" << std::endl;
|
||||
}
|
||||
|
||||
const float GLGizmoScale::Offset = 5.0f;
|
||||
const float GLGizmoScale::SquareHalfSize = 2.0f;
|
||||
|
||||
GLGizmoScale::GLGizmoScale()
|
||||
: GLGizmoBase()
|
||||
, m_scale_x(1.0f)
|
||||
|
@ -81,11 +92,6 @@ GLGizmoScale::GLGizmoScale()
|
|||
{
|
||||
}
|
||||
|
||||
void GLGizmoScale::render() const
|
||||
{
|
||||
std::cout << "GLGizmoScale::render()" << std::endl;
|
||||
}
|
||||
|
||||
bool GLGizmoScale::on_init()
|
||||
{
|
||||
std::string path = resources_dir() + "/icons/overlay/";
|
||||
|
@ -105,5 +111,56 @@ bool GLGizmoScale::on_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoScale::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
const Pointf3& size = box.size();
|
||||
const Pointf3& center = box.center();
|
||||
|
||||
Pointf3 half_scaled_size = 0.5 * Pointf3((coordf_t)m_scale_x * size.x, (coordf_t)m_scale_y * size.y, (coordf_t)m_scale_z * size.z);
|
||||
coordf_t min_x = center.x - half_scaled_size.x - (coordf_t)Offset;
|
||||
coordf_t max_x = center.x + half_scaled_size.x + (coordf_t)Offset;
|
||||
coordf_t min_y = center.y - half_scaled_size.y - (coordf_t)Offset;
|
||||
coordf_t max_y = center.y + half_scaled_size.y + (coordf_t)Offset;
|
||||
|
||||
::glLineWidth(2.0f);
|
||||
::glBegin(GL_LINE_LOOP);
|
||||
// draw outline
|
||||
::glColor3f(1.0f, 1.0f, 1.0f);
|
||||
::glVertex3f((GLfloat)min_x, (GLfloat)min_y, 0.0f);
|
||||
::glVertex3f((GLfloat)max_x, (GLfloat)min_y, 0.0f);
|
||||
::glVertex3f((GLfloat)max_x, (GLfloat)max_y, 0.0f);
|
||||
::glVertex3f((GLfloat)min_x, (GLfloat)max_y, 0.0f);
|
||||
::glEnd();
|
||||
|
||||
// draw grabbers
|
||||
::glColor3f(1.0f, 0.38f, 0.0f);
|
||||
::glDisable(GL_CULL_FACE);
|
||||
_render_square(Pointf3(min_x, min_y, 0.0));
|
||||
_render_square(Pointf3(max_x, min_y, 0.0));
|
||||
_render_square(Pointf3(max_x, max_y, 0.0));
|
||||
_render_square(Pointf3(min_x, max_y, 0.0));
|
||||
::glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
void GLGizmoScale::_render_square(const Pointf3& center) const
|
||||
{
|
||||
float min_x = (float)center.x - SquareHalfSize;
|
||||
float max_x = (float)center.x + SquareHalfSize;
|
||||
float min_y = (float)center.y - SquareHalfSize;
|
||||
float max_y = (float)center.y + SquareHalfSize;
|
||||
|
||||
::glBegin(GL_TRIANGLES);
|
||||
::glVertex3f((GLfloat)min_x, (GLfloat)min_y, 0.0f);
|
||||
::glVertex3f((GLfloat)max_x, (GLfloat)min_y, 0.0f);
|
||||
::glVertex3f((GLfloat)max_x, (GLfloat)max_y, 0.0f);
|
||||
::glVertex3f((GLfloat)max_x, (GLfloat)max_y, 0.0f);
|
||||
::glVertex3f((GLfloat)min_x, (GLfloat)max_y, 0.0f);
|
||||
::glVertex3f((GLfloat)min_x, (GLfloat)min_y, 0.0f);
|
||||
::glEnd();
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue