Destroy a joint * @param joint Pointer to the joint you want to destroy */
| 604 | * @param joint Pointer to the joint you want to destroy |
| 605 | */ |
| 606 | void 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 |
no test coverage detected