MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / explode

Method explode

physx/samples/samplesubmarine/SampleSubmarine.cpp:812–849  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

810///////////////////////////////////////////////////////////////////////////////
811
812void SampleSubmarine::explode(PxRigidActor* actor, const PxVec3& explosionPos, const PxReal explosionStrength)
813{
814 size_t numRenderActors = mRenderActors.size();
815 for(PxU32 i = 0; i < numRenderActors; i++)
816 {
817 if(mRenderActors[i]->getPhysicsActor() == actor)
818 {
819 PxShape* shape = mRenderActors[i]->getPhysicsShape();
820 PxTransform pose = PxShapeExt::getGlobalPose(*shape, *actor);
821
822 PxGeometryHolder geom = shape->getGeometry();
823
824 // create new actor from shape (to split compound)
825 PxRigidDynamic* newActor = mPhysics->createRigidDynamic(pose);
826 if(!newActor) fatalError("createRigidDynamic failed!");
827
828 PxShape* newShape = PxRigidActorExt::createExclusiveShape(*newActor, geom.any(), *mMaterial);
829 unlink(mRenderActors[i], shape, actor);
830 link(mRenderActors[i], newShape, newActor);
831
832 newActor->setActorFlag(PxActorFlag::eVISUALIZATION, true);
833 newActor->setLinearDamping(10.5f);
834 newActor->setAngularDamping(0.5f);
835 PxRigidBodyExt::updateMassAndInertia(*newActor, 1.0f);
836 mScene->addActor(*newActor);
837 mPhysicsActors.push_back(newActor);
838
839 PxVec3 explosion = pose.p - explosionPos;
840 PxReal len = explosion.normalize();
841 explosion *= (explosionStrength / len);
842 newActor->setLinearVelocity(explosion);
843 newActor->setAngularVelocity(PxVec3(1,2,3));
844
845 }
846 }
847
848 removeActor(actor);
849}
850///////////////////////////////////////////////////////////////////////////////
851
852

Callers

nothing calls this directly

Calls 14

updateMassAndInertiaFunction · 0.85
getPhysicsShapeMethod · 0.80
PxVec3Class · 0.50
sizeMethod · 0.45
getPhysicsActorMethod · 0.45
getGeometryMethod · 0.45
createRigidDynamicMethod · 0.45
setActorFlagMethod · 0.45
setLinearDampingMethod · 0.45
setAngularDampingMethod · 0.45
addActorMethod · 0.45
normalizeMethod · 0.45

Tested by

no test coverage detected