| 727 | } |
| 728 | |
| 729 | void PhysicsBody::removeAllShapes(bool reduceMassAndMoment /* = true*/) |
| 730 | { |
| 731 | for (auto&& child : _shapes) |
| 732 | { |
| 733 | PhysicsShape* shape = dynamic_cast<PhysicsShape*>(child); |
| 734 | |
| 735 | // deduce the area, mass and moment |
| 736 | // area must update before mass, because the density changes depend on it. |
| 737 | if (reduceMassAndMoment) |
| 738 | { |
| 739 | _area -= shape->getArea(); |
| 740 | addMass(-shape->getMass()); |
| 741 | addMoment(-shape->getMoment()); |
| 742 | } |
| 743 | |
| 744 | if (_world) |
| 745 | { |
| 746 | _world->removeShape(shape); |
| 747 | } |
| 748 | |
| 749 | // set shape->_body = nullptr make the shape->setBody will not trigger the _body->removeShape function call. |
| 750 | shape->_body = nullptr; |
| 751 | shape->setBody(nullptr); |
| 752 | } |
| 753 | |
| 754 | _shapes.clear(); |
| 755 | } |
| 756 | |
| 757 | void PhysicsBody::removeFromWorld() |
| 758 | { |
no test coverage detected