// 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 SetMass(float mass){ btVector3 inertia; mSelf->getCollisionShape()->calculateLocalInertia(mass, inertia); mSelf->setMassProps(mass, inertia); }