2019-03-06 14:46:19 +00:00
|
|
|
#ifndef slic3r_Camera_hpp_
|
|
|
|
#define slic3r_Camera_hpp_
|
|
|
|
|
|
|
|
#include "libslic3r/BoundingBox.hpp"
|
2019-04-01 08:28:04 +00:00
|
|
|
#include <array>
|
2019-03-06 14:46:19 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
struct Camera
|
|
|
|
{
|
2019-06-13 07:12:44 +00:00
|
|
|
static const float DefaultDistance;
|
|
|
|
|
2019-03-06 14:46:19 +00:00
|
|
|
enum EType : unsigned char
|
|
|
|
{
|
|
|
|
Unknown,
|
|
|
|
// Perspective,
|
|
|
|
Ortho,
|
|
|
|
Num_types
|
|
|
|
};
|
|
|
|
|
|
|
|
EType type;
|
|
|
|
float zoom;
|
|
|
|
float phi;
|
2019-06-13 07:12:44 +00:00
|
|
|
// Distance between camera position and camera target measured along the camera Z axis
|
|
|
|
float distance;
|
2019-03-06 14:46:19 +00:00
|
|
|
bool requires_zoom_to_bed;
|
2019-04-30 13:09:25 +00:00
|
|
|
bool inverted_phi;
|
2019-03-06 14:46:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Vec3d m_target;
|
|
|
|
float m_theta;
|
|
|
|
|
2019-04-01 08:00:10 +00:00
|
|
|
mutable std::array<int, 4> m_viewport;
|
|
|
|
mutable Transform3d m_view_matrix;
|
|
|
|
mutable Transform3d m_projection_matrix;
|
|
|
|
|
2019-03-06 14:46:19 +00:00
|
|
|
BoundingBoxf3 m_scene_box;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Camera();
|
|
|
|
|
|
|
|
std::string get_type_as_string() const;
|
|
|
|
|
|
|
|
const Vec3d& get_target() const { return m_target; }
|
|
|
|
void set_target(const Vec3d& target);
|
|
|
|
|
|
|
|
float get_theta() const { return m_theta; }
|
|
|
|
void set_theta(float theta, bool apply_limit);
|
|
|
|
|
|
|
|
const BoundingBoxf3& get_scene_box() const { return m_scene_box; }
|
2019-05-16 13:54:11 +00:00
|
|
|
void set_scene_box(const BoundingBoxf3& box){ m_scene_box = box; }
|
2019-04-01 08:00:10 +00:00
|
|
|
|
|
|
|
bool select_view(const std::string& direction);
|
|
|
|
|
|
|
|
const std::array<int, 4>& get_viewport() const { return m_viewport; }
|
|
|
|
const Transform3d& get_view_matrix() const { return m_view_matrix; }
|
|
|
|
const Transform3d& get_projection_matrix() const { return m_projection_matrix; }
|
|
|
|
|
|
|
|
Vec3d get_dir_right() const { return m_view_matrix.matrix().block(0, 0, 3, 3).row(0); }
|
|
|
|
Vec3d get_dir_up() const { return m_view_matrix.matrix().block(0, 0, 3, 3).row(1); }
|
2019-06-13 06:38:49 +00:00
|
|
|
Vec3d get_dir_forward() const { return -m_view_matrix.matrix().block(0, 0, 3, 3).row(2); }
|
2019-04-01 08:00:10 +00:00
|
|
|
|
2019-06-13 06:47:38 +00:00
|
|
|
Vec3d get_position() const { return m_view_matrix.matrix().inverse().block(0, 3, 3, 1); }
|
2019-04-01 08:00:10 +00:00
|
|
|
|
|
|
|
void apply_viewport(int x, int y, unsigned int w, unsigned int h) const;
|
|
|
|
void apply_view_matrix() const;
|
2019-05-16 13:54:11 +00:00
|
|
|
void apply_projection(const BoundingBoxf3& box) const;
|
|
|
|
|
2019-05-20 07:39:57 +00:00
|
|
|
#if ENABLE_CAMERA_STATISTICS
|
|
|
|
void debug_render() const;
|
|
|
|
#endif // ENABLE_CAMERA_STATISTICS
|
|
|
|
|
2019-05-16 13:54:11 +00:00
|
|
|
private:
|
|
|
|
void apply_ortho_projection(double x_min, double x_max, double y_min, double y_max, double z_min, double z_max) const;
|
2019-03-06 14:46:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // GUI
|
|
|
|
} // Slic3r
|
|
|
|
|
|
|
|
#endif // slic3r_Camera_hpp_
|
|
|
|
|