From 55a4b99e44ea544612125ef3fb475a73579514f1 Mon Sep 17 00:00:00 2001
From: Enrico Turri <enricoturri@seznam.cz>
Date: Thu, 7 Nov 2019 11:48:59 +0100
Subject: [PATCH] Fixed bug into Camera::set_target()

---
 src/slic3r/GUI/Camera.cpp     | 14 ++++++++------
 src/slic3r/GUI/GLCanvas3D.cpp |  4 ++--
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp
index 59f0a6c47..6ccb5af49 100644
--- a/src/slic3r/GUI/Camera.cpp
+++ b/src/slic3r/GUI/Camera.cpp
@@ -91,14 +91,16 @@ void Camera::select_next_type()
 
 void Camera::set_target(const Vec3d& target)
 {
-    // We may let these factors be customizable
-    static const double ScaleFactor = 1.1;
     BoundingBoxf3 test_box = m_scene_box;
+    test_box.translate(-m_scene_box.center());
+    // We may let this factor be customizable
+    static const double ScaleFactor = 1.5;
     test_box.scale(ScaleFactor);
-    m_target = target;
-    m_target(0) = clamp(test_box.min(0), test_box.max(0), m_target(0));
-    m_target(1) = clamp(test_box.min(1), test_box.max(1), m_target(1));
-    m_target(2) = clamp(test_box.min(2), test_box.max(2), m_target(2));
+    test_box.translate(m_scene_box.center());
+
+    m_target(0) = clamp(test_box.min(0), test_box.max(0), target(0));
+    m_target(1) = clamp(test_box.min(1), test_box.max(1), target(1));
+    m_target(2) = clamp(test_box.min(2), test_box.max(2), target(2));
 }
 
 void Camera::set_theta(float theta, bool apply_limit)
diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp
index 7786f55f3..76990fb89 100644
--- a/src/slic3r/GUI/GLCanvas3D.cpp
+++ b/src/slic3r/GUI/GLCanvas3D.cpp
@@ -1373,7 +1373,7 @@ void GLCanvas3D::set_model(Model* model)
 
 void GLCanvas3D::bed_shape_changed()
 {
-    m_camera.set_scene_box(scene_bounding_box());
+    refresh_camera_scene_box();
     m_camera.requires_zoom_to_bed = true;
     m_dirty = true;
     if (m_bed.is_prusa())
@@ -2116,7 +2116,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
         post_event(Event<bool>(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, false));
     }
 
-    m_camera.set_scene_box(scene_bounding_box());
+    refresh_camera_scene_box();
 
     if (m_selection.is_empty())
     {