Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEnrico Turri <enricoturri@seznam.cz>2019-06-13 10:12:44 +0300
committerEnrico Turri <enricoturri@seznam.cz>2019-06-13 10:12:44 +0300
commitf0b228c4d2f2d385bbfd3fe917fd928ffaadd1d3 (patch)
tree19f7b5f5803b8cefdfb6ec70d25669739a4fb8fb /src
parent26d48b7f5263e37cd891bdcdc49b7015e4bd0e47 (diff)
Added support for distance between camera position and camera target
Diffstat (limited to 'src')
-rw-r--r--src/slic3r/GUI/Camera.cpp15
-rw-r--r--src/slic3r/GUI/Camera.hpp5
2 files changed, 15 insertions, 5 deletions
diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp
index a9edb7626..4c7cb314a 100644
--- a/src/slic3r/GUI/Camera.cpp
+++ b/src/slic3r/GUI/Camera.cpp
@@ -22,11 +22,13 @@ static const float VIEW_REAR[2] = { 180.0f, 90.0f };
namespace Slic3r {
namespace GUI {
+const float Camera::DefaultDistance = 1000.0f;
+
Camera::Camera()
: type(Ortho)
, zoom(1.0f)
, phi(45.0f)
-// , distance(0.0f)
+ , distance(DefaultDistance)
, requires_zoom_to_bed(false)
, inverted_phi(false)
, m_theta(45.0f)
@@ -107,12 +109,18 @@ void Camera::apply_viewport(int x, int y, unsigned int w, unsigned int h) const
void Camera::apply_view_matrix() const
{
+ double theta_rad = Geometry::deg2rad(-(double)m_theta);
+ double phi_rad = Geometry::deg2rad((double)phi);
+ double sin_theta = ::sin(theta_rad);
+ Vec3d camera_pos = m_target + (double)distance * Vec3d(sin_theta * ::sin(phi_rad), sin_theta * ::cos(phi_rad), ::cos(theta_rad));
+
glsafe(::glMatrixMode(GL_MODELVIEW));
glsafe(::glLoadIdentity());
glsafe(::glRotatef(-m_theta, 1.0f, 0.0f, 0.0f)); // pitch
glsafe(::glRotatef(phi, 0.0f, 0.0f, 1.0f)); // yaw
- glsafe(::glTranslated(-m_target(0), -m_target(1), -m_target(2))); // target to origin
+
+ glsafe(::glTranslated(-camera_pos(0), -camera_pos(1), -camera_pos(2)));
glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, m_view_matrix.data()));
}
@@ -136,8 +144,7 @@ void Camera::apply_projection(const BoundingBoxf3& box) const
// FIXME: calculate a tighter value for depth will improve z-fighting
// Set at least some minimum depth in case the bounding box is empty to avoid an OpenGL driver error.
double depth = std::max(1.0, 5.0 * box.max_size());
- apply_ortho_projection(-w2, w2, -h2, h2, -depth, depth);
-
+ apply_ortho_projection(-w2, w2, -h2, h2, (double)distance - depth, (double)distance + depth);
break;
}
// case Perspective:
diff --git a/src/slic3r/GUI/Camera.hpp b/src/slic3r/GUI/Camera.hpp
index 4b719dc23..83dbb0f6d 100644
--- a/src/slic3r/GUI/Camera.hpp
+++ b/src/slic3r/GUI/Camera.hpp
@@ -9,6 +9,8 @@ namespace GUI {
struct Camera
{
+ static const float DefaultDistance;
+
enum EType : unsigned char
{
Unknown,
@@ -20,7 +22,8 @@ struct Camera
EType type;
float zoom;
float phi;
-// float distance;
+ // Distance between camera position and camera target measured along the camera Z axis
+ float distance;
bool requires_zoom_to_bed;
bool inverted_phi;