From fc886e3f8d34f7da164cb101588ace34189eaa74 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Thu, 24 Nov 2022 11:40:38 +0100 Subject: [PATCH] Fix for adding object with ortho camera --- src/slic3r/GUI/CameraUtils.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/slic3r/GUI/CameraUtils.cpp b/src/slic3r/GUI/CameraUtils.cpp index 7c5616594..c99616b34 100644 --- a/src/slic3r/GUI/CameraUtils.cpp +++ b/src/slic3r/GUI/CameraUtils.cpp @@ -104,6 +104,18 @@ Vec2d CameraUtils::get_z0_position(const Camera &camera, const Vec2d & coor) { Vec3d dir = CameraUtils::create_ray(camera, coor); Vec3d p0 = camera.get_position(); + if (camera.get_type() == Camera::EType::Ortho) { + Matrix4d modelview = camera.get_view_matrix().matrix(); + Matrix4d projection = camera.get_projection_matrix().matrix(); + Vec4i viewport(camera.get_viewport().data()); + igl::unproject(Vec3d(coor.x(), viewport[3] - coor.y(), 0.), modelview, projection, viewport, p0); + } + + // is approx zero + if ((fabs(dir.z()) - 1e-4) < 0) + return Vec2d(std::numeric_limits::max(), + std::numeric_limits::max()); + // find position of ray cross plane(z = 0) double t = p0.z() / dir.z(); Vec3d p = p0 - t * dir;