Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
camera_node.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef BOT3_CAMERA_NODE_HPP__
4 #define BOT3_CAMERA_NODE_HPP__
5 
6 #include <QSize>
7 #include <QVector3D>
8 
9 #include <sceneview/scene_node.hpp>
10 
11 namespace sv {
12 
25 class CameraNode : public SceneNode {
26  public:
27  enum ProjectionType {
28  kOrthographic,
29  kPerspective,
30  // Manually defined projection matrix
31  kManual
32  };
33 
34  SceneNodeType NodeType() const override {
35  return SceneNodeType::kCameraNode; }
36 
45  void CopyFrom(const CameraNode& other);
46 
53  void SetViewportSize(int width, int height);
54 
58  QSize GetViewportSize() const;
59 
66  void SetPerspective(double vfov_deg, double z_near, double z_far);
67 
75  void SetOrthographic(double vfov_deg, double z_near, double z_far);
76 
80  void SetManual(const QMatrix4x4& proj_mat);
81 
85  ProjectionType GetProjectionType() const { return proj_type_; }
86 
90  void LookAt(const QVector3D& eye, const QVector3D& look_at,
91  const QVector3D& up);
92 
96  double GetVFovDeg() const { return vfov_deg_; }
97 
101  double GetZNear() const { return z_near_; }
102 
106  double GetZFar() const { return z_far_; }
107 
111  QVector3D GetLookDir() const;
112 
116  QVector3D GetLookAt() const;
117 
121  QVector3D GetUpDir() const;
122 
129  QVector3D Unproject(double x, double y);
130 
134  QMatrix4x4 GetProjectionMatrix();
135 
142  QMatrix4x4 GetViewMatrix();
143 
152  QMatrix4x4 GetViewProjectionMatrix();
153 
154  const AxisAlignedBox& WorldBoundingBox() override;
155 
156  void SetTranslation(const QVector3D& vec) override;
157 
158  void SetRotation(const QQuaternion& quat) override;
159 
160  private:
161  friend class Scene;
162 
163  explicit CameraNode(const QString& name);
164 
165  void ComputeProjectionMatrix();
166 
167  static const AxisAlignedBox kBoundingBox;
168 
169  QVector3D look_;
170  QVector3D up_;
171  QVector3D look_at_;
172 
173  int viewport_width_ = 0;
174  int viewport_height_ = 0;
175 
176  ProjectionType proj_type_;
177 
178  double vfov_deg_;
179 
180  double z_near_;
181  double z_far_;
182 
183  QMatrix4x4 projection_matrix_;
184 };
185 
186 } // namespace sv
187 
188 #endif // SCENEVIEW_VISCAMERA_HPP__
void SetTranslation(const QVector3D &vec) override
Sets the translation component of the node transform.
void LookAt(const QVector3D &eye, const QVector3D &look_at, const QVector3D &up)
Rotate and translate the camera to look at the specified point.
double GetVFovDeg() const
Retrieve the vertical field of view, in degrees.
Definition: camera_node.hpp:96
Pure virtual class that all scene graph nodes inherit.
Definition: scene_node.hpp:41
QVector3D GetLookAt() const
Retrieve the look at point.
void SetRotation(const QQuaternion &quat) override
Sets the rotation component of the node to parent transform.
void CopyFrom(const CameraNode &other)
Copies parameters in from the specified camera.
void SetOrthographic(double vfov_deg, double z_near, double z_far)
Sets orthographic projection mode.
An axis-aligned box typically used for bounding box and intersection calculations.
Definition: axis_aligned_box.hpp:17
void SetViewportSize(int width, int height)
Sets the size of the viewport.
QVector3D GetUpDir() const
Retrieve the camera's up vector.
Camera.
Definition: camera_node.hpp:25
SceneNodeType NodeType() const override
Retrieve the node type.
Definition: camera_node.hpp:34
void SetManual(const QMatrix4x4 &proj_mat)
Sets a manual projection matrix.
double GetZFar() const
Retrieve the far clipping plane.
Definition: camera_node.hpp:106
const AxisAlignedBox & WorldBoundingBox() override
Retrieve the world-space bounding box of the node and all of its children (if applicable).
A scene graph.
Definition: scene.hpp:36
QSize GetViewportSize() const
Retrieve the viewport size.
ProjectionType GetProjectionType() const
Retrieve the current projection type.
Definition: camera_node.hpp:85
QVector3D GetLookDir() const
Retrieve the direction the camera is facing.
QVector3D Unproject(double x, double y)
Computes a world-space direction corresponding to the specified screen-space pixel.
QMatrix4x4 GetViewProjectionMatrix()
Gets the combined projection and view matrix.
double GetZNear() const
Retrieve the near clipping plane.
Definition: camera_node.hpp:101
SceneNodeType
Specifies a scene node type.
Definition: scene_node.hpp:19
void SetPerspective(double vfov_deg, double z_near, double z_far)
Sets perspective projection mode.
QMatrix4x4 GetViewMatrix()
Retrieve the camera view matrix.
QMatrix4x4 GetProjectionMatrix()
Retrieve the camera projection matrix.