void PhysicsWorld::removeBody(PhysicsBody* body) { if (body->getWorld() != this) { CCLOG("Physics Warnning: this body doesn't belong to this world"); return; } // destory the body's joints for (auto joint : body->_joints) { // set destroy param to false to keep the iterator available removeJoint(joint, false); PhysicsBody* other = (joint->getBodyA() == body ? joint->getBodyB() : body); other->removeJoint(joint); // test the distraction is delaied or not if (_delayRemoveJoints.size() > 0 && _delayRemoveJoints.back() == joint) { joint->_destoryMark = true; } else { delete joint; } } body->_joints.clear(); removeBodyOrDelay(body); _bodies.eraseObject(body); body->_world = nullptr; }
void PackageTarget::clearJoint (b2Joint *joint) { IEntity::clearJoint(joint); if (_joint == joint) { removeJoint(); } }
void PhysicsWorld::removeAllJoints(bool destroy) { auto removeCopy = _joints; for (auto joint : removeCopy) { removeJoint(joint, destroy); } }
void PackageTarget::updateJoint (uint32_t deltaTime) { assert(_joint != nullptr); const float currentLength = _joint->GetLength(); if (currentLength < 0.05f) { removeJoint(); return; } _lengthUpdate -= deltaTime; if (_lengthUpdate > 0) return; _lengthUpdate = LENGTH_UPDATE_DELAY; _joint->SetLength(currentLength - 0.1f); }
void PhysicsWorld::removeBody(PhysicsBody* body) { if (body->getWorld() != this) { CCLOG("Physics Warnning: this body doesn't belong to this world"); return; } // destory the body's joints for (auto joint : body->_joints) { removeJoint(joint, true); } removeBodyOrDelay(body); _bodies->removeObject(body); body->_world = nullptr; }
void PhysicsWorld::removeBody(PhysicsBody* body) { if (body->getWorld() != this) { CCLOG("Physics Warning: this body doesn't belong to this world"); return; } // destroy the body's joints auto removeCopy = body->_joints; for (auto joint : removeCopy) { removeJoint(joint, true); } body->_joints.clear(); removeBodyOrDelay(body); _bodies.eraseObject(body); body->_world = nullptr; }