1 #pragma once 2 3 /* 4 5 Camera 6 7 For usage, see QGLView.cc, GLView.cc, export_png.cc, openscad.cc 8 9 There are two different types of cameras represented in this class: 10 11 *Gimbal camera - uses Euler Angles, object translation, and viewer distance 12 *Vector camera - uses 'eye', 'center', and 'up' vectors ('lookat' style) 13 14 They are not necessarily kept in sync. There are two modes of 15 projection, Perspective and Orthogonal. 16 17 */ 18 19 #include "linalg.h" 20 #include "modcontext.h" 21 #include <vector> 22 #include <Eigen/Geometry> 23 24 class Camera 25 { 26 public: 27 enum class ProjectionType { ORTHOGONAL, PERSPECTIVE } projection; 28 Camera(); 29 void setup(std::vector<double> params); 30 void gimbalDefaultTranslate(); 31 void setProjection(ProjectionType type); 32 void zoom(int delta, bool relative); 33 double zoomValue() const; 34 double fovValue() const; 35 void resetView(); 36 void updateView(const std::shared_ptr<class FileContext> ctx, bool enableWarning); 37 void viewAll(const BoundingBox &bbox); 38 std::string statusText() const; 39 40 // accessors to get and set camera settings in the user space format (different for historical reasons) 41 Eigen::Vector3d getVpt() const; 42 void setVpt(double x, double y, double z); 43 Eigen::Vector3d getVpr() const; 44 void setVpr(double x, double y, double z); 45 void setVpd(double d); 46 void setVpf(double d); 47 48 // Gimbalcam 49 Eigen::Vector3d object_trans; 50 Eigen::Vector3d object_rot; 51 52 // Perspective settings 53 double fov; // Field of view 54 55 // true if camera should try to view everything in a given 56 // bounding box. 57 bool viewall; 58 59 // true if camera should point at center of bounding box 60 // (normally it points at 0,0,0 or at given coordinates) 61 bool autocenter; 62 63 unsigned int pixel_width; 64 unsigned int pixel_height; 65 66 // true if camera settings are fixed 67 // (--camera option in commandline mode) 68 bool locked; 69 70 protected: 71 // Perspective settings 72 double viewer_distance; 73 }; 74