diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index d8b80f1ce8..a01e76ea4c 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -116,23 +116,22 @@ void Camera::apply_view_matrix() const glsafe(::glMultMatrixd(m_view_matrix.data())); } -void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double far_z) const +void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double far_z) { double w = 0.0; double h = 0.0; const double old_distance = m_distance; - std::pair* frustrum_zs = const_cast*>(&m_frustrum_zs); - *frustrum_zs = calc_tight_frustrum_zs_around(box); + m_frustrum_zs = calc_tight_frustrum_zs_around(box); if (m_distance != old_distance) // the camera has been moved re-apply view matrix apply_view_matrix(); if (near_z > 0.0) - frustrum_zs->first = std::max(std::min(frustrum_zs->first, near_z), FrustrumMinNearZ); + m_frustrum_zs.first = std::max(std::min(m_frustrum_zs.first, near_z), FrustrumMinNearZ); if (far_z > 0.0) - frustrum_zs->second = std::max(frustrum_zs->second, far_z); + m_frustrum_zs.second = std::max(m_frustrum_zs.second, far_z); w = 0.5 * (double)m_viewport[2]; h = 0.5 * (double)m_viewport[3]; @@ -146,16 +145,16 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa default: case Ortho: { - *const_cast(&m_gui_scale) = 1.0; + m_gui_scale = 1.0; break; } case Perspective: { // scale near plane to keep w and h constant on the plane at z = m_distance - const double scale = frustrum_zs->first / m_distance; + const double scale = m_frustrum_zs.first / m_distance; w *= scale; h *= scale; - *const_cast(&m_gui_scale) = scale; + m_gui_scale = scale; break; } } @@ -168,17 +167,17 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa default: case Ortho: { - glsafe(::glOrtho(-w, w, -h, h, frustrum_zs->first, frustrum_zs->second)); + glsafe(::glOrtho(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second)); break; } case Perspective: { - glsafe(::glFrustum(-w, w, -h, h, frustrum_zs->first, frustrum_zs->second)); + glsafe(::glFrustum(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second)); break; } } - glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, const_cast(&m_projection_matrix)->data())); + glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, m_projection_matrix.data())); glsafe(::glMatrixMode(GL_MODELVIEW)); } @@ -292,7 +291,7 @@ void Camera::rotate_local_around_target(const Vec3d& rotation_rad) } } -std::pair Camera::calc_tight_frustrum_zs_around(const BoundingBoxf3& box) const +std::pair Camera::calc_tight_frustrum_zs_around(const BoundingBoxf3& box) { std::pair ret; auto& [near_z, far_z] = ret; @@ -448,11 +447,11 @@ double Camera::calc_zoom_to_volumes_factor(const GLVolumePtrs& volumes, Vec3d& c return std::min((double)m_viewport[2] / dx, (double)m_viewport[3] / dy); } -void Camera::set_distance(double distance) const +void Camera::set_distance(double distance) { if (m_distance != distance) { - const_cast(&m_view_matrix)->translate((distance - m_distance) * get_dir_forward()); - *const_cast(&m_distance) = distance; + m_view_matrix.translate((distance - m_distance) * get_dir_forward()); + m_distance = distance; } } diff --git a/src/slic3r/GUI/Camera.hpp b/src/slic3r/GUI/Camera.hpp index 1abb430ca9..7fbe1d55c7 100644 --- a/src/slic3r/GUI/Camera.hpp +++ b/src/slic3r/GUI/Camera.hpp @@ -95,7 +95,7 @@ public: void apply_view_matrix() const; // Calculates and applies the projection matrix tighting the frustrum z range around the given box. // If larger z span is needed, pass the desired values of near and far z (negative values are ignored) - void apply_projection(const BoundingBoxf3& box, double near_z = -1.0, double far_z = -1.0) const; + void apply_projection(const BoundingBoxf3& box, double near_z = -1.0, double far_z = -1.0); void zoom_to_box(const BoundingBoxf3& box, double margin_factor = DefaultZoomToBoxMarginFactor); void zoom_to_volumes(const GLVolumePtrs& volumes, double margin_factor = DefaultZoomToVolumesMarginFactor); @@ -132,10 +132,10 @@ public: private: // returns tight values for nearZ and farZ plane around the given bounding box // the camera MUST be outside of the bounding box in eye coordinate of the given box - std::pair calc_tight_frustrum_zs_around(const BoundingBoxf3& box) const; + std::pair calc_tight_frustrum_zs_around(const BoundingBoxf3& box); double calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, double margin_factor = DefaultZoomToBoxMarginFactor) const; double calc_zoom_to_volumes_factor(const GLVolumePtrs& volumes, Vec3d& center, double margin_factor = DefaultZoomToVolumesMarginFactor) const; - void set_distance(double distance) const; + void set_distance(double distance); void set_default_orientation(); Vec3d validate_target(const Vec3d& target) const;