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

Camera.hpp « GUI « slic3r « src - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 18dec6083c7663949973b7461bebf4b3ff4ddcff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef slic3r_Camera_hpp_
#define slic3r_Camera_hpp_

#include "libslic3r/BoundingBox.hpp"
#include <array>

namespace Slic3r {
namespace GUI {

struct Camera
{
    static const float DefaultDistance;
    static double FrustrumMinZSize;
    static double FrustrumZMargin;

    enum EType : unsigned char
    {
        Unknown,
//        Perspective,
        Ortho,
        Num_types
    };

    EType type;
    float zoom;
    float phi;
    // Distance between camera position and camera target measured along the camera Z axis
    float distance;
    bool requires_zoom_to_bed;
    bool inverted_phi;

private:
    Vec3d m_target;
    float m_theta;

    mutable std::array<int, 4> m_viewport;
    mutable Transform3d m_view_matrix;
    mutable Transform3d m_projection_matrix;
    mutable std::pair<double, double> m_frustrum_zs;

    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; }
    void set_scene_box(const BoundingBoxf3& box){ m_scene_box = box; }

    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); }
    Vec3d get_dir_forward() const { return -m_view_matrix.matrix().block(0, 0, 3, 3).row(2); }

    Vec3d get_position() const { return m_view_matrix.matrix().inverse().block(0, 3, 3, 1); }

    double get_near_z() const { return m_frustrum_zs.first; }
    double get_far_z() const { return m_frustrum_zs.second; }

    void apply_viewport(int x, int y, unsigned int w, unsigned int h) const;
    void apply_view_matrix() const;
    void apply_projection(const BoundingBoxf3& box) const;

#if ENABLE_CAMERA_STATISTICS
    void debug_render() const;
#endif // ENABLE_CAMERA_STATISTICS

private:
    void apply_ortho_projection(double x_min, double x_max, double y_min, double y_max, double z_min, double z_max) const;
    // 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<double, double> calc_tight_frustrum_zs_around(const BoundingBoxf3& box) const;
};

} // GUI
} // Slic3r

#endif // slic3r_Camera_hpp_