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
virtual void SetScale(float aScale)
Definition: SceneGraphNode.hpp:96
float scale
Definition: SceneGraphNode.hpp:171
Contains meshes loaded from Aether3D&#39;s own .ae3d file format.
Definition: Model.hpp:21
virtual void SetName(const std::string &newName)
Definition: SceneGraphNode.hpp:84
Light.
Definition: Light.hpp:11
Type
Definition: SceneGraphNode.hpp:33
bool IsDirty() const
Definition: SceneGraphNode.hpp:138
Stores an orientation.
Definition: Quaternion.hpp:17
Perspective or orthographic camera.
Definition: Camera.hpp:12
virtual std::list< SceneGraphNode * > & Children()
Definition: SceneGraphNode.hpp:117
Matrix44 modelMatrix
Definition: SceneGraphNode.hpp:165
virtual void SetPosition(const Vec3 &aPosition)
Definition: SceneGraphNode.hpp:87
SceneGraphNode * parent
Definition: SceneGraphNode.hpp:175
virtual SceneGraphNode * Parent()
Definition: SceneGraphNode.hpp:105
Type type
Definition: SceneGraphNode.hpp:169
Stores scene in a scene graph.
Definition: Scene.hpp:27
3-component vector.
Definition: Vec3.hpp:22
virtual Type GetType() const
Definition: SceneGraphNode.hpp:111
Scene Graph Node. Models, Lights and Cameras are derived from this class.
Definition: SceneGraphNode.hpp:28
virtual std::string GetName() const
Definition: SceneGraphNode.hpp:108
virtual void SetRotation(const Quaternion &aRotation)
Definition: SceneGraphNode.hpp:90
std::string name
Definition: SceneGraphNode.hpp:179
Row-major 4x4 Matrix.
Definition: Matrix.hpp:20
std::list< SceneGraphNode * > children
Definition: SceneGraphNode.hpp:126
bool dirtyTransform
Definition: SceneGraphNode.hpp:181
virtual float GetScale() const
Definition: SceneGraphNode.hpp:99
virtual void SetLayerMask(unsigned mask)
Definition: SceneGraphNode.hpp:81
virtual Quaternion GetRotation() const
Definition: SceneGraphNode.hpp:93
Vec3 position
Definition: SceneGraphNode.hpp:173
virtual Vec3 GetPosition() const
Definition: SceneGraphNode.hpp:120
Quaternion rotation
Definition: SceneGraphNode.hpp:177
virtual unsigned GetLayerMask() const
Definition: SceneGraphNode.hpp:114