From a9529fbcdc314d4dc58b99cb53205dc6100538fd Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 16 Jan 2020 12:00:54 +0100 Subject: [PATCH] Added method void Camera::rotate_local_around_pivot(const Vec3d& rotation_rad, const Vec3d& pivot) to rotate the camera around a generic point --- src/slic3r/GUI/Camera.cpp | 13 ++++++++++--- src/slic3r/GUI/Camera.hpp | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index 49246dbb9..f2a560c08 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -442,12 +442,19 @@ void Camera::rotate_on_sphere(double delta_azimut_rad, double delta_zenit_rad) void Camera::rotate_local_around_target(const Vec3d& rotation_rad) { - Vec3d target = m_target; - translate_world(-target); + rotate_local_around_pivot(rotation_rad, m_target); +} + +void Camera::rotate_local_around_pivot(const Vec3d& rotation_rad, const Vec3d& pivot) +{ + // we use a copy of the pivot because a reference to the current m_target may be passed in (see i.e. rotate_local_around_target()) + // and m_target is modified by the translate_world() calls + Vec3d center = pivot; + translate_world(-center); m_view_matrix.rotate(Eigen::AngleAxisd(rotation_rad(0), get_dir_right())); m_view_matrix.rotate(Eigen::AngleAxisd(rotation_rad(1), get_dir_up())); m_view_matrix.rotate(Eigen::AngleAxisd(rotation_rad(2), get_dir_forward())); - translate_world(target); + translate_world(center); } bool Camera::is_looking_downward() const diff --git a/src/slic3r/GUI/Camera.hpp b/src/slic3r/GUI/Camera.hpp index 257b27901..87060e288 100644 --- a/src/slic3r/GUI/Camera.hpp +++ b/src/slic3r/GUI/Camera.hpp @@ -136,6 +136,9 @@ public: // rotate the camera around three axes parallel to the camera local axes and passing through m_target void rotate_local_around_target(const Vec3d& rotation_rad); + // rotate the camera around three axes parallel to the camera local axes and passing through the given pivot point + void rotate_local_around_pivot(const Vec3d& rotation_rad, const Vec3d& pivot); + // returns true if the camera z axis (forward) is pointing in the negative direction of the world z axis bool is_looking_downward() const; #endif // ENABLE_6DOF_CAMERA