SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLEntities.h
Go to the documentation of this file.
1 /**
2  * \file SLEntities.h
3  * \date June 2022
4  * \authors Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef SLENTITIES_H
11 #define SLENTITIES_H
12 
13 #include <SLMat4.h>
14 #include <SLMesh.h>
15 
16 using namespace std;
17 
18 //#define SL_USE_ENTITIES
19 //#define SL_USE_ENTITIES_DEBUG
20 
21 //-----------------------------------------------------------------------------
22 //! SLEntity is the Data Oriented Design version of a SLNode
23 /* This struct is an entity for a tightly packed vector without pointers for
24  * the parent-child relation. This allows a scene traversal with much less
25  * cache misses.
26  */
27 struct SLEntity
28 {
29  SLEntity(SLNode* myNode = nullptr)
30  : node(myNode),
31  parentID(0),
32  childCount(0) {}
33 
34  SLint parentID; //!< ID of the parent node (-1 of no parent)
35  SLuint childCount; //!< Number of children
36  SLMat4f om; //!< Object matrix for local transforms
37  SLMat4f wm; //!< World matrix for world transform
38  SLMat4f wmI; //!< Inverse world matrix
39  SLNode* node; //!< Pointer to the corresponding SLNode instance
40 };
41 //-----------------------------------------------------------------------------
42 //! Vector of SLEntity
43 typedef vector<SLEntity> SLVEntity;
44 //-----------------------------------------------------------------------------
45 //! Scenegraph in Data Oriented Design with flat std::vector of SLEntity
47 {
48 public:
49  //! Adds a child into the vector nodes right after its parent
50  void addChildEntity(SLint myParentID, SLEntity entity);
51 
52  //! Deletes a node at index id with all its children
53  void deleteEntity(SLint id);
54 
55  //! Deletes all children of an entity with index id
56  void deleteChildren(SLint id);
57 
58  //! Updates all world matrices and returns no. of updated
59  SLint updateWMRec(SLint id, SLMat4f& parentWM);
60 
61  //! Returns the pointer to a node if id is valid else a nullptr
62  SLEntity* getEntity(SLint id);
63 
64  //! Returns the ID of the entity with a SLNode pointer
65  SLint getEntityID(SLNode* node);
66 
67  //! Returns the pointer to the parent of a node if id is valid else a nullptr
68  SLEntity* getParent(SLint id);
69 
70  //! Returns the parentID of a SLNode pointer
71  SLint getParentID(SLNode* node);
72 
73  //! Dump scenegraph as a flat vector or as a tree
74  void dump(SLbool doTreeDump);
75 
76  //! Returns the size of the entity vector
77  SLuint size() { return (SLuint)_graph.size(); }
78 
79  //! Clears the the entities vector
80  void clear() { _graph.clear(); }
81 
82 private:
83  SLVEntity _graph; //!< Vector of SLEntity of entire scenegraph
84 };
85 //-----------------------------------------------------------------------------
86 #endif // SLENTITIES_H
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
int SLint
Definition: SL.h:170
vector< SLEntity > SLVEntity
Vector of SLEntity.
Definition: SLEntities.h:43
Scenegraph in Data Oriented Design with flat std::vector of SLEntity.
Definition: SLEntities.h:47
SLuint size()
Returns the size of the entity vector.
Definition: SLEntities.h:77
SLVEntity _graph
Vector of SLEntity of entire scenegraph.
Definition: SLEntities.h:83
void clear()
Clears the the entities vector.
Definition: SLEntities.h:80
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
SLEntity is the Data Oriented Design version of a SLNode.
Definition: SLEntities.h:28
SLuint childCount
Number of children.
Definition: SLEntities.h:35
SLMat4f wm
World matrix for world transform.
Definition: SLEntities.h:37
SLint parentID
ID of the parent node (-1 of no parent)
Definition: SLEntities.h:34
SLMat4f wmI
Inverse world matrix.
Definition: SLEntities.h:38
SLNode * node
Pointer to the corresponding SLNode instance.
Definition: SLEntities.h:39
SLEntity(SLNode *myNode=nullptr)
Definition: SLEntities.h:29
SLMat4f om
Object matrix for local transforms.
Definition: SLEntities.h:36