MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / updateObject

Method updateObject

src/collision/broadphase/DynamicAABBTree.cpp:186–214  ·  view source on GitHub ↗

Update the dynamic tree after an object has moved. If the new AABB of the object that has moved is still inside its fat AABB, then nothing is done. Otherwise, the corresponding node is removed and reinserted into the tree. The method returns true if the object has been reinserted into the tree. If the "forceReInsert" parameter is true, we force the existing AABB to take the size of the "newAABB" p

Source from the content-addressed store, hash-verified

184/// of the "newAABB" parameter even if it is larger than "newAABB". This can be used to shrink the
185/// AABB in the tree for instance if the corresponding collision shape has been shrunk.
186bool DynamicAABBTree::updateObject(int32 nodeID, const AABB& newAABB, bool forceReinsert) {
187
188 RP3D_PROFILE("DynamicAABBTree::updateObject()", mProfiler);
189
190 assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
191 assert(mNodes[nodeID].isLeaf());
192 assert(mNodes[nodeID].height >= 0);
193
194 // If the new AABB is still inside the fat AABB of the node
195 if (!forceReinsert && mNodes[nodeID].aabb.contains(newAABB)) {
196 return false;
197 }
198
199 // If the new AABB is outside the fat AABB, we remove the corresponding node
200 removeLeafNode(nodeID);
201
202 // Compute the fat AABB by inflating the AABB with by a constant percentage of the size of the AABB
203 mNodes[nodeID].aabb = newAABB;
204 const Vector3 gap(newAABB.getExtent() * mFatAABBInflatePercentage * decimal(0.5f));
205 mNodes[nodeID].aabb.mMinCoordinates -= gap;
206 mNodes[nodeID].aabb.mMaxCoordinates += gap;
207
208 assert(mNodes[nodeID].aabb.contains(newAABB));
209
210 // Reinsert the node into the tree
211 insertLeafNode(nodeID);
212
213 return true;
214}
215
216// Insert a leaf node in the tree. The process of inserting a new leaf node
217// in the dynamic tree is described in the book "Introduction to Game Physics

Callers 3

testOverlappingMethod · 0.80
testRaycastMethod · 0.80

Calls 3

isLeafMethod · 0.80
getExtentMethod · 0.80
containsMethod · 0.45

Tested by 2

testOverlappingMethod · 0.64
testRaycastMethod · 0.64