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

Method destroyJoint

src/engine/PhysicsWorld.cpp:606–656  ·  view source on GitHub ↗

Destroy a joint * @param joint Pointer to the joint you want to destroy */

Source from the content-addressed store, hash-verified

604 * @param joint Pointer to the joint you want to destroy
605 */
606void PhysicsWorld::destroyJoint(Joint* joint) {
607
608 assert(joint != nullptr);
609
610 RP3D_LOG(mConfig.worldName, Logger::Level::Information, Logger::Category::Joint,
611 "Joint " + std::to_string(joint->getEntity().id) + ": joint destroyed", __FILE__, __LINE__);
612
613 // If the collision between the two bodies of the constraint was disabled
614 if (!joint->isCollisionEnabled()) {
615
616 // Remove the pair of bodies from the set of body pairs that cannot collide with each other
617 mCollisionDetection.removeNoCollisionPair(joint->getBody1()->getEntity(), joint->getBody2()->getEntity());
618 }
619
620 RigidBody* body1 = joint->getBody1();
621 RigidBody* body2 = joint->getBody2();
622
623 // Wake up the two bodies of the joint
624 body1->setIsSleeping(false);
625 body2->setIsSleeping(false);
626
627 // Remove the joint from the joint array of the bodies involved in the joint
628 mRigidBodyComponents.removeJointFromBody(body1->getEntity(), joint->getEntity());
629 mRigidBodyComponents.removeJointFromBody(body2->getEntity(), joint->getEntity());
630
631 size_t nbBytes = joint->getSizeInBytes();
632
633 Entity jointEntity = joint->getEntity();
634
635 // Destroy the corresponding entity and its components
636 mJointsComponents.removeComponent(jointEntity);
637 if (mBallAndSocketJointsComponents.hasComponent(jointEntity)) {
638 mBallAndSocketJointsComponents.removeComponent(jointEntity);
639 }
640 if (mFixedJointsComponents.hasComponent(jointEntity)) {
641 mFixedJointsComponents.removeComponent(jointEntity);
642 }
643 if (mHingeJointsComponents.hasComponent(jointEntity)) {
644 mHingeJointsComponents.removeComponent(jointEntity);
645 }
646 if (mSliderJointsComponents.hasComponent(jointEntity)) {
647 mSliderJointsComponents.removeComponent(jointEntity);
648 }
649 mEntityManager.destroyEntity(jointEntity);
650
651 // Call the destructor of the joint
652 joint->~Joint();
653
654 // Release the allocated memory
655 mMemoryManager.release(MemoryManager::AllocationType::Pool, joint, nbBytes);
656}
657
658
659// Set the number of iterations for the velocity constraint solver

Callers 3

updatePhysicsMethod · 0.80
initBodiesPositionsMethod · 0.80

Calls 13

isCollisionEnabledMethod · 0.80
removeNoCollisionPairMethod · 0.80
removeJointFromBodyMethod · 0.80
removeComponentMethod · 0.80
hasComponentMethod · 0.80
destroyEntityMethod · 0.80
~JointMethod · 0.80
getEntityMethod · 0.45
getBody1Method · 0.45
getBody2Method · 0.45
setIsSleepingMethod · 0.45
getSizeInBytesMethod · 0.45

Tested by

no test coverage detected