mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-28 00:57:35 +08:00
More eigenized gizmos
This commit is contained in:
parent
255e837d33
commit
84fb7940b7
@ -26,10 +26,8 @@ const float GLGizmoBase::Grabber::HalfSize = 2.0f;
|
|||||||
const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f;
|
const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f;
|
||||||
|
|
||||||
GLGizmoBase::Grabber::Grabber()
|
GLGizmoBase::Grabber::Grabber()
|
||||||
: center(0.0, 0.0, 0.0)
|
: center(Vec3d::Zero())
|
||||||
, angle_x(0.0f)
|
, angles(Vec3d::Zero())
|
||||||
, angle_y(0.0f)
|
|
||||||
, angle_z(0.0f)
|
|
||||||
, dragging(false)
|
, dragging(false)
|
||||||
{
|
{
|
||||||
color[0] = 1.0f;
|
color[0] = 1.0f;
|
||||||
@ -64,9 +62,9 @@ void GLGizmoBase::Grabber::render(const float* render_color, bool use_lighting)
|
|||||||
::glTranslatef((GLfloat)center(0), (GLfloat)center(1), (GLfloat)center(2));
|
::glTranslatef((GLfloat)center(0), (GLfloat)center(1), (GLfloat)center(2));
|
||||||
|
|
||||||
float rad_to_deg = 180.0f / (GLfloat)PI;
|
float rad_to_deg = 180.0f / (GLfloat)PI;
|
||||||
::glRotatef((GLfloat)angle_x * rad_to_deg, 1.0f, 0.0f, 0.0f);
|
::glRotatef((GLfloat)angles(0) * rad_to_deg, 1.0f, 0.0f, 0.0f);
|
||||||
::glRotatef((GLfloat)angle_y * rad_to_deg, 0.0f, 1.0f, 0.0f);
|
::glRotatef((GLfloat)angles(1) * rad_to_deg, 0.0f, 1.0f, 0.0f);
|
||||||
::glRotatef((GLfloat)angle_z * rad_to_deg, 0.0f, 0.0f, 1.0f);
|
::glRotatef((GLfloat)angles(2) * rad_to_deg, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
// face min x
|
// face min x
|
||||||
::glPushMatrix();
|
::glPushMatrix();
|
||||||
@ -233,17 +231,17 @@ const float GLGizmoRotate::GrabberOffset = 5.0f;
|
|||||||
GLGizmoRotate::GLGizmoRotate(GLCanvas3D& parent, GLGizmoRotate::Axis axis)
|
GLGizmoRotate::GLGizmoRotate(GLCanvas3D& parent, GLGizmoRotate::Axis axis)
|
||||||
: GLGizmoBase(parent)
|
: GLGizmoBase(parent)
|
||||||
, m_axis(axis)
|
, m_axis(axis)
|
||||||
, m_angle(0.0f)
|
, m_angle(0.0)
|
||||||
, m_center(0.0, 0.0, 0.0)
|
, m_center(0.0, 0.0, 0.0)
|
||||||
, m_radius(0.0f)
|
, m_radius(0.0f)
|
||||||
, m_keep_initial_values(false)
|
, m_keep_initial_values(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoRotate::set_angle(float angle)
|
void GLGizmoRotate::set_angle(double angle)
|
||||||
{
|
{
|
||||||
if (std::abs(angle - 2.0f * PI) < EPSILON)
|
if (std::abs(angle - 2.0 * (double)PI) < EPSILON)
|
||||||
angle = 0.0f;
|
angle = 0.0;
|
||||||
|
|
||||||
m_angle = angle;
|
m_angle = angle;
|
||||||
}
|
}
|
||||||
@ -290,7 +288,7 @@ void GLGizmoRotate::on_update(const Linef3& mouse_ray)
|
|||||||
if (theta == 2.0 * (double)PI)
|
if (theta == 2.0 * (double)PI)
|
||||||
theta = 0.0;
|
theta = 0.0;
|
||||||
|
|
||||||
m_angle = (float)theta;
|
m_angle = theta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
|
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
|
||||||
@ -420,7 +418,7 @@ void GLGizmoRotate::render_reference_radius() const
|
|||||||
|
|
||||||
void GLGizmoRotate::render_angle() const
|
void GLGizmoRotate::render_angle() const
|
||||||
{
|
{
|
||||||
float step_angle = m_angle / AngleResolution;
|
float step_angle = (float)m_angle / AngleResolution;
|
||||||
float ex_radius = m_radius + GrabberOffset;
|
float ex_radius = m_radius + GrabberOffset;
|
||||||
|
|
||||||
::glBegin(GL_LINE_STRIP);
|
::glBegin(GL_LINE_STRIP);
|
||||||
@ -437,9 +435,9 @@ void GLGizmoRotate::render_angle() const
|
|||||||
|
|
||||||
void GLGizmoRotate::render_grabber() const
|
void GLGizmoRotate::render_grabber() const
|
||||||
{
|
{
|
||||||
float grabber_radius = 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);
|
||||||
m_grabbers[0].angle_z = m_angle;
|
m_grabbers[0].angles(2) = m_angle;
|
||||||
|
|
||||||
::glColor3fv((m_hover_id != -1) ? m_drag_color : m_highlight_color);
|
::glColor3fv((m_hover_id != -1) ? m_drag_color : m_highlight_color);
|
||||||
|
|
||||||
@ -509,17 +507,7 @@ Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) cons
|
|||||||
|
|
||||||
m.translate(-m_center);
|
m.translate(-m_center);
|
||||||
|
|
||||||
Eigen::Matrix<double, 3, 2> world_ray;
|
return transform(mouse_ray, m).intersect_plane(0.0);
|
||||||
Eigen::Matrix<double, 3, 2> local_ray;
|
|
||||||
world_ray(0, 0) = mouse_ray.a(0);
|
|
||||||
world_ray(1, 0) = mouse_ray.a(1);
|
|
||||||
world_ray(2, 0) = mouse_ray.a(2);
|
|
||||||
world_ray(0, 1) = mouse_ray.b(0);
|
|
||||||
world_ray(1, 1) = mouse_ray.b(1);
|
|
||||||
world_ray(2, 1) = mouse_ray.b(2);
|
|
||||||
local_ray = m * world_ray.colwise().homogeneous();
|
|
||||||
|
|
||||||
return Linef3(Vec3d(local_ray(0, 0), local_ray(1, 0), local_ray(2, 0)), Vec3d(local_ray(0, 1), local_ray(1, 1), local_ray(2, 1))).intersect_plane(0.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent)
|
GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent)
|
||||||
@ -627,12 +615,9 @@ const float GLGizmoScale3D::Offset = 5.0f;
|
|||||||
|
|
||||||
GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent)
|
GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent)
|
||||||
: GLGizmoBase(parent)
|
: GLGizmoBase(parent)
|
||||||
, m_scale_x(1.0f)
|
, m_scale(Vec3d::Ones())
|
||||||
, m_scale_y(1.0f)
|
, m_starting_scale(Vec3d::Ones())
|
||||||
, m_scale_z(1.0f)
|
, m_starting_center(Vec3d::Zero())
|
||||||
, m_starting_scale_x(1.0f)
|
|
||||||
, m_starting_scale_y(1.0f)
|
|
||||||
, m_starting_scale_z(1.0f)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,15 +642,15 @@ bool GLGizmoScale3D::on_init()
|
|||||||
m_grabbers.push_back(Grabber());
|
m_grabbers.push_back(Grabber());
|
||||||
}
|
}
|
||||||
|
|
||||||
float half_pi = 0.5f * (float)PI;
|
double half_pi = 0.5 * (double)PI;
|
||||||
|
|
||||||
// x axis
|
// x axis
|
||||||
m_grabbers[0].angle_y = half_pi;
|
m_grabbers[0].angles(1) = half_pi;
|
||||||
m_grabbers[1].angle_y = half_pi;
|
m_grabbers[1].angles(1) = half_pi;
|
||||||
|
|
||||||
// y axis
|
// y axis
|
||||||
m_grabbers[2].angle_x = half_pi;
|
m_grabbers[2].angles(0) = half_pi;
|
||||||
m_grabbers[3].angle_x = half_pi;
|
m_grabbers[3].angles(0) = half_pi;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -694,16 +679,16 @@ void GLGizmoScale3D::on_update(const Linef3& mouse_ray)
|
|||||||
void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
||||||
{
|
{
|
||||||
if (m_grabbers[0].dragging || m_grabbers[1].dragging)
|
if (m_grabbers[0].dragging || m_grabbers[1].dragging)
|
||||||
set_tooltip("X: " + format(100.0f * m_scale_x, 4) + "%");
|
set_tooltip("X: " + format(100.0f * m_scale(0), 4) + "%");
|
||||||
else if (m_grabbers[2].dragging || m_grabbers[3].dragging)
|
else if (m_grabbers[2].dragging || m_grabbers[3].dragging)
|
||||||
set_tooltip("Y: " + format(100.0f * m_scale_y, 4) + "%");
|
set_tooltip("Y: " + format(100.0f * m_scale(1), 4) + "%");
|
||||||
else if (m_grabbers[4].dragging || m_grabbers[5].dragging)
|
else if (m_grabbers[4].dragging || m_grabbers[5].dragging)
|
||||||
set_tooltip("Z: " + format(100.0f * m_scale_z, 4) + "%");
|
set_tooltip("Z: " + format(100.0f * m_scale(2), 4) + "%");
|
||||||
else if (m_grabbers[6].dragging || m_grabbers[7].dragging || m_grabbers[8].dragging || m_grabbers[9].dragging)
|
else if (m_grabbers[6].dragging || m_grabbers[7].dragging || m_grabbers[8].dragging || m_grabbers[9].dragging)
|
||||||
{
|
{
|
||||||
std::string tooltip = "X: " + format(100.0f * m_scale_x, 4) + "%\n";
|
std::string tooltip = "X: " + format(100.0f * m_scale(0), 4) + "%\n";
|
||||||
tooltip += "Y: " + format(100.0f * m_scale_y, 4) + "%\n";
|
tooltip += "Y: " + format(100.0f * m_scale(1), 4) + "%\n";
|
||||||
tooltip += "Z: " + format(100.0f * m_scale_z, 4) + "%";
|
tooltip += "Z: " + format(100.0f * m_scale(2), 4) + "%";
|
||||||
set_tooltip(tooltip);
|
set_tooltip(tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -850,7 +835,7 @@ void GLGizmoScale3D::do_scale_x(const Linef3& mouse_ray)
|
|||||||
double ratio = calc_ratio(1, mouse_ray, m_starting_center);
|
double ratio = calc_ratio(1, mouse_ray, m_starting_center);
|
||||||
|
|
||||||
if (ratio > 0.0)
|
if (ratio > 0.0)
|
||||||
m_scale_x = m_starting_scale_x * (float)ratio;
|
m_scale(0) = m_starting_scale(0) * ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
|
void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
|
||||||
@ -858,8 +843,8 @@ void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
|
|||||||
double ratio = calc_ratio(2, mouse_ray, m_starting_center);
|
double ratio = calc_ratio(2, mouse_ray, m_starting_center);
|
||||||
|
|
||||||
if (ratio > 0.0)
|
if (ratio > 0.0)
|
||||||
m_scale_x = m_starting_scale_y * (float)ratio; // << this is temporary
|
m_scale(0) = m_starting_scale(1) * ratio; // << this is temporary
|
||||||
// m_scale_y = m_starting_scale_y * (float)ratio;
|
// m_scale(1) = m_starting_scale(1) * ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
|
void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
|
||||||
@ -867,8 +852,8 @@ void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
|
|||||||
double ratio = calc_ratio(1, mouse_ray, m_starting_center);
|
double ratio = calc_ratio(1, mouse_ray, m_starting_center);
|
||||||
|
|
||||||
if (ratio > 0.0)
|
if (ratio > 0.0)
|
||||||
m_scale_x = m_starting_scale_z * (float)ratio; // << this is temporary
|
m_scale(0) = m_starting_scale(2) * ratio; // << this is temporary
|
||||||
// m_scale_z = m_starting_scale_z * (float)ratio;
|
// m_scale(2) = m_starting_scale(2) * ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
|
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
|
||||||
@ -878,11 +863,7 @@ void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
|
|||||||
double ratio = calc_ratio(0, mouse_ray, center);
|
double ratio = calc_ratio(0, mouse_ray, center);
|
||||||
|
|
||||||
if (ratio > 0.0)
|
if (ratio > 0.0)
|
||||||
{
|
m_scale = m_starting_scale * ratio;
|
||||||
m_scale_x = m_starting_scale_x * (float)ratio;
|
|
||||||
m_scale_y = m_starting_scale_y * (float)ratio;
|
|
||||||
m_scale_z = m_starting_scale_z * (float)ratio;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const
|
double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const
|
||||||
|
@ -26,9 +26,7 @@ protected:
|
|||||||
static const float DraggingScaleFactor;
|
static const float DraggingScaleFactor;
|
||||||
|
|
||||||
Vec3d center;
|
Vec3d center;
|
||||||
float angle_x;
|
Vec3d angles;
|
||||||
float angle_y;
|
|
||||||
float angle_z;
|
|
||||||
float color[3];
|
float color[3];
|
||||||
bool dragging;
|
bool dragging;
|
||||||
|
|
||||||
@ -134,7 +132,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Axis m_axis;
|
Axis m_axis;
|
||||||
float m_angle;
|
double m_angle;
|
||||||
|
|
||||||
mutable Vec3d m_center;
|
mutable Vec3d m_center;
|
||||||
mutable float m_radius;
|
mutable float m_radius;
|
||||||
@ -143,8 +141,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
GLGizmoRotate(GLCanvas3D& parent, Axis axis);
|
GLGizmoRotate(GLCanvas3D& parent, Axis axis);
|
||||||
|
|
||||||
float get_angle() const { return m_angle; }
|
double get_angle() const { return m_angle; }
|
||||||
void set_angle(float angle);
|
void set_angle(double angle);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool on_init();
|
virtual bool on_init();
|
||||||
@ -176,14 +174,14 @@ class GLGizmoRotate3D : public GLGizmoBase
|
|||||||
public:
|
public:
|
||||||
explicit GLGizmoRotate3D(GLCanvas3D& parent);
|
explicit GLGizmoRotate3D(GLCanvas3D& parent);
|
||||||
|
|
||||||
float get_angle_x() const { return m_x.get_angle(); }
|
double get_angle_x() const { return m_x.get_angle(); }
|
||||||
void set_angle_x(float angle) { m_x.set_angle(angle); }
|
void set_angle_x(double angle) { m_x.set_angle(angle); }
|
||||||
|
|
||||||
float get_angle_y() const { return m_y.get_angle(); }
|
double get_angle_y() const { return m_y.get_angle(); }
|
||||||
void set_angle_y(float angle) { m_y.set_angle(angle); }
|
void set_angle_y(double angle) { m_y.set_angle(angle); }
|
||||||
|
|
||||||
float get_angle_z() const { return m_z.get_angle(); }
|
double get_angle_z() const { return m_z.get_angle(); }
|
||||||
void set_angle_z(float angle) { m_z.set_angle(angle); }
|
void set_angle_z(double angle) { m_z.set_angle(angle); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool on_init();
|
virtual bool on_init();
|
||||||
@ -228,35 +226,25 @@ class GLGizmoScale3D : public GLGizmoBase
|
|||||||
|
|
||||||
mutable BoundingBoxf3 m_box;
|
mutable BoundingBoxf3 m_box;
|
||||||
|
|
||||||
float m_scale_x;
|
Vec3d m_scale;
|
||||||
float m_scale_y;
|
|
||||||
float m_scale_z;
|
|
||||||
|
|
||||||
float m_starting_scale_x;
|
|
||||||
float m_starting_scale_y;
|
|
||||||
float m_starting_scale_z;
|
|
||||||
|
|
||||||
|
Vec3d m_starting_scale;
|
||||||
Vec3d m_starting_drag_position;
|
Vec3d m_starting_drag_position;
|
||||||
Vec3d m_starting_center;
|
Vec3d m_starting_center;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GLGizmoScale3D(GLCanvas3D& parent);
|
explicit GLGizmoScale3D(GLCanvas3D& parent);
|
||||||
|
|
||||||
float get_scale_x() const { return m_scale_x; }
|
double get_scale_x() const { return m_scale(0); }
|
||||||
void set_scale_x(float scale) { m_starting_scale_x = scale; }
|
void set_scale_x(double scale) { m_starting_scale(0) = scale; }
|
||||||
|
|
||||||
float get_scale_y() const { return m_scale_y; }
|
double get_scale_y() const { return m_scale(1); }
|
||||||
void set_scale_y(float scale) { m_starting_scale_y = scale; }
|
void set_scale_y(double scale) { m_starting_scale(1) = scale; }
|
||||||
|
|
||||||
float get_scale_z() const { return m_scale_z; }
|
double get_scale_z() const { return m_scale(2); }
|
||||||
void set_scale_z(float scale) { m_starting_scale_z = scale; }
|
void set_scale_z(double scale) { m_starting_scale(2) = scale; }
|
||||||
|
|
||||||
void set_scale(float scale)
|
void set_scale(double scale) { m_starting_scale = scale * Vec3d::Ones(); }
|
||||||
{
|
|
||||||
m_starting_scale_x = scale;
|
|
||||||
m_starting_scale_y = scale;
|
|
||||||
m_starting_scale_z = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool on_init();
|
virtual bool on_init();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user