| 810 | /////////////////////////////////////////////////////////////////////////////// |
| 811 | |
| 812 | void 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 |
nothing calls this directly
no test coverage detected