2018-06-13 07:12:16 +00:00
|
|
|
#ifndef slic3r_GLGizmo_hpp_
|
|
|
|
#define slic3r_GLGizmo_hpp_
|
|
|
|
|
|
|
|
#include "../../slic3r/GUI/GLTexture.hpp"
|
2018-06-15 12:10:28 +00:00
|
|
|
#include "../../libslic3r/Point.hpp"
|
2018-08-21 06:50:35 +00:00
|
|
|
#include "../../libslic3r/BoundingBox.hpp"
|
2018-06-15 12:10:28 +00:00
|
|
|
|
|
|
|
#include <vector>
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
#define ENABLE_GIZMOS_3D 0
|
2018-08-20 08:23:17 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
namespace Slic3r {
|
2018-06-13 13:44:04 +00:00
|
|
|
|
|
|
|
class BoundingBoxf3;
|
|
|
|
class Pointf3;
|
2018-08-20 08:23:17 +00:00
|
|
|
class Linef3;
|
2018-06-13 13:44:04 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class GLGizmoBase
|
|
|
|
{
|
2018-06-14 08:00:59 +00:00
|
|
|
protected:
|
2018-06-15 12:10:28 +00:00
|
|
|
struct Grabber
|
|
|
|
{
|
|
|
|
static const float HalfSize;
|
2018-08-20 08:23:17 +00:00
|
|
|
static const float DraggingScaleFactor;
|
2018-06-15 12:10:28 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
Pointf3 center;
|
|
|
|
float angle_x;
|
|
|
|
float angle_y;
|
2018-06-15 14:16:55 +00:00
|
|
|
float angle_z;
|
2018-06-15 12:10:28 +00:00
|
|
|
float color[3];
|
2018-08-20 08:23:17 +00:00
|
|
|
bool dragging;
|
2018-06-15 12:10:28 +00:00
|
|
|
|
|
|
|
Grabber();
|
2018-08-20 08:23:17 +00:00
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
void render(bool hover) const;
|
2018-08-21 06:50:35 +00:00
|
|
|
void render_for_picking() const { render(color); }
|
2018-08-20 08:23:17 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void render(const float* render_color) const;
|
2018-06-15 12:10:28 +00:00
|
|
|
};
|
2018-06-14 08:00:59 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
public:
|
|
|
|
enum EState
|
|
|
|
{
|
|
|
|
Off,
|
|
|
|
Hover,
|
|
|
|
On,
|
|
|
|
Num_States
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
2018-08-20 08:23:17 +00:00
|
|
|
int m_group_id;
|
2018-06-13 07:12:16 +00:00
|
|
|
EState m_state;
|
2018-06-15 12:10:28 +00:00
|
|
|
// textures are assumed to be square and all with the same size in pixels, no internal check is done
|
2018-06-13 07:12:16 +00:00
|
|
|
GLTexture m_textures[Num_States];
|
2018-06-14 13:32:26 +00:00
|
|
|
int m_hover_id;
|
2018-08-20 08:23:17 +00:00
|
|
|
float m_base_color[3];
|
|
|
|
float m_drag_color[3];
|
|
|
|
float m_highlight_color[3];
|
2018-06-15 12:10:28 +00:00
|
|
|
mutable std::vector<Grabber> m_grabbers;
|
2018-08-20 08:23:17 +00:00
|
|
|
bool m_is_container;
|
2018-06-13 07:12:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GLGizmoBase();
|
2018-08-20 08:23:17 +00:00
|
|
|
virtual ~GLGizmoBase() {}
|
|
|
|
|
|
|
|
bool init() { return on_init(); }
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
int get_group_id() const { return m_group_id; }
|
|
|
|
void set_group_id(int id) { m_group_id = id; }
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
EState get_state() const { return m_state; }
|
|
|
|
void set_state(EState state) { m_state = state; on_set_state(); }
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
unsigned int get_texture_id() const { return m_textures[m_state].get_id(); }
|
|
|
|
int get_textures_size() const { return m_textures[Off].get_width(); }
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
int get_hover_id() const { return m_hover_id; }
|
2018-06-14 13:32:26 +00:00
|
|
|
void set_hover_id(int id);
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void set_highlight_color(const float* color);
|
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
void start_dragging();
|
2018-07-12 09:26:13 +00:00
|
|
|
void stop_dragging();
|
2018-08-20 08:23:17 +00:00
|
|
|
void update(const Linef3& mouse_ray);
|
2018-08-21 06:50:35 +00:00
|
|
|
void refresh() { on_refresh(); }
|
2018-06-15 12:10:28 +00:00
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
void render(const BoundingBoxf3& box) const { on_render(box); }
|
|
|
|
void render_for_picking(const BoundingBoxf3& box) const { on_render_for_picking(box); }
|
2018-06-13 07:12:16 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool on_init() = 0;
|
2018-08-20 08:23:17 +00:00
|
|
|
virtual void on_set_state() {}
|
|
|
|
virtual void on_set_hover_id() {}
|
|
|
|
virtual void on_start_dragging() {}
|
|
|
|
virtual void on_stop_dragging() {}
|
|
|
|
virtual void on_update(const Linef3& mouse_ray) = 0;
|
|
|
|
virtual void on_refresh() {}
|
2018-06-13 13:44:04 +00:00
|
|
|
virtual void on_render(const BoundingBoxf3& box) const = 0;
|
2018-06-14 13:32:26 +00:00
|
|
|
virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0;
|
2018-06-14 08:00:59 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
float picking_color_component(unsigned int id) const;
|
2018-06-15 12:10:28 +00:00
|
|
|
void render_grabbers() const;
|
2018-08-20 08:23:17 +00:00
|
|
|
void render_grabbers_for_picking() const;
|
2018-06-13 07:12:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GLGizmoRotate : public GLGizmoBase
|
|
|
|
{
|
2018-06-14 08:00:59 +00:00
|
|
|
static const float Offset;
|
|
|
|
static const unsigned int CircleResolution;
|
2018-06-15 14:16:55 +00:00
|
|
|
static const unsigned int AngleResolution;
|
2018-06-14 08:00:59 +00:00
|
|
|
static const unsigned int ScaleStepsCount;
|
|
|
|
static const float ScaleStepRad;
|
|
|
|
static const unsigned int ScaleLongEvery;
|
|
|
|
static const float ScaleLongTooth;
|
|
|
|
static const float ScaleShortTooth;
|
|
|
|
static const unsigned int SnapRegionsCount;
|
|
|
|
static const float GrabberOffset;
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
public:
|
|
|
|
enum Axis : unsigned char
|
|
|
|
{
|
|
|
|
X,
|
|
|
|
Y,
|
|
|
|
Z
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
Axis m_axis;
|
|
|
|
float m_angle;
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
mutable Pointf3 m_center;
|
2018-06-15 14:16:55 +00:00
|
|
|
mutable float m_radius;
|
2018-08-15 10:50:06 +00:00
|
|
|
mutable bool m_keep_initial_values;
|
2018-06-15 14:16:55 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
public:
|
2018-08-20 08:23:17 +00:00
|
|
|
explicit GLGizmoRotate(Axis axis);
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
float get_angle() const { return m_angle; }
|
2018-08-20 08:23:17 +00:00
|
|
|
void set_angle(float angle);
|
2018-06-19 07:46:26 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
protected:
|
|
|
|
virtual bool on_init();
|
2018-08-21 06:50:35 +00:00
|
|
|
virtual void on_set_state() { m_keep_initial_values = (m_state == On) ? false : true; }
|
2018-08-20 08:23:17 +00:00
|
|
|
virtual void on_update(const Linef3& mouse_ray);
|
2018-08-21 06:50:35 +00:00
|
|
|
virtual void on_refresh() { m_keep_initial_values = false; }
|
2018-06-13 13:44:04 +00:00
|
|
|
virtual void on_render(const BoundingBoxf3& box) const;
|
2018-06-14 13:32:26 +00:00
|
|
|
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
2018-06-14 08:00:59 +00:00
|
|
|
|
|
|
|
private:
|
2018-08-20 08:23:17 +00:00
|
|
|
void render_circle() const;
|
|
|
|
void render_scale() const;
|
|
|
|
void render_snap_radii() const;
|
|
|
|
void render_reference_radius() const;
|
|
|
|
void render_angle() const;
|
|
|
|
void render_grabber() const;
|
|
|
|
|
|
|
|
void transform_to_local() const;
|
|
|
|
Pointf mouse_position_in_local_plane(const Linef3& mouse_ray) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GLGizmoRotate3D : public GLGizmoBase
|
|
|
|
{
|
|
|
|
GLGizmoRotate m_x;
|
|
|
|
GLGizmoRotate m_y;
|
|
|
|
GLGizmoRotate m_z;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GLGizmoRotate3D();
|
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
float get_angle_x() const { return m_x.get_angle(); }
|
|
|
|
void set_angle_x(float angle) { m_x.set_angle(angle); }
|
2018-08-20 08:23:17 +00:00
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
float get_angle_y() const { return m_y.get_angle(); }
|
|
|
|
void set_angle_y(float angle) { m_y.set_angle(angle); }
|
2018-08-20 08:23:17 +00:00
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
float get_angle_z() const { return m_z.get_angle(); }
|
|
|
|
void set_angle_z(float angle) { m_z.set_angle(angle); }
|
2018-08-20 08:23:17 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool on_init();
|
2018-08-21 06:50:35 +00:00
|
|
|
virtual void on_set_state()
|
|
|
|
{
|
|
|
|
m_x.set_state(m_state);
|
|
|
|
m_y.set_state(m_state);
|
|
|
|
m_z.set_state(m_state);
|
|
|
|
}
|
|
|
|
virtual void on_set_hover_id()
|
|
|
|
{
|
|
|
|
m_x.set_hover_id(m_hover_id == 0 ? 0 : -1);
|
|
|
|
m_y.set_hover_id(m_hover_id == 1 ? 0 : -1);
|
|
|
|
m_z.set_hover_id(m_hover_id == 2 ? 0 : -1);
|
|
|
|
}
|
2018-08-20 08:23:17 +00:00
|
|
|
virtual void on_start_dragging();
|
|
|
|
virtual void on_stop_dragging();
|
2018-08-21 06:50:35 +00:00
|
|
|
virtual void on_update(const Linef3& mouse_ray)
|
|
|
|
{
|
|
|
|
m_x.update(mouse_ray);
|
|
|
|
m_y.update(mouse_ray);
|
|
|
|
m_z.update(mouse_ray);
|
|
|
|
}
|
|
|
|
virtual void on_refresh()
|
|
|
|
{
|
|
|
|
m_x.refresh();
|
|
|
|
m_y.refresh();
|
|
|
|
m_z.refresh();
|
|
|
|
}
|
2018-08-20 08:23:17 +00:00
|
|
|
virtual void on_render(const BoundingBoxf3& box) const;
|
2018-08-21 06:50:35 +00:00
|
|
|
virtual void on_render_for_picking(const BoundingBoxf3& box) const
|
|
|
|
{
|
|
|
|
m_x.render_for_picking(box);
|
|
|
|
m_y.render_for_picking(box);
|
|
|
|
m_z.render_for_picking(box);
|
|
|
|
}
|
2018-06-13 07:12:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GLGizmoScale : public GLGizmoBase
|
|
|
|
{
|
2018-06-13 13:44:04 +00:00
|
|
|
static const float Offset;
|
|
|
|
|
2018-06-18 13:07:17 +00:00
|
|
|
float m_scale;
|
2018-06-19 07:46:26 +00:00
|
|
|
float m_starting_scale;
|
2018-06-18 13:07:17 +00:00
|
|
|
|
|
|
|
Pointf m_starting_drag_position;
|
2018-06-13 07:12:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GLGizmoScale();
|
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
float get_scale() const { return m_scale; }
|
|
|
|
void set_scale(float scale) { m_starting_scale = scale; }
|
2018-06-18 13:07:17 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
protected:
|
|
|
|
virtual bool on_init();
|
2018-06-18 13:07:17 +00:00
|
|
|
virtual void on_start_dragging();
|
2018-08-20 08:23:17 +00:00
|
|
|
virtual void on_update(const Linef3& mouse_ray);
|
2018-06-13 13:44:04 +00:00
|
|
|
virtual void on_render(const BoundingBoxf3& box) const;
|
2018-06-14 13:32:26 +00:00
|
|
|
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
2018-06-13 07:12:16 +00:00
|
|
|
};
|
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
class GLGizmoScale3D : public GLGizmoBase
|
|
|
|
{
|
|
|
|
static const float Offset;
|
|
|
|
|
|
|
|
mutable BoundingBoxf3 m_box;
|
|
|
|
|
|
|
|
float m_scale_x;
|
|
|
|
float m_scale_y;
|
|
|
|
float m_scale_z;
|
|
|
|
|
|
|
|
float m_starting_scale_x;
|
|
|
|
float m_starting_scale_y;
|
|
|
|
float m_starting_scale_z;
|
|
|
|
|
|
|
|
Pointf3 m_starting_drag_position;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GLGizmoScale3D();
|
|
|
|
|
|
|
|
float get_scale_x() const { return m_scale_x; }
|
|
|
|
void set_scale_x(float scale) { m_starting_scale_x = scale; }
|
|
|
|
|
|
|
|
float get_scale_y() const { return m_scale_y; }
|
|
|
|
void set_scale_y(float scale) { m_starting_scale_y = scale; }
|
|
|
|
|
|
|
|
float get_scale_z() const { return m_scale_z; }
|
|
|
|
void set_scale_z(float scale) { m_starting_scale_z = scale; }
|
|
|
|
|
|
|
|
void set_scale(float scale)
|
|
|
|
{
|
|
|
|
m_starting_scale_x = scale;
|
|
|
|
m_starting_scale_y = scale;
|
|
|
|
m_starting_scale_z = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool on_init();
|
|
|
|
virtual void on_start_dragging();
|
|
|
|
virtual void on_update(const Linef3& mouse_ray);
|
|
|
|
virtual void on_render(const BoundingBoxf3& box) const;
|
|
|
|
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
|
|
|
|
|
|
|
void render_box_x_faces() const;
|
|
|
|
void render_box_y_faces() const;
|
|
|
|
void render_box_z_faces() const;
|
|
|
|
|
|
|
|
void do_scale_x(const Linef3& mouse_ray);
|
|
|
|
void do_scale_y(const Linef3& mouse_ray);
|
|
|
|
void do_scale_z(const Linef3& mouse_ray);
|
|
|
|
void do_scale_uniform(const Linef3& mouse_ray);
|
|
|
|
};
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|
|
|
|
|
|
|
|
#endif // slic3r_GLGizmo_hpp_
|
|
|
|
|