diff --git a/src/libslic3r/Point.hpp b/src/libslic3r/Point.hpp index e5ce68420..ceb235244 100644 --- a/src/libslic3r/Point.hpp +++ b/src/libslic3r/Point.hpp @@ -27,6 +27,7 @@ using Vec2crd = Eigen::Matrix; using Vec3crd = Eigen::Matrix; using Vec2i = Eigen::Matrix; using Vec3i = Eigen::Matrix; +using Vec4i = Eigen::Matrix; using Vec2i32 = Eigen::Matrix; using Vec2i64 = Eigen::Matrix; using Vec3i32 = Eigen::Matrix; @@ -50,12 +51,15 @@ using Matrix2f = Eigen::Matrix; using Matrix2d = Eigen::Matrix; using Matrix3f = Eigen::Matrix; using Matrix3d = Eigen::Matrix; +using Matrix4f = Eigen::Matrix; +using Matrix4d = Eigen::Matrix; using Transform2f = Eigen::Transform; using Transform2d = Eigen::Transform; using Transform3f = Eigen::Transform; using Transform3d = Eigen::Transform; + inline bool operator<(const Vec2d &lhs, const Vec2d &rhs) { return lhs(0) < rhs(0) || (lhs(0) == rhs(0) && lhs(1) < rhs(1)); } template diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index eaa4c7f0d..880e69bbd 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1,6 +1,8 @@ #include "libslic3r/libslic3r.h" #include "GLCanvas3D.hpp" +#include + #include "libslic3r/ClipperUtils.hpp" #include "libslic3r/PrintConfig.hpp" #include "libslic3r/GCode/ThumbnailData.hpp" @@ -5391,9 +5393,9 @@ Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z) return Vec3d(DBL_MAX, DBL_MAX, DBL_MAX); const Camera& camera = wxGetApp().plater()->get_camera(); - const std::array& viewport = camera.get_viewport(); - const Transform3d& modelview_matrix = camera.get_view_matrix(); - const Transform3d& projection_matrix = camera.get_projection_matrix(); + Matrix4d modelview = camera.get_view_matrix().matrix(); + Matrix4d projection= camera.get_projection_matrix().matrix(); + Vec4i viewport(camera.get_viewport().data()); GLint y = viewport[3] - (GLint)mouse_pos(1); GLfloat mouse_z; @@ -5402,9 +5404,9 @@ Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z) else mouse_z = *z; - GLdouble out_x, out_y, out_z; - ::gluUnProject((GLdouble)mouse_pos(0), (GLdouble)y, (GLdouble)mouse_z, (GLdouble*)modelview_matrix.data(), (GLdouble*)projection_matrix.data(), (GLint*)viewport.data(), &out_x, &out_y, &out_z); - return Vec3d((double)out_x, (double)out_y, (double)out_z); + Vec3d out; + igl::unproject(Vec3d(mouse_pos(0), y, mouse_z), modelview, projection, viewport, out); + return out; } Vec3d GLCanvas3D::_mouse_to_bed_3d(const Point& mouse_pos) diff --git a/src/slic3r/GUI/GLSelectionRectangle.cpp b/src/slic3r/GUI/GLSelectionRectangle.cpp index d7f3f7a3a..13467499a 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.cpp +++ b/src/slic3r/GUI/GLSelectionRectangle.cpp @@ -4,6 +4,7 @@ #include "GLCanvas3D.hpp" #include "GUI_App.hpp" #include "Plater.hpp" +#include #include @@ -38,23 +39,26 @@ namespace GUI { m_state = Off; const Camera& camera = wxGetApp().plater()->get_camera(); - const std::array& viewport = camera.get_viewport(); - const Transform3d& modelview_matrix = camera.get_view_matrix(); - const Transform3d& projection_matrix = camera.get_projection_matrix(); + Matrix4d modelview = camera.get_view_matrix().matrix(); + Matrix4d projection= camera.get_projection_matrix().matrix(); + Vec4i viewport(camera.get_viewport().data()); + + // Convert our std::vector to Eigen dynamic matrix. + Eigen::Matrix pts(points.size(), 3); + for (size_t i=0; i(i, 0) = points[i]; + + // Get the projections. + Eigen::Matrix projections; + igl::project(pts, modelview, projection, viewport, projections); // bounding box created from the rectangle corners - will take care of order of the corners BoundingBox rectangle(Points{ Point(m_start_corner.cast()), Point(m_end_corner.cast()) }); // Iterate over all points and determine whether they're in the rectangle. - for (unsigned int i = 0; i +#include + namespace Slic3r { namespace GUI { @@ -122,14 +124,16 @@ Vec3f MeshRaycaster::get_triangle_normal(size_t facet_idx) const void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, Vec3d& point, Vec3d& direction) const { - const std::array& viewport = camera.get_viewport(); - const Transform3d& model_mat = camera.get_view_matrix(); - const Transform3d& proj_mat = camera.get_projection_matrix(); + Matrix4d modelview = camera.get_view_matrix().matrix(); + Matrix4d projection= camera.get_projection_matrix().matrix(); + Vec4i viewport(camera.get_viewport().data()); Vec3d pt1; Vec3d pt2; - ::gluUnProject(mouse_pos(0), viewport[3] - mouse_pos(1), 0., model_mat.data(), proj_mat.data(), viewport.data(), &pt1(0), &pt1(1), &pt1(2)); - ::gluUnProject(mouse_pos(0), viewport[3] - mouse_pos(1), 1., model_mat.data(), proj_mat.data(), viewport.data(), &pt2(0), &pt2(1), &pt2(2)); + igl::unproject(Vec3d(mouse_pos(0), viewport[3] - mouse_pos(1), 0.), + modelview, projection, viewport, pt1); + igl::unproject(Vec3d(mouse_pos(0), viewport[3] - mouse_pos(1), 1.), + modelview, projection, viewport, pt2); Transform3d inv = trafo.inverse(); pt1 = inv * pt1;