| 425 | } |
| 426 | |
| 427 | PhysicsShape* PhysicsBody::addShape(PhysicsShape* shape, bool addMassAndMoment /* = true*/) |
| 428 | { |
| 429 | if (shape == nullptr) |
| 430 | return nullptr; |
| 431 | |
| 432 | // add shape to body |
| 433 | if (_shapes.getIndex(shape) == -1) |
| 434 | { |
| 435 | shape->setBody(this); |
| 436 | |
| 437 | // calculate the area, mass, and density |
| 438 | // area must update before mass, because the density changes depend on it. |
| 439 | if (addMassAndMoment) |
| 440 | { |
| 441 | _area += shape->getArea(); |
| 442 | addMass(shape->getMass()); |
| 443 | addMoment(shape->getMoment()); |
| 444 | } |
| 445 | |
| 446 | if (_world && cpBodyGetSpace(_cpBody)) |
| 447 | { |
| 448 | _world->addShape(shape); |
| 449 | } |
| 450 | |
| 451 | _shapes.pushBack(shape); |
| 452 | } |
| 453 | |
| 454 | return shape; |
| 455 | } |
| 456 | |
| 457 | void PhysicsBody::applyForce(const Vec2& force, const Vec2& offset) |
| 458 | { |