2018-06-13 07:12:16 +00:00
|
|
|
#include "GLGizmo.hpp"
|
|
|
|
|
2018-06-13 07:26:58 +00:00
|
|
|
#include "../../libslic3r/Utils.hpp"
|
2018-06-13 13:44:04 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
#include <Eigen/Dense>
|
|
|
|
|
2018-06-13 13:44:04 +00:00
|
|
|
#include <GL/glew.h>
|
2018-06-13 07:12:16 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
static const float DEFAULT_BASE_COLOR[3] = { 0.625f, 0.625f, 0.625f };
|
|
|
|
static const float DEFAULT_DRAG_COLOR[3] = { 1.0f, 1.0f, 1.0f };
|
|
|
|
static const float DEFAULT_HIGHLIGHT_COLOR[3] = { 1.0f, 0.38f, 0.0f };
|
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
static const float RED[3] = { 1.0f, 0.0f, 0.0f };
|
|
|
|
static const float GREEN[3] = { 0.0f, 1.0f, 0.0f };
|
|
|
|
static const float BLUE[3] = { 0.0f, 0.0f, 1.0f };
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
namespace GUI {
|
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
const float GLGizmoBase::Grabber::HalfSize = 2.0f;
|
2018-08-20 08:23:17 +00:00
|
|
|
const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f;
|
2018-06-15 12:10:28 +00:00
|
|
|
|
|
|
|
GLGizmoBase::Grabber::Grabber()
|
2018-08-23 13:37:38 +00:00
|
|
|
: center(0.0, 0.0, 0.0)
|
2018-08-20 08:23:17 +00:00
|
|
|
, angle_x(0.0f)
|
|
|
|
, angle_y(0.0f)
|
2018-06-15 14:16:55 +00:00
|
|
|
, angle_z(0.0f)
|
2018-08-20 08:23:17 +00:00
|
|
|
, dragging(false)
|
2018-06-15 12:10:28 +00:00
|
|
|
{
|
|
|
|
color[0] = 1.0f;
|
|
|
|
color[1] = 1.0f;
|
|
|
|
color[2] = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoBase::Grabber::render(bool hover) const
|
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
float render_color[3];
|
|
|
|
if (hover)
|
|
|
|
{
|
|
|
|
render_color[0] = 1.0f - color[0];
|
|
|
|
render_color[1] = 1.0f - color[1];
|
|
|
|
render_color[2] = 1.0f - color[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
::memcpy((void*)render_color, (const void*)color, 3 * sizeof(float));
|
2018-06-15 12:10:28 +00:00
|
|
|
|
2018-08-21 12:27:36 +00:00
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
render(render_color, true);
|
|
|
|
#else
|
2018-08-20 08:23:17 +00:00
|
|
|
render(render_color);
|
2018-08-21 12:27:36 +00:00
|
|
|
#endif // ENABLE_GIZMOS_3D
|
2018-08-20 08:23:17 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 12:27:36 +00:00
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
void GLGizmoBase::Grabber::render(const float* render_color, bool use_lighting) const
|
|
|
|
#else
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoBase::Grabber::render(const float* render_color) const
|
2018-08-21 12:27:36 +00:00
|
|
|
#endif // ENABLE_GIZMOS_3D
|
2018-08-20 08:23:17 +00:00
|
|
|
{
|
|
|
|
float half_size = dragging ? HalfSize * DraggingScaleFactor : HalfSize;
|
2018-08-21 12:27:36 +00:00
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
if (use_lighting)
|
|
|
|
::glEnable(GL_LIGHTING);
|
|
|
|
#else
|
2018-08-20 08:23:17 +00:00
|
|
|
float min_x = -half_size;
|
|
|
|
float max_x = +half_size;
|
|
|
|
float min_y = -half_size;
|
|
|
|
float max_y = +half_size;
|
2018-08-21 12:27:36 +00:00
|
|
|
#endif // !ENABLE_GIZMOS_3D
|
2018-08-20 08:23:17 +00:00
|
|
|
|
|
|
|
::glColor3f((GLfloat)render_color[0], (GLfloat)render_color[1], (GLfloat)render_color[2]);
|
2018-06-15 12:10:28 +00:00
|
|
|
|
2018-06-15 14:16:55 +00:00
|
|
|
::glPushMatrix();
|
2018-08-23 13:37:38 +00:00
|
|
|
::glTranslatef((GLfloat)center(0), (GLfloat)center(1), (GLfloat)center(2));
|
2018-08-20 08:23:17 +00:00
|
|
|
|
|
|
|
float rad_to_deg = 180.0f / (GLfloat)PI;
|
|
|
|
::glRotatef((GLfloat)angle_x * rad_to_deg, 1.0f, 0.0f, 0.0f);
|
|
|
|
::glRotatef((GLfloat)angle_y * rad_to_deg, 0.0f, 1.0f, 0.0f);
|
|
|
|
::glRotatef((GLfloat)angle_z * rad_to_deg, 0.0f, 0.0f, 1.0f);
|
2018-06-15 14:16:55 +00:00
|
|
|
|
2018-08-21 12:27:36 +00:00
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
// face min x
|
|
|
|
::glPushMatrix();
|
|
|
|
::glTranslatef(-(GLfloat)half_size, 0.0f, 0.0f);
|
|
|
|
::glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);
|
|
|
|
render_face(half_size);
|
|
|
|
::glPopMatrix();
|
|
|
|
|
|
|
|
// face max x
|
|
|
|
::glPushMatrix();
|
|
|
|
::glTranslatef((GLfloat)half_size, 0.0f, 0.0f);
|
|
|
|
::glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
|
|
|
|
render_face(half_size);
|
|
|
|
::glPopMatrix();
|
|
|
|
|
|
|
|
// face min y
|
|
|
|
::glPushMatrix();
|
|
|
|
::glTranslatef(0.0f, -(GLfloat)half_size, 0.0f);
|
|
|
|
::glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
|
|
|
|
render_face(half_size);
|
|
|
|
::glPopMatrix();
|
|
|
|
|
|
|
|
// face max y
|
|
|
|
::glPushMatrix();
|
|
|
|
::glTranslatef(0.0f, (GLfloat)half_size, 0.0f);
|
|
|
|
::glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
|
|
|
|
render_face(half_size);
|
|
|
|
::glPopMatrix();
|
|
|
|
|
|
|
|
// face min z
|
|
|
|
::glPushMatrix();
|
|
|
|
::glTranslatef(0.0f, 0.0f, -(GLfloat)half_size);
|
|
|
|
::glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
|
|
|
|
render_face(half_size);
|
|
|
|
::glPopMatrix();
|
|
|
|
|
|
|
|
// face max z
|
|
|
|
::glPushMatrix();
|
|
|
|
::glTranslatef(0.0f, 0.0f, (GLfloat)half_size);
|
|
|
|
render_face(half_size);
|
|
|
|
::glPopMatrix();
|
|
|
|
#else
|
2018-06-15 12:10:28 +00:00
|
|
|
::glDisable(GL_CULL_FACE);
|
|
|
|
::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();
|
|
|
|
::glEnable(GL_CULL_FACE);
|
2018-08-21 12:27:36 +00:00
|
|
|
#endif // ENABLE_GIZMOS_3D
|
2018-06-15 12:10:28 +00:00
|
|
|
|
2018-06-15 14:16:55 +00:00
|
|
|
::glPopMatrix();
|
2018-08-21 12:27:36 +00:00
|
|
|
|
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
if (use_lighting)
|
|
|
|
::glDisable(GL_LIGHTING);
|
|
|
|
#endif // ENABLE_GIZMOS_3D
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
void GLGizmoBase::Grabber::render_face(float half_size) const
|
|
|
|
{
|
|
|
|
::glBegin(GL_TRIANGLES);
|
|
|
|
::glNormal3f(0.0f, 0.0f, 1.0f);
|
|
|
|
::glVertex3f(-(GLfloat)half_size, -(GLfloat)half_size, 0.0f);
|
|
|
|
::glVertex3f((GLfloat)half_size, -(GLfloat)half_size, 0.0f);
|
|
|
|
::glVertex3f((GLfloat)half_size, (GLfloat)half_size, 0.0f);
|
|
|
|
::glVertex3f((GLfloat)half_size, (GLfloat)half_size, 0.0f);
|
|
|
|
::glVertex3f(-(GLfloat)half_size, (GLfloat)half_size, 0.0f);
|
|
|
|
::glVertex3f(-(GLfloat)half_size, -(GLfloat)half_size, 0.0f);
|
|
|
|
::glEnd();
|
2018-06-15 12:10:28 +00:00
|
|
|
}
|
2018-08-21 12:27:36 +00:00
|
|
|
#endif // ENABLE_GIZMOS_3D
|
2018-06-14 08:00:59 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
GLGizmoBase::GLGizmoBase()
|
2018-08-20 08:23:17 +00:00
|
|
|
: m_group_id(-1)
|
|
|
|
, m_state(Off)
|
2018-06-14 13:32:26 +00:00
|
|
|
, m_hover_id(-1)
|
2018-08-20 08:23:17 +00:00
|
|
|
, m_is_container(false)
|
2018-06-13 07:12:16 +00:00
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
::memcpy((void*)m_base_color, (const void*)DEFAULT_BASE_COLOR, 3 * sizeof(float));
|
|
|
|
::memcpy((void*)m_drag_color, (const void*)DEFAULT_DRAG_COLOR, 3 * sizeof(float));
|
|
|
|
::memcpy((void*)m_highlight_color, (const void*)DEFAULT_HIGHLIGHT_COLOR, 3 * sizeof(float));
|
2018-06-13 07:12:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoBase::set_hover_id(int id)
|
2018-06-15 12:10:28 +00:00
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
if (m_is_container || (id < (int)m_grabbers.size()))
|
|
|
|
{
|
|
|
|
m_hover_id = id;
|
|
|
|
on_set_hover_id();
|
|
|
|
}
|
2018-06-15 12:10:28 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoBase::set_highlight_color(const float* color)
|
2018-06-14 13:32:26 +00:00
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
if (color != nullptr)
|
|
|
|
::memcpy((void*)m_highlight_color, (const void*)color, 3 * sizeof(float));
|
2018-06-15 12:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoBase::start_dragging()
|
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
for (int i = 0; i < (int)m_grabbers.size(); ++i)
|
|
|
|
{
|
|
|
|
m_grabbers[i].dragging = (m_hover_id == i);
|
|
|
|
}
|
|
|
|
|
2018-06-18 13:07:17 +00:00
|
|
|
on_start_dragging();
|
2018-06-15 12:10:28 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 09:26:13 +00:00
|
|
|
void GLGizmoBase::stop_dragging()
|
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
for (int i = 0; i < (int)m_grabbers.size(); ++i)
|
|
|
|
{
|
|
|
|
m_grabbers[i].dragging = false;
|
|
|
|
}
|
|
|
|
|
2018-07-12 09:26:13 +00:00
|
|
|
on_stop_dragging();
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoBase::update(const Linef3& mouse_ray)
|
2018-06-15 12:10:28 +00:00
|
|
|
{
|
|
|
|
if (m_hover_id != -1)
|
2018-08-20 08:23:17 +00:00
|
|
|
on_update(mouse_ray);
|
2018-06-14 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
float GLGizmoBase::picking_color_component(unsigned int id) const
|
2018-07-12 09:26:13 +00:00
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
int color = 254 - (int)id;
|
|
|
|
if (m_group_id > -1)
|
|
|
|
color -= m_group_id;
|
2018-07-12 09:26:13 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
return (float)color / 255.0f;
|
2018-07-12 09:26:13 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoBase::render_grabbers() const
|
2018-07-12 09:26:13 +00:00
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
for (int i = 0; i < (int)m_grabbers.size(); ++i)
|
|
|
|
{
|
|
|
|
m_grabbers[i].render(m_hover_id == i);
|
|
|
|
}
|
2018-06-18 13:07:17 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoBase::render_grabbers_for_picking() const
|
2018-06-14 08:00:59 +00:00
|
|
|
{
|
2018-06-19 07:46:26 +00:00
|
|
|
for (int i = 0; i < (int)m_grabbers.size(); ++i)
|
2018-06-14 13:32:26 +00:00
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
m_grabbers[i].render_for_picking();
|
2018-06-14 13:32:26 +00:00
|
|
|
}
|
2018-06-14 08:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const float GLGizmoRotate::Offset = 5.0f;
|
|
|
|
const unsigned int GLGizmoRotate::CircleResolution = 64;
|
2018-06-15 14:16:55 +00:00
|
|
|
const unsigned int GLGizmoRotate::AngleResolution = 64;
|
2018-08-20 08:23:17 +00:00
|
|
|
const unsigned int GLGizmoRotate::ScaleStepsCount = 72;
|
2018-06-14 08:00:59 +00:00
|
|
|
const float GLGizmoRotate::ScaleStepRad = 2.0f * (float)PI / GLGizmoRotate::ScaleStepsCount;
|
2018-08-20 08:23:17 +00:00
|
|
|
const unsigned int GLGizmoRotate::ScaleLongEvery = 2;
|
2018-06-14 08:00:59 +00:00
|
|
|
const float GLGizmoRotate::ScaleLongTooth = 2.0f;
|
|
|
|
const float GLGizmoRotate::ScaleShortTooth = 1.0f;
|
|
|
|
const unsigned int GLGizmoRotate::SnapRegionsCount = 8;
|
|
|
|
const float GLGizmoRotate::GrabberOffset = 5.0f;
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
GLGizmoRotate::GLGizmoRotate(GLGizmoRotate::Axis axis)
|
2018-06-13 07:12:16 +00:00
|
|
|
: GLGizmoBase()
|
2018-08-20 08:23:17 +00:00
|
|
|
, m_axis(axis)
|
|
|
|
, m_angle(0.0f)
|
2018-08-23 13:37:38 +00:00
|
|
|
, m_center(0.0, 0.0, 0.0)
|
2018-06-15 14:16:55 +00:00
|
|
|
, m_radius(0.0f)
|
2018-08-15 10:50:06 +00:00
|
|
|
, m_keep_initial_values(false)
|
2018-06-13 07:12:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoRotate::set_angle(float angle)
|
2018-06-19 07:46:26 +00:00
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
if (std::abs(angle - 2.0f * PI) < EPSILON)
|
|
|
|
angle = 0.0f;
|
2018-06-19 07:46:26 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
m_angle = angle;
|
2018-06-19 07:46:26 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
bool GLGizmoRotate::on_init()
|
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
#if !ENABLE_GIZMOS_3D
|
2018-06-13 07:12:16 +00:00
|
|
|
std::string path = resources_dir() + "/icons/overlay/";
|
|
|
|
|
|
|
|
std::string filename = path + "rotate_off.png";
|
2018-06-14 08:37:28 +00:00
|
|
|
if (!m_textures[Off].load_from_file(filename, false))
|
2018-06-13 07:12:16 +00:00
|
|
|
return false;
|
2018-08-20 08:23:17 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
filename = path + "rotate_hover.png";
|
2018-06-14 08:37:28 +00:00
|
|
|
if (!m_textures[Hover].load_from_file(filename, false))
|
2018-06-13 07:12:16 +00:00
|
|
|
return false;
|
2018-08-20 08:23:17 +00:00
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
filename = path + "rotate_on.png";
|
2018-06-14 08:37:28 +00:00
|
|
|
if (!m_textures[On].load_from_file(filename, false))
|
2018-06-13 07:12:16 +00:00
|
|
|
return false;
|
2018-08-20 08:23:17 +00:00
|
|
|
#endif // !ENABLE_GIZMOS_3D
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
m_grabbers.push_back(Grabber());
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoRotate::on_update(const Linef3& mouse_ray)
|
2018-08-23 13:37:38 +00:00
|
|
|
{
|
|
|
|
Vec2d mouse_pos = to_2d(mouse_position_in_local_plane(mouse_ray));
|
2018-08-20 08:23:17 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
Vec2d orig_dir = Vec2d::UnitX();
|
|
|
|
Vec2d new_dir = mouse_pos.normalized();
|
2018-08-20 08:23:17 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
double theta = ::acos(clamp(-1.0, 1.0, new_dir.dot(orig_dir)));
|
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
2018-08-17 12:14:24 +00:00
|
|
|
if (cross2(orig_dir, new_dir) < 0.0)
|
2018-08-24 08:20:00 +00:00
|
|
|
theta = 2.0 * (double)PI - theta;
|
2018-06-15 14:16:55 +00:00
|
|
|
|
2018-06-19 07:46:26 +00:00
|
|
|
// snap
|
2018-08-23 13:37:38 +00:00
|
|
|
double len = mouse_pos.norm();
|
2018-08-20 08:23:17 +00:00
|
|
|
double in_radius = (double)m_radius / 3.0;
|
|
|
|
double out_radius = 2.0 * (double)in_radius;
|
|
|
|
if ((in_radius <= len) && (len <= out_radius))
|
2018-06-15 14:16:55 +00:00
|
|
|
{
|
2018-08-24 08:20:00 +00:00
|
|
|
double step = 2.0 * (double)PI / (double)SnapRegionsCount;
|
|
|
|
theta = step * (double)std::round(theta / step);
|
2018-06-15 14:16:55 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 08:20:00 +00:00
|
|
|
if (theta == 2.0 * (double)PI)
|
2018-06-15 14:16:55 +00:00
|
|
|
theta = 0.0;
|
2018-06-19 07:46:26 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
m_angle = (float)theta;
|
2018-06-15 12:10:28 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:44:04 +00:00
|
|
|
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
|
|
|
|
{
|
2018-08-21 12:27:36 +00:00
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
::glEnable(GL_DEPTH_TEST);
|
|
|
|
#else
|
2018-06-14 08:00:59 +00:00
|
|
|
::glDisable(GL_DEPTH_TEST);
|
2018-08-21 12:27:36 +00:00
|
|
|
#endif // ENABLE_GIZMOS_3D
|
2018-06-14 08:00:59 +00:00
|
|
|
|
2018-08-15 10:50:06 +00:00
|
|
|
if (!m_keep_initial_values)
|
2018-07-12 09:26:13 +00:00
|
|
|
{
|
2018-08-15 10:50:06 +00:00
|
|
|
m_center = box.center();
|
2018-08-20 08:23:17 +00:00
|
|
|
#if !ENABLE_GIZMOS_3D
|
2018-08-23 13:37:38 +00:00
|
|
|
const Vec3d& size = box.size();
|
|
|
|
m_center(2) = 0.0;
|
2018-08-20 08:23:17 +00:00
|
|
|
#endif // !ENABLE_GIZMOS_3D
|
|
|
|
|
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
m_radius = Offset + box.radius();
|
|
|
|
#else
|
2018-08-23 13:37:38 +00:00
|
|
|
m_radius = Offset + ::sqrt(sqr(0.5f * (float)size(0)) + sqr(0.5f * (float)size(1)));
|
2018-08-20 08:23:17 +00:00
|
|
|
#endif // ENABLE_GIZMOS_3D
|
2018-08-15 10:50:06 +00:00
|
|
|
m_keep_initial_values = true;
|
2018-07-12 09:26:13 +00:00
|
|
|
}
|
2018-06-14 08:00:59 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
::glPushMatrix();
|
|
|
|
transform_to_local();
|
|
|
|
|
|
|
|
#if ENABLE_GIZMOS_3D
|
2018-08-21 07:03:38 +00:00
|
|
|
::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f);
|
|
|
|
::glColor3fv((m_hover_id != -1) ? m_drag_color : m_highlight_color);
|
2018-08-20 08:23:17 +00:00
|
|
|
#else
|
2018-08-21 07:03:38 +00:00
|
|
|
::glLineWidth(2.0f);
|
2018-08-20 08:23:17 +00:00
|
|
|
::glColor3fv(m_drag_color);
|
|
|
|
#endif // ENABLE_GIZMOS_3D
|
2018-06-15 14:16:55 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
render_circle();
|
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
if (m_hover_id != -1)
|
|
|
|
{
|
|
|
|
#endif // ENABLE_GIZMOS_3D
|
|
|
|
render_scale();
|
|
|
|
render_snap_radii();
|
|
|
|
render_reference_radius();
|
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
}
|
|
|
|
#endif // ENABLE_GIZMOS_3D
|
|
|
|
|
|
|
|
::glColor3fv(m_highlight_color);
|
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
if (m_hover_id != -1)
|
|
|
|
#endif // ENABLE_GIZMOS_3D
|
|
|
|
render_angle();
|
|
|
|
|
|
|
|
render_grabber();
|
|
|
|
|
|
|
|
::glPopMatrix();
|
2018-06-14 08:00:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 13:32:26 +00:00
|
|
|
void GLGizmoRotate::on_render_for_picking(const BoundingBoxf3& box) const
|
|
|
|
{
|
2018-08-21 12:27:36 +00:00
|
|
|
#if ENABLE_GIZMOS_3D
|
|
|
|
::glEnable(GL_DEPTH_TEST);
|
|
|
|
#else
|
2018-06-14 13:32:26 +00:00
|
|
|
::glDisable(GL_DEPTH_TEST);
|
2018-08-21 12:27:36 +00:00
|
|
|
#endif // ENABLE_GIZMOS_3D
|
2018-06-14 13:32:26 +00:00
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
::glPushMatrix();
|
|
|
|
transform_to_local();
|
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
m_grabbers[0].color[0] = 1.0f;
|
|
|
|
m_grabbers[0].color[1] = 1.0f;
|
2018-08-20 08:23:17 +00:00
|
|
|
m_grabbers[0].color[2] = picking_color_component(0);
|
|
|
|
|
|
|
|
render_grabbers_for_picking();
|
|
|
|
|
|
|
|
::glPopMatrix();
|
2018-06-14 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoRotate::render_circle() const
|
2018-06-14 08:00:59 +00:00
|
|
|
{
|
|
|
|
::glBegin(GL_LINE_LOOP);
|
|
|
|
for (unsigned int i = 0; i < ScaleStepsCount; ++i)
|
|
|
|
{
|
|
|
|
float angle = (float)i * ScaleStepRad;
|
2018-08-20 08:23:17 +00:00
|
|
|
float x = ::cos(angle) * m_radius;
|
|
|
|
float y = ::sin(angle) * m_radius;
|
|
|
|
float z = 0.0f;
|
|
|
|
::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z);
|
2018-06-14 08:00:59 +00:00
|
|
|
}
|
|
|
|
::glEnd();
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoRotate::render_scale() const
|
2018-06-14 08:00:59 +00:00
|
|
|
{
|
2018-06-15 14:16:55 +00:00
|
|
|
float out_radius_long = m_radius + ScaleLongTooth;
|
|
|
|
float out_radius_short = m_radius + ScaleShortTooth;
|
2018-06-14 08:00:59 +00:00
|
|
|
|
|
|
|
::glBegin(GL_LINES);
|
|
|
|
for (unsigned int i = 0; i < ScaleStepsCount; ++i)
|
|
|
|
{
|
|
|
|
float angle = (float)i * ScaleStepRad;
|
|
|
|
float cosa = ::cos(angle);
|
|
|
|
float sina = ::sin(angle);
|
2018-08-20 08:23:17 +00:00
|
|
|
float in_x = cosa * m_radius;
|
|
|
|
float in_y = sina * m_radius;
|
|
|
|
float in_z = 0.0f;
|
|
|
|
float out_x = (i % ScaleLongEvery == 0) ? cosa * out_radius_long : cosa * out_radius_short;
|
|
|
|
float out_y = (i % ScaleLongEvery == 0) ? sina * out_radius_long : sina * out_radius_short;
|
|
|
|
float out_z = 0.0f;
|
|
|
|
::glVertex3f((GLfloat)in_x, (GLfloat)in_y, (GLfloat)in_z);
|
|
|
|
::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z);
|
2018-06-14 08:00:59 +00:00
|
|
|
}
|
|
|
|
::glEnd();
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoRotate::render_snap_radii() const
|
2018-06-14 08:00:59 +00:00
|
|
|
{
|
2018-06-15 14:16:55 +00:00
|
|
|
float step = 2.0f * (float)PI / (float)SnapRegionsCount;
|
2018-06-14 08:00:59 +00:00
|
|
|
|
2018-06-15 14:16:55 +00:00
|
|
|
float in_radius = m_radius / 3.0f;
|
2018-06-14 08:00:59 +00:00
|
|
|
float out_radius = 2.0f * in_radius;
|
|
|
|
|
|
|
|
::glBegin(GL_LINES);
|
|
|
|
for (unsigned int i = 0; i < SnapRegionsCount; ++i)
|
|
|
|
{
|
2018-06-15 14:16:55 +00:00
|
|
|
float angle = (float)i * step;
|
2018-06-14 08:00:59 +00:00
|
|
|
float cosa = ::cos(angle);
|
|
|
|
float sina = ::sin(angle);
|
2018-08-20 08:23:17 +00:00
|
|
|
float in_x = cosa * in_radius;
|
|
|
|
float in_y = sina * in_radius;
|
|
|
|
float in_z = 0.0f;
|
|
|
|
float out_x = cosa * out_radius;
|
|
|
|
float out_y = sina * out_radius;
|
|
|
|
float out_z = 0.0f;
|
|
|
|
::glVertex3f((GLfloat)in_x, (GLfloat)in_y, (GLfloat)in_z);
|
|
|
|
::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z);
|
2018-06-14 08:00:59 +00:00
|
|
|
}
|
|
|
|
::glEnd();
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoRotate::render_reference_radius() const
|
2018-06-14 08:00:59 +00:00
|
|
|
{
|
|
|
|
::glBegin(GL_LINES);
|
2018-08-20 08:23:17 +00:00
|
|
|
::glVertex3f(0.0f, 0.0f, 0.0f);
|
|
|
|
::glVertex3f((GLfloat)(m_radius + GrabberOffset), 0.0f, 0.0f);
|
2018-06-14 08:00:59 +00:00
|
|
|
::glEnd();
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoRotate::render_angle() const
|
2018-06-14 08:00:59 +00:00
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
float step_angle = m_angle / AngleResolution;
|
2018-06-15 14:16:55 +00:00
|
|
|
float ex_radius = m_radius + GrabberOffset;
|
2018-06-14 08:00:59 +00:00
|
|
|
|
2018-06-15 14:16:55 +00:00
|
|
|
::glBegin(GL_LINE_STRIP);
|
|
|
|
for (unsigned int i = 0; i <= AngleResolution; ++i)
|
|
|
|
{
|
|
|
|
float angle = (float)i * step_angle;
|
2018-08-20 08:23:17 +00:00
|
|
|
float x = ::cos(angle) * ex_radius;
|
|
|
|
float y = ::sin(angle) * ex_radius;
|
|
|
|
float z = 0.0f;
|
|
|
|
::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z);
|
2018-06-15 14:16:55 +00:00
|
|
|
}
|
|
|
|
::glEnd();
|
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoRotate::render_grabber() const
|
2018-06-15 14:16:55 +00:00
|
|
|
{
|
|
|
|
float grabber_radius = m_radius + GrabberOffset;
|
2018-08-23 13:37:38 +00:00
|
|
|
m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0);
|
2018-08-20 08:23:17 +00:00
|
|
|
m_grabbers[0].angle_z = m_angle;
|
|
|
|
|
|
|
|
#if ENABLE_GIZMOS_3D
|
2018-08-21 07:03:38 +00:00
|
|
|
::glColor3fv((m_hover_id != -1) ? m_drag_color : m_highlight_color);
|
2018-08-20 08:23:17 +00:00
|
|
|
#else
|
|
|
|
::glColor3fv(m_drag_color);
|
|
|
|
#endif // ENABLE_GIZMOS_3D
|
2018-06-15 14:16:55 +00:00
|
|
|
|
2018-06-14 08:00:59 +00:00
|
|
|
::glBegin(GL_LINES);
|
2018-08-20 08:23:17 +00:00
|
|
|
::glVertex3f(0.0f, 0.0f, 0.0f);
|
2018-08-23 13:37:38 +00:00
|
|
|
::glVertex3f((GLfloat)m_grabbers[0].center(0), (GLfloat)m_grabbers[0].center(1), (GLfloat)m_grabbers[0].center(2));
|
2018-06-14 08:00:59 +00:00
|
|
|
::glEnd();
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
::memcpy((void*)m_grabbers[0].color, (const void*)m_highlight_color, 3 * sizeof(float));
|
2018-06-15 12:10:28 +00:00
|
|
|
render_grabbers();
|
2018-06-13 13:44:04 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoRotate::transform_to_local() const
|
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
::glTranslatef((GLfloat)m_center(0), (GLfloat)m_center(1), (GLfloat)m_center(2));
|
2018-08-20 08:23:17 +00:00
|
|
|
|
|
|
|
switch (m_axis)
|
|
|
|
{
|
|
|
|
case X:
|
|
|
|
{
|
|
|
|
::glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
|
|
|
|
::glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Y:
|
|
|
|
{
|
|
|
|
::glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
|
|
|
|
::glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
case Z:
|
|
|
|
{
|
|
|
|
// no rotation
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) const
|
2018-08-20 08:23:17 +00:00
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
double half_pi = 0.5 * (double)PI;
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
Transform3d m = Transform3d::Identity();
|
2018-08-20 08:23:17 +00:00
|
|
|
|
|
|
|
switch (m_axis)
|
|
|
|
{
|
|
|
|
case X:
|
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
m.rotate(Eigen::AngleAxisd(-half_pi, Vec3d::UnitZ()));
|
|
|
|
m.rotate(Eigen::AngleAxisd(-half_pi, Vec3d::UnitY()));
|
2018-08-20 08:23:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Y:
|
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
m.rotate(Eigen::AngleAxisd(-(double)PI, Vec3d::UnitZ()));
|
|
|
|
m.rotate(Eigen::AngleAxisd(-half_pi, Vec3d::UnitX()));
|
2018-08-20 08:23:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
case Z:
|
|
|
|
{
|
|
|
|
// no rotation applied
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
m.translate(-m_center);
|
2018-08-20 08:23:17 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
Eigen::Matrix<double, 3, 2> world_ray;
|
|
|
|
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);
|
2018-08-20 08:23:17 +00:00
|
|
|
local_ray = m * world_ray.colwise().homogeneous();
|
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
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);
|
2018-08-20 08:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLGizmoRotate3D::GLGizmoRotate3D()
|
|
|
|
: GLGizmoBase()
|
|
|
|
, m_x(GLGizmoRotate::X)
|
|
|
|
, m_y(GLGizmoRotate::Y)
|
|
|
|
, m_z(GLGizmoRotate::Z)
|
|
|
|
{
|
|
|
|
m_is_container = true;
|
|
|
|
|
|
|
|
m_x.set_group_id(0);
|
|
|
|
m_y.set_group_id(1);
|
|
|
|
m_z.set_group_id(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLGizmoRotate3D::on_init()
|
|
|
|
{
|
|
|
|
if (!m_x.init() || !m_y.init() || !m_z.init())
|
|
|
|
return false;
|
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
m_x.set_highlight_color(RED);
|
|
|
|
m_y.set_highlight_color(GREEN);
|
|
|
|
m_z.set_highlight_color(BLUE);
|
2018-08-20 08:23:17 +00:00
|
|
|
|
|
|
|
std::string path = resources_dir() + "/icons/overlay/";
|
|
|
|
|
|
|
|
std::string filename = path + "rotate_off.png";
|
|
|
|
if (!m_textures[Off].load_from_file(filename, false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
filename = path + "rotate_hover.png";
|
|
|
|
if (!m_textures[Hover].load_from_file(filename, false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
filename = path + "rotate_on.png";
|
|
|
|
if (!m_textures[On].load_from_file(filename, false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoRotate3D::on_start_dragging()
|
|
|
|
{
|
|
|
|
switch (m_hover_id)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
m_x.start_dragging();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
m_y.start_dragging();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
m_z.start_dragging();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoRotate3D::on_stop_dragging()
|
|
|
|
{
|
|
|
|
switch (m_hover_id)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
m_x.stop_dragging();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
m_y.stop_dragging();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
m_z.stop_dragging();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoRotate3D::on_render(const BoundingBoxf3& box) const
|
|
|
|
{
|
|
|
|
if ((m_hover_id == -1) || (m_hover_id == 0))
|
|
|
|
m_x.render(box);
|
|
|
|
|
|
|
|
if ((m_hover_id == -1) || (m_hover_id == 1))
|
|
|
|
m_y.render(box);
|
|
|
|
|
|
|
|
if ((m_hover_id == -1) || (m_hover_id == 2))
|
|
|
|
m_z.render(box);
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:44:04 +00:00
|
|
|
const float GLGizmoScale::Offset = 5.0f;
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
GLGizmoScale::GLGizmoScale()
|
|
|
|
: GLGizmoBase()
|
2018-06-18 13:07:17 +00:00
|
|
|
, m_scale(1.0f)
|
|
|
|
, m_starting_scale(1.0f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
bool GLGizmoScale::on_init()
|
|
|
|
{
|
|
|
|
std::string path = resources_dir() + "/icons/overlay/";
|
|
|
|
|
|
|
|
std::string filename = path + "scale_off.png";
|
2018-06-14 08:37:28 +00:00
|
|
|
if (!m_textures[Off].load_from_file(filename, false))
|
2018-06-13 07:12:16 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
filename = path + "scale_hover.png";
|
2018-06-14 08:37:28 +00:00
|
|
|
if (!m_textures[Hover].load_from_file(filename, false))
|
2018-06-13 07:12:16 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
filename = path + "scale_on.png";
|
2018-06-14 08:37:28 +00:00
|
|
|
if (!m_textures[On].load_from_file(filename, false))
|
2018-06-13 07:12:16 +00:00
|
|
|
return false;
|
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
for (unsigned int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
m_grabbers.push_back(Grabber());
|
|
|
|
}
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-18 13:07:17 +00:00
|
|
|
void GLGizmoScale::on_start_dragging()
|
|
|
|
{
|
|
|
|
if (m_hover_id != -1)
|
2018-08-23 13:37:38 +00:00
|
|
|
m_starting_drag_position = to_2d(m_grabbers[m_hover_id].center);
|
2018-06-18 13:07:17 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 08:23:17 +00:00
|
|
|
void GLGizmoScale::on_update(const Linef3& mouse_ray)
|
2018-06-15 12:10:28 +00:00
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
Vec2d mouse_pos = to_2d(mouse_ray.intersect_plane(0.0));
|
2018-08-21 19:05:24 +00:00
|
|
|
Vec2d center(0.5 * (m_grabbers[1].center(0) + m_grabbers[0].center(0)), 0.5 * (m_grabbers[3].center(1) + m_grabbers[0].center(1)));
|
2018-06-15 12:10:28 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
double orig_len = (m_starting_drag_position - center).norm();
|
|
|
|
double new_len = (mouse_pos - center).norm();
|
|
|
|
double ratio = (orig_len != 0.0) ? new_len / orig_len : 1.0;
|
2018-06-15 12:10:28 +00:00
|
|
|
|
2018-06-18 13:07:17 +00:00
|
|
|
m_scale = m_starting_scale * (float)ratio;
|
2018-06-15 12:10:28 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:44:04 +00:00
|
|
|
void GLGizmoScale::on_render(const BoundingBoxf3& box) const
|
|
|
|
{
|
|
|
|
::glDisable(GL_DEPTH_TEST);
|
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
double min_x = box.min(0) - (double)Offset;
|
|
|
|
double max_x = box.max(0) + (double)Offset;
|
|
|
|
double min_y = box.min(1) - (double)Offset;
|
|
|
|
double max_y = box.max(1) + (double)Offset;
|
2018-06-13 13:44:04 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
m_grabbers[0].center = Vec3d(min_x, min_y, 0.0);
|
|
|
|
m_grabbers[1].center = Vec3d(max_x, min_y, 0.0);
|
|
|
|
m_grabbers[2].center = Vec3d(max_x, max_y, 0.0);
|
|
|
|
m_grabbers[3].center = Vec3d(min_x, max_y, 0.0);
|
2018-06-15 12:10:28 +00:00
|
|
|
|
2018-06-13 13:44:04 +00:00
|
|
|
::glLineWidth(2.0f);
|
2018-08-20 08:23:17 +00:00
|
|
|
::glColor3fv(m_drag_color);
|
|
|
|
|
2018-06-13 13:44:04 +00:00
|
|
|
// draw outline
|
2018-06-14 08:00:59 +00:00
|
|
|
::glBegin(GL_LINE_LOOP);
|
2018-06-15 12:10:28 +00:00
|
|
|
for (unsigned int i = 0; i < 4; ++i)
|
|
|
|
{
|
2018-08-17 13:53:43 +00:00
|
|
|
::glVertex3f((GLfloat)m_grabbers[i].center(0), (GLfloat)m_grabbers[i].center(1), 0.0f);
|
2018-06-15 12:10:28 +00:00
|
|
|
}
|
2018-06-13 13:44:04 +00:00
|
|
|
::glEnd();
|
|
|
|
|
|
|
|
// draw grabbers
|
2018-06-15 12:10:28 +00:00
|
|
|
for (unsigned int i = 0; i < 4; ++i)
|
|
|
|
{
|
2018-08-20 08:23:17 +00:00
|
|
|
::memcpy((void*)m_grabbers[i].color, (const void*)m_highlight_color, 3 * sizeof(float));
|
2018-06-15 12:10:28 +00:00
|
|
|
}
|
|
|
|
render_grabbers();
|
2018-06-14 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoScale::on_render_for_picking(const BoundingBoxf3& box) const
|
|
|
|
{
|
|
|
|
::glDisable(GL_DEPTH_TEST);
|
|
|
|
|
2018-06-15 12:10:28 +00:00
|
|
|
for (unsigned int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
m_grabbers[i].color[0] = 1.0f;
|
|
|
|
m_grabbers[i].color[1] = 1.0f;
|
2018-08-20 08:23:17 +00:00
|
|
|
m_grabbers[i].color[2] = picking_color_component(i);
|
2018-06-15 12:10:28 +00:00
|
|
|
}
|
2018-08-20 08:23:17 +00:00
|
|
|
render_grabbers_for_picking();
|
2018-06-13 13:44:04 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 06:50:35 +00:00
|
|
|
const float GLGizmoScale3D::Offset = 5.0f;
|
|
|
|
|
|
|
|
GLGizmoScale3D::GLGizmoScale3D()
|
|
|
|
: GLGizmoBase()
|
|
|
|
, m_scale_x(1.0f)
|
|
|
|
, m_scale_y(1.0f)
|
|
|
|
, m_scale_z(1.0f)
|
|
|
|
, m_starting_scale_x(1.0f)
|
|
|
|
, m_starting_scale_y(1.0f)
|
|
|
|
, m_starting_scale_z(1.0f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLGizmoScale3D::on_init()
|
|
|
|
{
|
|
|
|
std::string path = resources_dir() + "/icons/overlay/";
|
|
|
|
|
|
|
|
std::string filename = path + "scale_off.png";
|
|
|
|
if (!m_textures[Off].load_from_file(filename, false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
filename = path + "scale_hover.png";
|
|
|
|
if (!m_textures[Hover].load_from_file(filename, false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
filename = path + "scale_on.png";
|
|
|
|
if (!m_textures[On].load_from_file(filename, false))
|
|
|
|
return false;
|
|
|
|
|
2018-08-21 12:27:36 +00:00
|
|
|
for (int i = 0; i < 10; ++i)
|
2018-08-21 06:50:35 +00:00
|
|
|
{
|
|
|
|
m_grabbers.push_back(Grabber());
|
|
|
|
}
|
|
|
|
|
|
|
|
float half_pi = 0.5f * (float)PI;
|
|
|
|
|
|
|
|
// x axis
|
|
|
|
m_grabbers[0].angle_y = half_pi;
|
|
|
|
m_grabbers[1].angle_y = half_pi;
|
|
|
|
|
|
|
|
// y axis
|
|
|
|
m_grabbers[2].angle_x = half_pi;
|
|
|
|
m_grabbers[3].angle_x = half_pi;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoScale3D::on_start_dragging()
|
|
|
|
{
|
|
|
|
if (m_hover_id != -1)
|
2018-08-22 09:22:07 +00:00
|
|
|
{
|
2018-08-21 06:50:35 +00:00
|
|
|
m_starting_drag_position = m_grabbers[m_hover_id].center;
|
2018-08-22 09:22:07 +00:00
|
|
|
m_starting_center = m_box.center();
|
|
|
|
}
|
2018-08-21 06:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoScale3D::on_update(const Linef3& mouse_ray)
|
|
|
|
{
|
|
|
|
if ((m_hover_id == 0) || (m_hover_id == 1))
|
|
|
|
do_scale_x(mouse_ray);
|
|
|
|
else if ((m_hover_id == 2) || (m_hover_id == 3))
|
|
|
|
do_scale_y(mouse_ray);
|
|
|
|
else if ((m_hover_id == 4) || (m_hover_id == 5))
|
|
|
|
do_scale_z(mouse_ray);
|
2018-08-21 12:27:36 +00:00
|
|
|
else if (m_hover_id >= 6)
|
2018-08-21 06:50:35 +00:00
|
|
|
do_scale_uniform(mouse_ray);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
|
|
|
{
|
2018-08-21 12:27:36 +00:00
|
|
|
::glEnable(GL_DEPTH_TEST);
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
Vec3d offset_vec((double)Offset, (double)Offset, (double)Offset);
|
2018-08-21 06:50:35 +00:00
|
|
|
|
|
|
|
m_box = BoundingBoxf3(box.min - offset_vec, box.max + offset_vec);
|
2018-08-23 13:37:38 +00:00
|
|
|
const Vec3d& center = m_box.center();
|
2018-08-21 06:50:35 +00:00
|
|
|
|
|
|
|
// x axis
|
2018-08-23 13:37:38 +00:00
|
|
|
m_grabbers[0].center = Vec3d(m_box.min(0), center(1), center(2));
|
|
|
|
m_grabbers[1].center = Vec3d(m_box.max(0), center(1), center(2));
|
2018-08-21 06:50:35 +00:00
|
|
|
::memcpy((void*)m_grabbers[0].color, (const void*)RED, 3 * sizeof(float));
|
|
|
|
::memcpy((void*)m_grabbers[1].color, (const void*)RED, 3 * sizeof(float));
|
2018-08-21 12:27:36 +00:00
|
|
|
|
|
|
|
// y axis
|
2018-08-23 13:37:38 +00:00
|
|
|
m_grabbers[2].center = Vec3d(center(0), m_box.min(1), center(2));
|
|
|
|
m_grabbers[3].center = Vec3d(center(0), m_box.max(1), center(2));
|
2018-08-21 06:50:35 +00:00
|
|
|
::memcpy((void*)m_grabbers[2].color, (const void*)GREEN, 3 * sizeof(float));
|
|
|
|
::memcpy((void*)m_grabbers[3].color, (const void*)GREEN, 3 * sizeof(float));
|
2018-08-21 12:27:36 +00:00
|
|
|
|
|
|
|
// z axis
|
2018-08-23 13:37:38 +00:00
|
|
|
m_grabbers[4].center = Vec3d(center(0), center(1), m_box.min(2));
|
|
|
|
m_grabbers[5].center = Vec3d(center(0), center(1), m_box.max(2));
|
2018-08-21 06:50:35 +00:00
|
|
|
::memcpy((void*)m_grabbers[4].color, (const void*)BLUE, 3 * sizeof(float));
|
|
|
|
::memcpy((void*)m_grabbers[5].color, (const void*)BLUE, 3 * sizeof(float));
|
|
|
|
|
2018-08-21 12:27:36 +00:00
|
|
|
// uniform
|
2018-08-23 13:37:38 +00:00
|
|
|
m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(1), m_box.min(2));
|
|
|
|
m_grabbers[7].center = Vec3d(m_box.max(0), m_box.min(1), m_box.min(2));
|
|
|
|
m_grabbers[8].center = Vec3d(m_box.max(0), m_box.max(1), m_box.min(2));
|
|
|
|
m_grabbers[9].center = Vec3d(m_box.min(0), m_box.max(1), m_box.min(2));
|
2018-08-21 12:27:36 +00:00
|
|
|
for (int i = 6; i < 10; ++i)
|
|
|
|
{
|
|
|
|
::memcpy((void*)m_grabbers[i].color, (const void*)m_highlight_color, 3 * sizeof(float));
|
|
|
|
}
|
|
|
|
|
|
|
|
::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f);
|
2018-08-21 06:50:35 +00:00
|
|
|
|
|
|
|
if (m_hover_id == -1)
|
|
|
|
{
|
|
|
|
::glColor3fv(m_base_color);
|
2018-08-21 12:27:36 +00:00
|
|
|
// draw box
|
|
|
|
render_box();
|
2018-08-21 06:50:35 +00:00
|
|
|
// draw grabbers
|
|
|
|
render_grabbers();
|
|
|
|
}
|
|
|
|
else if ((m_hover_id == 0) || (m_hover_id == 1))
|
|
|
|
{
|
2018-08-21 12:27:36 +00:00
|
|
|
::glColor3fv(m_grabbers[0].color);
|
|
|
|
// draw connection
|
|
|
|
render_grabbers_connection(0, 1);
|
|
|
|
// draw grabbers
|
2018-08-21 06:50:35 +00:00
|
|
|
m_grabbers[0].render(true);
|
|
|
|
m_grabbers[1].render(true);
|
|
|
|
}
|
|
|
|
else if ((m_hover_id == 2) || (m_hover_id == 3))
|
|
|
|
{
|
2018-08-21 12:27:36 +00:00
|
|
|
::glColor3fv(m_grabbers[2].color);
|
|
|
|
// draw connection
|
|
|
|
render_grabbers_connection(2, 3);
|
|
|
|
// draw grabbers
|
2018-08-21 06:50:35 +00:00
|
|
|
m_grabbers[2].render(true);
|
|
|
|
m_grabbers[3].render(true);
|
|
|
|
}
|
|
|
|
else if ((m_hover_id == 4) || (m_hover_id == 5))
|
|
|
|
{
|
2018-08-21 12:27:36 +00:00
|
|
|
::glColor3fv(m_grabbers[4].color);
|
|
|
|
// draw connection
|
|
|
|
render_grabbers_connection(4, 5);
|
|
|
|
// draw grabbers
|
2018-08-21 06:50:35 +00:00
|
|
|
m_grabbers[4].render(true);
|
|
|
|
m_grabbers[5].render(true);
|
|
|
|
}
|
2018-08-21 12:27:36 +00:00
|
|
|
else if (m_hover_id >= 6)
|
2018-08-21 06:50:35 +00:00
|
|
|
{
|
|
|
|
::glColor3fv(m_drag_color);
|
2018-08-21 12:27:36 +00:00
|
|
|
// draw box
|
|
|
|
render_box();
|
|
|
|
// draw grabbers
|
|
|
|
for (int i = 6; i < 10; ++i)
|
|
|
|
{
|
|
|
|
m_grabbers[i].render(true);
|
|
|
|
}
|
2018-08-21 06:50:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoScale3D::on_render_for_picking(const BoundingBoxf3& box) const
|
|
|
|
{
|
2018-08-21 12:27:36 +00:00
|
|
|
::glEnable(GL_DEPTH_TEST);
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-21 12:27:36 +00:00
|
|
|
for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i)
|
2018-08-21 06:50:35 +00:00
|
|
|
{
|
|
|
|
m_grabbers[i].color[0] = 1.0f;
|
|
|
|
m_grabbers[i].color[1] = 1.0f;
|
|
|
|
m_grabbers[i].color[2] = picking_color_component(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
render_grabbers_for_picking();
|
|
|
|
}
|
|
|
|
|
2018-08-21 12:27:36 +00:00
|
|
|
void GLGizmoScale3D::render_box() const
|
2018-08-21 06:50:35 +00:00
|
|
|
{
|
2018-08-21 12:27:36 +00:00
|
|
|
// bottom face
|
2018-08-21 06:50:35 +00:00
|
|
|
::glBegin(GL_LINE_LOOP);
|
2018-08-23 13:37:38 +00:00
|
|
|
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.min(1), (GLfloat)m_box.min(2));
|
|
|
|
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.max(1), (GLfloat)m_box.min(2));
|
|
|
|
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.max(1), (GLfloat)m_box.min(2));
|
|
|
|
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.min(1), (GLfloat)m_box.min(2));
|
2018-08-21 06:50:35 +00:00
|
|
|
::glEnd();
|
|
|
|
|
2018-08-21 12:27:36 +00:00
|
|
|
// top face
|
2018-08-21 06:50:35 +00:00
|
|
|
::glBegin(GL_LINE_LOOP);
|
2018-08-23 13:37:38 +00:00
|
|
|
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.min(1), (GLfloat)m_box.max(2));
|
|
|
|
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.max(1), (GLfloat)m_box.max(2));
|
|
|
|
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.max(1), (GLfloat)m_box.max(2));
|
|
|
|
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.min(1), (GLfloat)m_box.max(2));
|
2018-08-21 12:27:36 +00:00
|
|
|
::glEnd();
|
|
|
|
|
|
|
|
// vertical edges
|
|
|
|
::glBegin(GL_LINES);
|
2018-08-23 13:37:38 +00:00
|
|
|
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.min(1), (GLfloat)m_box.min(2)); ::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.min(1), (GLfloat)m_box.max(2));
|
|
|
|
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.max(1), (GLfloat)m_box.min(2)); ::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.max(1), (GLfloat)m_box.max(2));
|
|
|
|
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.max(1), (GLfloat)m_box.min(2)); ::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.max(1), (GLfloat)m_box.max(2));
|
|
|
|
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.min(1), (GLfloat)m_box.min(2)); ::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.min(1), (GLfloat)m_box.max(2));
|
2018-08-21 06:50:35 +00:00
|
|
|
::glEnd();
|
|
|
|
}
|
|
|
|
|
2018-08-21 12:27:36 +00:00
|
|
|
void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const
|
2018-08-21 06:50:35 +00:00
|
|
|
{
|
2018-08-21 12:27:36 +00:00
|
|
|
unsigned int grabbers_count = (unsigned int)m_grabbers.size();
|
|
|
|
if ((id_1 < grabbers_count) && (id_2 < grabbers_count))
|
|
|
|
{
|
|
|
|
::glBegin(GL_LINES);
|
2018-08-23 13:37:38 +00:00
|
|
|
::glVertex3f((GLfloat)m_grabbers[id_1].center(0), (GLfloat)m_grabbers[id_1].center(1), (GLfloat)m_grabbers[id_1].center(2));
|
|
|
|
::glVertex3f((GLfloat)m_grabbers[id_2].center(0), (GLfloat)m_grabbers[id_2].center(1), (GLfloat)m_grabbers[id_2].center(2));
|
2018-08-21 12:27:36 +00:00
|
|
|
::glEnd();
|
|
|
|
}
|
2018-08-21 06:50:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
Linef3 transform(const Linef3& line, const Transform3d& t)
|
2018-08-21 06:50:35 +00:00
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
Eigen::Matrix<double, 3, 2> world_line;
|
|
|
|
Eigen::Matrix<double, 3, 2> local_line;
|
|
|
|
world_line(0, 0) = line.a(0);
|
|
|
|
world_line(1, 0) = line.a(1);
|
|
|
|
world_line(2, 0) = line.a(2);
|
|
|
|
world_line(0, 1) = line.b(0);
|
|
|
|
world_line(1, 1) = line.b(1);
|
|
|
|
world_line(2, 1) = line.b(2);
|
2018-08-21 06:50:35 +00:00
|
|
|
local_line = t * world_line.colwise().homogeneous();
|
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
return Linef3(Vec3d(local_line(0, 0), local_line(1, 0), local_line(2, 0)), Vec3d(local_line(0, 1), local_line(1, 1), local_line(2, 1)));
|
2018-08-21 06:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoScale3D::do_scale_x(const Linef3& mouse_ray)
|
|
|
|
{
|
2018-08-22 09:22:07 +00:00
|
|
|
double ratio = calc_ratio(1, mouse_ray, m_starting_center);
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-22 09:22:07 +00:00
|
|
|
if (ratio > 0.0)
|
|
|
|
m_scale_x = m_starting_scale_x * (float)ratio;
|
2018-08-21 06:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
|
|
|
|
{
|
2018-08-22 09:22:07 +00:00
|
|
|
double ratio = calc_ratio(2, mouse_ray, m_starting_center);
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-22 09:22:07 +00:00
|
|
|
if (ratio > 0.0)
|
|
|
|
m_scale_x = m_starting_scale_y * (float)ratio;
|
|
|
|
// m_scale_y = m_starting_scale_y * (float)ratio;
|
2018-08-21 06:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
|
|
|
|
{
|
2018-08-22 09:22:07 +00:00
|
|
|
double ratio = calc_ratio(1, mouse_ray, m_starting_center);
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-22 09:22:07 +00:00
|
|
|
if (ratio > 0.0)
|
|
|
|
m_scale_x = m_starting_scale_z * (float)ratio;
|
|
|
|
// m_scale_z = m_starting_scale_z * (float)ratio;
|
|
|
|
}
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-22 09:22:07 +00:00
|
|
|
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
|
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
Vec3d center = m_starting_center;
|
|
|
|
center(2) = m_box.min(2);
|
2018-08-22 09:22:07 +00:00
|
|
|
double ratio = calc_ratio(0, mouse_ray, center);
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-22 09:22:07 +00:00
|
|
|
if (ratio > 0.0)
|
2018-08-21 06:50:35 +00:00
|
|
|
{
|
2018-08-22 09:22:07 +00:00
|
|
|
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;
|
2018-08-21 06:50:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const
|
2018-08-21 06:50:35 +00:00
|
|
|
{
|
2018-08-22 09:22:07 +00:00
|
|
|
double ratio = 0.0;
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
Vec3d starting_vec = m_starting_drag_position - center;
|
|
|
|
double len_starting_vec = starting_vec.norm();
|
2018-08-22 09:22:07 +00:00
|
|
|
if (len_starting_vec == 0.0)
|
|
|
|
return ratio;
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
Vec3d starting_vec_dir = starting_vec.normalized();
|
|
|
|
Vec3d mouse_dir = mouse_ray.unit_vector();
|
2018-08-22 09:22:07 +00:00
|
|
|
unsigned int plane_id = preferred_plane_id;
|
|
|
|
|
|
|
|
// 1st try to see if the mouse direction is close enough to the preferred plane normal
|
|
|
|
double dot_to_normal = 0.0;
|
|
|
|
switch (plane_id)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
dot_to_normal = std::abs(mouse_dir.dot(Vec3d::UnitZ()));
|
2018-08-22 09:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
dot_to_normal = std::abs(mouse_dir.dot(-Vec3d::UnitY()));
|
2018-08-22 09:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
2018-08-23 13:37:38 +00:00
|
|
|
dot_to_normal = std::abs(mouse_dir.dot(Vec3d::UnitX()));
|
2018-08-22 09:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dot_to_normal < 0.1)
|
|
|
|
{
|
|
|
|
// if not, select the plane who's normal is closest to the mouse direction
|
|
|
|
|
|
|
|
typedef std::map<double, unsigned int> ProjsMap;
|
|
|
|
ProjsMap projs_map;
|
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(Vec3d::UnitZ())), 0)); // plane xy
|
|
|
|
projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(-Vec3d::UnitY())), 1)); // plane xz
|
|
|
|
projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(Vec3d::UnitX())), 2)); // plane yz
|
2018-08-22 09:22:07 +00:00
|
|
|
plane_id = projs_map.rbegin()->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (plane_id)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
// calculates the intersection of the mouse ray with the plane parallel to plane XY and passing through the given center
|
2018-08-23 13:37:38 +00:00
|
|
|
Transform3d m = Transform3d::Identity();
|
|
|
|
m.translate(-center);
|
|
|
|
Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0));
|
2018-08-22 09:22:07 +00:00
|
|
|
|
|
|
|
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
|
2018-08-23 13:37:38 +00:00
|
|
|
ratio = starting_vec_dir.dot(Vec3d(mouse_pos_2d(0), mouse_pos_2d(1), 0.0)) / len_starting_vec;
|
2018-08-22 09:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// calculates the intersection of the mouse ray with the plane parallel to plane XZ and passing through the given center
|
2018-08-23 13:37:38 +00:00
|
|
|
Transform3d m = Transform3d::Identity();
|
|
|
|
m.rotate(Eigen::AngleAxisd(-0.5 * (double)PI, Vec3d::UnitX()));
|
|
|
|
m.translate(-center);
|
|
|
|
Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0));
|
2018-08-22 09:22:07 +00:00
|
|
|
|
|
|
|
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
|
2018-08-23 13:37:38 +00:00
|
|
|
ratio = starting_vec_dir.dot(Vec3d(mouse_pos_2d(0), 0.0, mouse_pos_2d(1))) / len_starting_vec;
|
2018-08-22 09:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
// calculates the intersection of the mouse ray with the plane parallel to plane YZ and passing through the given center
|
2018-08-23 13:37:38 +00:00
|
|
|
Transform3d m = Transform3d::Identity();
|
|
|
|
m.rotate(Eigen::AngleAxisd(-0.5f * (double)PI, Vec3d::UnitY()));
|
|
|
|
m.translate(-center);
|
|
|
|
Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0));
|
2018-08-22 09:22:07 +00:00
|
|
|
|
|
|
|
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
|
2018-08-23 13:37:38 +00:00
|
|
|
ratio = starting_vec_dir.dot(Vec3d(0.0, mouse_pos_2d(1), -mouse_pos_2d(0))) / len_starting_vec;
|
2018-08-22 09:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-08-21 06:50:35 +00:00
|
|
|
|
2018-08-22 09:22:07 +00:00
|
|
|
return ratio;
|
2018-08-21 06:50:35 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|