Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
scene_node.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_SCENE_NODE_HPP__
4 #define SCENEVIEW_SCENE_NODE_HPP__
5 
6 #include <QVector3D>
7 #include <QQuaternion>
8 #include <QMatrix4x4>
9 
10 #include <sceneview/axis_aligned_box.hpp>
11 
12 namespace sv {
13 
19 enum class SceneNodeType {
20  kGroupNode,
21  kCameraNode,
22  kLightNode,
23  kDrawNode
24 };
25 
26 class GroupNode;
27 
41 class SceneNode {
42  public:
43  SceneNode(const SceneNode&) = delete;
44 
45  SceneNode& operator=(const SceneNode&) = delete;
46 
47  virtual ~SceneNode() {}
48 
52  virtual SceneNodeType NodeType() const = 0;
53 
57  const QString Name() const { return node_name_; }
58 
62  const QVector3D& Translation() const { return translation_; }
63 
67  const QQuaternion& Rotation() const { return rotation_; }
68 
72  const QVector3D& Scale() const { return scale_; }
73 
80  const QMatrix4x4& WorldTransform();
81 
85  bool Visible() const { return visible_; }
86 
90  virtual void SetTranslation(const QVector3D& vec);
91 
95  void SetTranslation(double x, double y, double z) {
96  SetTranslation(QVector3D(x, y, z));
97  }
98 
102  virtual void SetRotation(const QQuaternion& quat);
103 
107  virtual void SetScale(const QVector3D& vec);
108 
112  void SetScale(double x, double y, double z) {
113  SetScale(QVector3D(x, y, z));
114  }
115 
122  virtual void SetVisible(bool visible);
123 
127  GroupNode* ParentNode() { return parent_node_; }
128 
133  void SetParentNode(GroupNode* parent);
134 
142  void SetSelectionMask(int64_t mask) { selection_mask_ = mask; }
143 
147  int64_t GetSelectionMask() const { return selection_mask_; }
148 
155  virtual const AxisAlignedBox& WorldBoundingBox() = 0;
156 
157  protected:
161  explicit SceneNode(const QString& name);
162 
169  virtual void TransformChanged();
170 
176  virtual void BoundingBoxChanged();
177 
178  private:
179  friend class GroupNode;
180 
181  const QString node_name_;
182 
183  QVector3D translation_;
184  QQuaternion rotation_;
185  QVector3D scale_{1, 1, 1};
186 
187  QMatrix4x4 to_world_;
188  bool to_world_dirty_ = true;
189 
190  GroupNode* parent_node_ = nullptr;
191 
192  bool visible_ = true;
193  int64_t selection_mask_ = 0;
194 };
195 
196 } // namespace sv
197 
198 #endif // SCENEVIEW_SCENE_NODE_HPP__
virtual void SetScale(const QVector3D &vec)
Sets the scale component of the node to parent transform.
const QQuaternion & Rotation() const
Retrieve the rotation component of the node to parent transform.
Definition: scene_node.hpp:67
A scene graph node that can have children.
Definition: group_node.hpp:26
bool Visible() const
Check if the node is visible or not.
Definition: scene_node.hpp:85
virtual void SetTranslation(const QVector3D &vec)
Sets the translation component of the node transform.
Pure virtual class that all scene graph nodes inherit.
Definition: scene_node.hpp:41
void SetTranslation(double x, double y, double z)
Sets the translation component of the node transform.
Definition: scene_node.hpp:95
An axis-aligned box typically used for bounding box and intersection calculations.
Definition: axis_aligned_box.hpp:17
void SetSelectionMask(int64_t mask)
Sets the selection mask for this node.
Definition: scene_node.hpp:142
virtual const AxisAlignedBox & WorldBoundingBox()=0
Retrieve the world-space bounding box of the node and all of its children (if applicable).
virtual void TransformChanged()
Internal method, used to enable lazy matrix computations.
virtual void SetRotation(const QQuaternion &quat)
Sets the rotation component of the node to parent transform.
void SetParentNode(GroupNode *parent)
Sets the node's parent.
virtual void SetVisible(bool visible)
Sets the node visibility.
virtual SceneNodeType NodeType() const =0
Retrieve the node type.
SceneNodeType
Specifies a scene node type.
Definition: scene_node.hpp:19
void SetScale(double x, double y, double z)
Sets the scale component of the node to parent transform.
Definition: scene_node.hpp:112
const QVector3D & Scale() const
Retrieve the scale component of the node to parent transform.
Definition: scene_node.hpp:72
const QVector3D & Translation() const
Retrieve the translation component of the node to parent transform.
Definition: scene_node.hpp:62
int64_t GetSelectionMask() const
Retrieve the selection mask for this node.
Definition: scene_node.hpp:147
const QMatrix4x4 & WorldTransform()
Retrieve the transform from node coordinates to world coordinates.
const QString Name() const
Retrieve the node name.
Definition: scene_node.hpp:57
virtual void BoundingBoxChanged()
Internal method, used to enable lazy bounding box computations.
GroupNode * ParentNode()
Retrieve the parent of this node.
Definition: scene_node.hpp:127