Aether3D
Game Engine
SceneGraphNode.hpp
1 #ifndef SCENEGRAPHNODE_H
2 #define SCENEGRAPHNODE_H
3 
4 #ifndef INCLUDE_LIST_H
5 # include <list>
6 # define INCLUDE_LIST_H
7 #endif
8 #ifndef INCLUDE_STRING_H
9 # include <string>
10 # define INCLUDE_STRING_H
11 #endif
12 #ifndef MATRIX_H
13 # include "Matrix.hpp"
14 #endif
15 #ifndef VEC3_H
16 # include "Vec3.hpp"
17 #endif
18 #ifndef QUATERNION_H
19 # include "Quaternion.hpp"
20 #endif
21 
22 class Scene;
23 
25 #ifdef SIMD_SSE3
26 class BEGIN_ALIGNED( SceneGraphNode, 16 )
27 #else
29 #endif
30 {
31  public:
33  enum class Type { None, Model, Camera, Light };
34 
44  static void RegisterScene( Scene* scene );
45 
49  static void UnregisterScene();
50 
53 
55  virtual ~SceneGraphNode();
56 
61  virtual bool AddChild( SceneGraphNode* child );
62 
67  virtual bool ContainsChild( const SceneGraphNode* node ) const;
68 
73  virtual void FindFirstChildWithName( const char* name, SceneGraphNode** outNode );
74 
81  virtual void SetLayerMask( unsigned mask ) { layerMask = mask; }
82 
84  virtual void SetName( const std::string& newName ) { name = newName; }
85 
87  virtual void SetPosition( const Vec3& aPosition ) { position = aPosition; dirtyTransform = true; }
88 
90  virtual void SetRotation( const Quaternion& aRotation ) { rotation = aRotation; dirtyTransform = true; }
91 
93  virtual Quaternion GetRotation() const { return rotation; }
94 
96  virtual void SetScale( float aScale ) { scale = aScale; dirtyTransform = true; }
97 
99  virtual float GetScale() const { return scale; }
100 
102  virtual void SolveMatrices();
103 
105  virtual SceneGraphNode* Parent() { return parent; }
106 
108  virtual std::string GetName() const { return name; }
109 
111  virtual Type GetType() const { return type; }
112 
114  virtual unsigned GetLayerMask() const { return layerMask; }
115 
117  virtual std::list< SceneGraphNode* >& Children() { return children; }
118 
120  virtual Vec3 GetPosition() const { return position; }
121 
123  virtual SceneGraphNode* Root();
124 
126  std::list< SceneGraphNode* > children;
127 
129  void CleanDirties();
130 
138  bool IsDirty() const
139  {
140  bool outDirty = dirtyTransform;
141 
142  if (outDirty)
143  {
144  return true;
145  }
146 
147  SceneGraphNode* testParent = parent;
148 
149  while (testParent)
150  {
151  if (testParent->dirtyTransform)
152  {
153  return true;
154  }
155  else
156  {
157  testParent = testParent->parent;
158  }
159  }
160 
161  return false;
162  }
163 
166 
167 protected:
171  float scale;
179  std::string name;
181  bool dirtyTransform = true;
183  unsigned layerMask = 0xFFFFFFFF;
184 
185  private:
192  void FindChild( const SceneGraphNode* node, bool& outFound ) const;
193 
196  static Scene* sScene;
197 }
198 #ifdef SIMD_SSE3
199 END_ALIGNED( SceneGraphNode, 16 )
200 #endif
201 ;
202 #endif
SceneGraphNode::Parent
virtual SceneGraphNode * Parent()
Definition: SceneGraphNode.hpp:105
Scene
Stores scene in a scene graph.
Definition: Scene.hpp:28
SceneGraphNode::children
std::list< SceneGraphNode * > children
Definition: SceneGraphNode.hpp:126
SceneGraphNode::SetScale
virtual void SetScale(float aScale)
Definition: SceneGraphNode.hpp:96
Camera
Perspective or orthographic camera.
Definition: Camera.hpp:12
SceneGraphNode::SetPosition
virtual void SetPosition(const Vec3 &aPosition)
Definition: SceneGraphNode.hpp:87
SceneGraphNode::GetLayerMask
virtual unsigned GetLayerMask() const
Definition: SceneGraphNode.hpp:114
SceneGraphNode::GetType
virtual Type GetType() const
Definition: SceneGraphNode.hpp:111
SceneGraphNode::GetName
virtual std::string GetName() const
Definition: SceneGraphNode.hpp:108
SceneGraphNode::modelMatrix
Matrix44 modelMatrix
Definition: SceneGraphNode.hpp:165
Light
Light.
Definition: Light.hpp:11
SceneGraphNode::dirtyTransform
bool dirtyTransform
Definition: SceneGraphNode.hpp:181
Vec3
3-component vector.
Definition: Vec3.hpp:22
SceneGraphNode::scale
float scale
Definition: SceneGraphNode.hpp:171
SceneGraphNode::name
std::string name
Definition: SceneGraphNode.hpp:179
SceneGraphNode::SetName
virtual void SetName(const std::string &newName)
Definition: SceneGraphNode.hpp:84
SceneGraphNode::GetPosition
virtual Vec3 GetPosition() const
Definition: SceneGraphNode.hpp:120
SceneGraphNode::SetLayerMask
virtual void SetLayerMask(unsigned mask)
Definition: SceneGraphNode.hpp:81
SceneGraphNode::GetRotation
virtual Quaternion GetRotation() const
Definition: SceneGraphNode.hpp:93
SceneGraphNode::Children
virtual std::list< SceneGraphNode * > & Children()
Definition: SceneGraphNode.hpp:117
SceneGraphNode::position
Vec3 position
Definition: SceneGraphNode.hpp:173
SceneGraphNode::Type
Type
Definition: SceneGraphNode.hpp:33
Quaternion
Stores an orientation.
Definition: Quaternion.hpp:17
Model
Contains meshes loaded from Aether3D's own .ae3d file format.
Definition: Model.hpp:21
Matrix44
Row-major 4x4 Matrix.
Definition: Matrix.hpp:20
SceneGraphNode::SetRotation
virtual void SetRotation(const Quaternion &aRotation)
Definition: SceneGraphNode.hpp:90
SceneGraphNode::rotation
Quaternion rotation
Definition: SceneGraphNode.hpp:177
SceneGraphNode
Scene Graph Node. Models, Lights and Cameras are derived from this class.
Definition: SceneGraphNode.hpp:28
SceneGraphNode::GetScale
virtual float GetScale() const
Definition: SceneGraphNode.hpp:99
SceneGraphNode::parent
SceneGraphNode * parent
Definition: SceneGraphNode.hpp:175
SceneGraphNode::type
Type type
Definition: SceneGraphNode.hpp:169
SceneGraphNode::IsDirty
bool IsDirty() const
Definition: SceneGraphNode.hpp:138