Showing the changes to libraries/physics/src/PhysicsEngine.cpp (1 of 7 files). Show all
Unified · Split
| @@ -77,6 +77,10 @@ uint32_t PhysicsEngine::getNumSubsteps() const { · 76 unmodified lines | |||
| 77 | return _dynamicsWorld->getNumSubsteps(); | 77 | return _dynamicsWorld->getNumSubsteps(); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | int32_t PhysicsEngine::getNumCollisionObjects() const { | ||
| 81 | return _dynamicsWorld ? _dynamicsWorld->getNumCollisionObjects() : 0; | ||
| 82 | } | ||
| 83 | |||
| 80 | // private | 84 | // private |
| 81 | void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { | 85 | void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { |
| 82 | assert(motionState); | 86 | assert(motionState); |
| @@ -93,7 +97,6 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { · 10 unmodified lines | |||
| 93 | btCollisionShape* shape = const_cast<btCollisionShape*>(motionState->getShape()); | 97 | btCollisionShape* shape = const_cast<btCollisionShape*>(motionState->getShape()); |
| 94 | assert(shape); | 98 | assert(shape); |
| 95 | body = new btRigidBody(mass, motionState, shape, inertia); | 99 | body = new btRigidBody(mass, motionState, shape, inertia); |
| 96 | ++_numRigidBodies; | ||
| 97 | motionState->setRigidBody(body); | 100 | motionState->setRigidBody(body); |
| 98 | } else { | 101 | } else { |
| 99 | body->setMassProps(mass, inertia); | 102 | body->setMassProps(mass, inertia); |
| @@ -117,7 +120,6 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { · 17 unmodified lines | |||
| 117 | shape->calculateLocalInertia(mass, inertia); | 120 | shape->calculateLocalInertia(mass, inertia); |
| 118 | if (!body) { | 121 | if (!body) { |
| 119 | body = new btRigidBody(mass, motionState, shape, inertia); | 122 | body = new btRigidBody(mass, motionState, shape, inertia); |
| 120 | ++_numRigidBodies; | ||
| 121 | motionState->setRigidBody(body); | 123 | motionState->setRigidBody(body); |
| 122 | } else { | 124 | } else { |
| 123 | body->setMassProps(mass, inertia); | 125 | body->setMassProps(mass, inertia); |
| @@ -141,7 +143,6 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { · 17 unmodified lines | |||
| 141 | if (!body) { | 143 | if (!body) { |
| 142 | assert(motionState->getShape()); | 144 | assert(motionState->getShape()); |
| 143 | body = new btRigidBody(mass, motionState, const_cast<btCollisionShape*>(motionState->getShape()), inertia); | 145 | body = new btRigidBody(mass, motionState, const_cast<btCollisionShape*>(motionState->getShape()), inertia); |
| 144 | ++_numRigidBodies; | ||
| 145 | motionState->setRigidBody(body); | 146 | motionState->setRigidBody(body); |
| 146 | } else { | 147 | } else { |
| 147 | body->setMassProps(mass, inertia); | 148 | body->setMassProps(mass, inertia); |
| @@ -209,7 +210,6 @@ void PhysicsEngine::removeObjects(const VectorOfMotionStates& objects) { · 61 unmodified lines | |||
| 209 | if (body) { | 210 | if (body) { |
| 210 | removeDynamicsForBody(body); | 211 | removeDynamicsForBody(body); |
| 211 | _dynamicsWorld->removeRigidBody(body); | 212 | _dynamicsWorld->removeRigidBody(body); |
| 212 | --_numRigidBodies; | ||
| 213 | 213 | ||
| 214 | // NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it. | 214 | // NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it. |
| 215 | object->setRigidBody(nullptr); | 215 | object->setRigidBody(nullptr); |
| @@ -227,7 +227,6 @@ void PhysicsEngine::removeSetOfObjects(const SetOfMotionStates& objects) { · 11 unmodified lines | |||
| 227 | if (body) { | 227 | if (body) { |
| 228 | removeDynamicsForBody(body); | 228 | removeDynamicsForBody(body); |
| 229 | _dynamicsWorld->removeRigidBody(body); | 229 | _dynamicsWorld->removeRigidBody(body); |
| 230 | --_numRigidBodies; | ||
| 231 | 230 | ||
| 232 | // NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it. | 231 | // NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it. |
| 233 | object->setRigidBody(nullptr); | 232 | object->setRigidBody(nullptr); |
| @@ -279,7 +278,6 @@ void PhysicsEngine::reinsertObject(ObjectMotionState* object) { · 45 unmodified lines | |||
| 279 | btRigidBody* body = object->getRigidBody(); | 278 | btRigidBody* body = object->getRigidBody(); |
| 280 | if (body) { | 279 | if (body) { |
| 281 | _dynamicsWorld->removeRigidBody(body); | 280 | _dynamicsWorld->removeRigidBody(body); |
| 282 | --_numRigidBodies; | ||
| 283 | // add it back | 281 | // add it back |
| 284 | addObjectToDynamicsWorld(object); | 282 | addObjectToDynamicsWorld(object); |
| 285 | } | 283 | } |
| @@ -292,7 +290,6 @@ void PhysicsEngine::processTransaction(PhysicsEngine::Transaction& transaction) · 6 unmodified lines | |||
| 292 | if (body) { | 290 | if (body) { |
| 293 | removeDynamicsForBody(body); | 291 | removeDynamicsForBody(body); |
| 294 | _dynamicsWorld->removeRigidBody(body); | 292 | _dynamicsWorld->removeRigidBody(body); |
| 295 | --_numRigidBodies; | ||
| 296 | 293 | ||
| 297 | // NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it. | 294 | // NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it. |
| 298 | object->setRigidBody(nullptr); | 295 | object->setRigidBody(nullptr); |