24 if (myParentID > (
int)
_graph.size() || myParentID < -1)
29 #ifdef SL_USE_ENTITIES_DEBUG
41 _graph[0].node->entityID(0);
42 if (
_graph[0].node->parent() !=
nullptr)
43 SL_EXIT_MSG(
"Root node parent pointer must be null");
52 SLint insertPos = myParentID + 1;
53 while (insertPos <
_graph.size() &&
_graph[insertPos].parentID >= myParentID)
57 if (entityID ==
_graph.size())
62 _graph[myParentID].childCount++;
66 if (
_graph[i].parentID > myParentID)
71 _graph[i].node->entityID(i);
75 if (
_graph[entityID].node->children().size())
79 SLNode* childNode =
_graph[entityID].node->children()[i];
91 if (
id >= 0 &&
id <
_graph.size())
102 if (
_graph[i].node == node)
113 if (
id >= 1 &&
id <
_graph.size())
124 if (entity.node == node)
125 return entity.parentID;
138 #ifdef SL_USE_ENTITIES_DEBUG
142 string nodeName =
"nodeOM: " + entity->
node->
name();
144 entity->
node->
om().print(nodeName.c_str());
152 #ifdef SL_USE_ENTITIES_DEBUG
156 string nodeName =
"nodeWM: " + entity->
node->
name();
158 nodeWM.
print(nodeName.c_str());
162 SLuint handledChildren = 0;
163 while (handledChildren < entity->childCount)
165 SLuint childID =
id + handledChildren + 1;
169 return handledChildren + 1;
197 while (myParentID != -1)
200 myParentID =
_graph[myParentID].parentID;
204 for (
int d = 1; d < (int)depth; ++d)
211 printf(
"%02u(%02d).%02d.%02u-%s\n",
213 _graph[i].node->entityID(),
223 printf(
"| %02u ", i);
231 if (
_graph[i].parentID == -1)
232 printf(
"|-1 %02u",
_graph[i].childCount);
234 printf(
"|%02u %02u",
_graph[i].parentID,
_graph[i].childCount);
237 cout <<
"----------------------------------------------------------" << endl;
246 assert(
id <=
_graph.size() &&
257 for (toID =
id + 1; toID <
_graph.size(); toID++)
258 if (
_graph[toID].parentID == myParentID)
263 _graph[myParentID].childCount--;
266 SLint numNodesToErase = toID - id;
268 if (
_graph[i].parentID > myParentID)
269 _graph[i].parentID =
_graph[i].parentID - numNodesToErase;
279 assert(
id <=
_graph.size() &&
286 for (toID =
id + 1; toID <
_graph.size(); toID++)
287 if (
_graph[toID].parentID == myParentID)
292 _graph[id].childCount = 0;
295 SLuint numNodesToErase = toID - id;
297 if (
_graph[i].parentID > myParentID)
298 _graph[i].parentID =
_graph[i].parentID - numNodesToErase;
#define SL_EXIT_MSG(message)
void deleteEntity(SLint id)
Deletes a node at index id with all its children.
void addChildEntity(SLint myParentID, SLEntity entity)
Adds a child into the vector nodes right after its parent.
SLuint size()
Returns the size of the entity vector.
SLint updateWMRec(SLint id, SLMat4f &parentWM)
Updates all world matrices and returns no. of updated.
void deleteChildren(SLint id)
Deletes all children of an entity with index id.
SLint getEntityID(SLNode *node)
Returns the ID of the entity with a SLNode pointer.
SLEntity * getParent(SLint id)
Returns the pointer to the parent of a node if id is valid else a nullptr.
SLVEntity _graph
Vector of SLEntity of entire scenegraph.
SLint getParentID(SLNode *node)
Returns the parentID of a SLNode pointer.
SLEntity * getEntity(SLint id)
Returns the pointer to a node if id is valid else a nullptr.
void dump(SLbool doTreeDump)
Dump scenegraph as a flat vector or as a tree.
SLbool isEqual(const SLMat4 &A, SLfloat epsilon=0.01f)
Returns true if one element of the matrix differs more than epsilon.
void print(const SLchar *str=nullptr) const
void setMatrix(const SLMat4 &A)
Set matrix by other 4x4 matrix.
SLMat4< T > inverted() const
Computes the inverse of a 4x4 non-singular matrix.
SLNode represents a node in a hierarchical scene graph.
const SLMat4f & updateAndGetWM() const
void om(const SLMat4f &mat)
void name(const SLstring &Name)
SLEntity is the Data Oriented Design version of a SLNode.
SLuint childCount
Number of children.
SLMat4f wm
World matrix for world transform.
SLint parentID
ID of the parent node (-1 of no parent)
SLMat4f wmI
Inverse world matrix.
SLNode * node
Pointer to the corresponding SLNode instance.
SLMat4f om
Object matrix for local transforms.