void triMeshApp::exitPhysics() { //cleanup in the reverse order of creation/initialization if(m_convexRigidBody->getMotionState()) delete m_convexRigidBody->getMotionState(); m_dynamicsWorld->removeRigidBody(m_convexRigidBody); delete m_convexRigidBody; if(m_concaveRigidBody->getMotionState()) delete m_concaveRigidBody->getMotionState(); m_dynamicsWorld->removeRigidBody(m_concaveRigidBody); delete m_concaveRigidBody; if(m_hfRigidBody->getMotionState()) delete m_hfRigidBody->getMotionState(); m_dynamicsWorld->removeRigidBody(m_hfRigidBody); delete m_hfRigidBody; delete m_dynamicsWorld; delete m_solver; delete m_broadphase; delete m_dispatcher; delete m_collisionConfiguration; }
~World(void) { for (auto &robot : robots) dynamics.removeRigidBody(&robot.body); for (auto &ball : balls) dynamics.removeRigidBody(&ball.body); dynamics.removeRigidBody(&field.ground_body); dynamics.removeRigidBody(&field.ceil_body); dynamics.removeRigidBody(&field.left_wall_body); dynamics.removeRigidBody(&field.right_wall_body); dynamics.removeRigidBody(&field.top_wall_body); dynamics.removeRigidBody(&field.bottom_wall_body); dynamics.removeRigidBody(&field.left_goal_body); dynamics.removeRigidBody(&field.right_goal_body); }
void UnregisterFromWorld(){ if (mWorld){ auto num = mSelf->getNumConstraintRefs(); for (int i = 0; i < num; ++i){ auto constraint = mSelf->getConstraintRef(i); assert(constraint); constraint->setEnabled(false); } mWorld->removeRigidBody(mSelf); mAddedToWorld = false; } }
void UnregisterFromWorld(){ if (mWorld){ auto num = mSelf->getNumConstraintRefs(); for (int i = 0; i < num; ++i){ auto constraint = mSelf->getConstraintRef(i); assert(constraint); constraint->setEnabled(false); } mWorld->removeRigidBody(mSelf); mAddedToWorld = false; } else Logger::Log(FB_ERROR_LOG_ARG, "No colprovier exists!"); }
void BulletWrapper::removeAllBodies() { for (unsigned int i = 0; i < m_BodyDatas.size(); i++) { btRigidBody* body = m_BodyDatas[i].m_Body; m_DynamicsWorld->removeRigidBody(body); delete body->getMotionState(); delete body; // Shape is automatically released via the shared pointer } m_BodyDatas.clear(); }
// Physics dll internal void RefreshColShape(IPhysicsInterface* colProvider){ if (!colProvider) { Logger::Log(FB_ERROR_LOG_ARG, "No colProvider"); return; } mWorld->removeRigidBody(mSelf); mAddedToWorld = false; auto prevColShape = mSelf->getCollisionShape(); if (prevColShape){ Physics::GetInstance().Release(prevColShape); } btCollisionShape* colShape = 0; float mass = 1.0f; auto& physics = Physics::GetInstance(); if (mGroupedRigidBody){ if (colProvider->GetNumColShapes(mGroupIdx) == 0) return; colShape = physics.CreateColShapeForGroup(colProvider, mGroupIdx); mass = colProvider->GetMassForGroup(mGroupIdx); } else{ if (colProvider->GetNumColShapes() == 0) return; colShape = physics.CreateColShape(colProvider); mass = colProvider->GetMass(); } assert(colShape); mSelf->setCollisionShape(colShape); if (colShape) physics.AddRef(colShape); if (mass > 0 && colShape) { btVector3 inertia; colShape->calculateLocalInertia(mass, inertia); mSelf->setMassProps(mass, inertia); } else{ SetMass(0.f); } assert(!mAddedToWorld); mWorld->addRigidBody(mSelf, colProvider->GetCollisionGroup(), colProvider->GetCollisionMask()); mAddedToWorld = true; }
void BulletWrapper::removeBody(btRigidBody* bodyToRemove) { for (unsigned int i = 0; i < m_BodyDatas.size(); i++) { btRigidBody* body = m_BodyDatas[i].m_Body; if (body == bodyToRemove) { m_DynamicsWorld->removeRigidBody(body); delete body->getMotionState(); delete body; m_BodyDatas.erase(m_BodyDatas.begin()+i); break; } // Shape is automatically released via the shared pointer } }
~Impl(){ UnregisterFromWorld(); mSelf->setUserPointer(0); mGamePtr = 0; FB_DELETE(mRotationInfo); RemoveConstraints(); auto colShape = mSelf->getCollisionShape(); if (colShape){ Physics::GetInstance().Release(colShape); } if (mWorld){ mWorld->removeRigidBody(mSelf); mAddedToWorld = false; } FB_DELETE_ALIGNED(mSelf->getMotionState()); }