Skip to content

Commit

Permalink
SPE-2572 - Fixed panning of camera, in both 3D view and preview, when…
Browse files Browse the repository at this point in the history
… using multiple beds (#13621)
  • Loading branch information
enricoturri1966 authored and lukasmatena committed Dec 5, 2024
1 parent b713504 commit 63ce551
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/slic3r/GUI/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void Camera::set_type(EType type)
m_type = type;
if (m_update_config_on_type_change_enabled)
wxGetApp().app_config->set("use_perspective_camera", (m_type == EType::Perspective) ? "1" : "0");

update_projection();
}
}

Expand Down Expand Up @@ -634,6 +636,37 @@ void Camera::update_zenit()
m_zenit = Geometry::rad2deg(0.5 * M_PI - std::acos(std::clamp(-get_dir_forward().dot(Vec3d::UnitZ()), -1.0, 1.0)));
}

void Camera::update_projection()
{
double w = 0.5 * (double)m_viewport[2];
double h = 0.5 * (double)m_viewport[3];

const double inv_zoom = get_inv_zoom();
w *= inv_zoom;
h *= inv_zoom;

switch (m_type)
{
default:
case EType::Ortho:
{
m_gui_scale = 1.0;
break;
}
case EType::Perspective:
{
// scale near plane to keep w and h constant on the plane at z = m_distance
const double scale = m_frustrum_zs.first / m_distance;
w *= scale;
h *= scale;
m_gui_scale = scale;
break;
}
}

apply_projection(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second);
}

} // GUI
} // Slic3r

1 change: 1 addition & 0 deletions src/slic3r/GUI/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct Camera
void set_default_orientation();
Vec3d validate_target(const Vec3d& target) const;
void update_zenit();
void update_projection();
};

} // GUI
Expand Down
5 changes: 4 additions & 1 deletion src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7053,10 +7053,13 @@ Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, const float* z)
return hit.is_valid() ? hit.position.cast<double>() : _mouse_to_bed_3d(mouse_pos);
}
else {
const Camera& camera = wxGetApp().plater()->get_camera();
Camera& camera = wxGetApp().plater()->get_camera();
const Camera::EType type = camera.get_type();
camera.set_type(Camera::EType::Ortho);
const Vec4i viewport(camera.get_viewport().data());
Vec3d out;
igl::unproject(Vec3d(mouse_pos.x(), viewport[3] - mouse_pos.y(), *z), camera.get_view_matrix().matrix(), camera.get_projection_matrix().matrix(), viewport, out);
camera.set_type(type);
return out;
}
}
Expand Down

0 comments on commit 63ce551

Please sign in to comment.