| 725 | } |
| 726 | |
| 727 | void SampleSubmarine::onTickPreRender(float dtime) |
| 728 | { |
| 729 | mScene->lockWrite(); |
| 730 | |
| 731 | if(gResetScene) |
| 732 | resetScene(); |
| 733 | |
| 734 | // handle mine (and submarine) explosion |
| 735 | if(mSubmarineActor) |
| 736 | { |
| 737 | // explode all touched mines, apply damage and force to submarine |
| 738 | PxVec3 subMarinePos = mSubmarineActor->getGlobalPose().p; |
| 739 | const size_t nbExplodeSeamines = mMinesToExplode.size(); |
| 740 | for(PxU32 i=0; i < nbExplodeSeamines; i++) |
| 741 | { |
| 742 | Seamine* mine = mMinesToExplode[i]; |
| 743 | PxVec3 explosionPos = mine->mMineHead->getGlobalPose().p; |
| 744 | |
| 745 | // disable contact trigger callback of the chain & enable gravity |
| 746 | const size_t nbLinks = mine->mLinks.size(); |
| 747 | for(PxU32 j = 0; j < nbLinks; j++) |
| 748 | { |
| 749 | PxRigidDynamic* link = mine->mLinks[j]; |
| 750 | setupFiltering(link, 0, 0); |
| 751 | link->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, false); |
| 752 | } |
| 753 | |
| 754 | // remove mine head |
| 755 | std::vector<Seamine*>::iterator mineIter = std::find(mSeamines.begin(), mSeamines.end(), mine); |
| 756 | if(mineIter != mSeamines.end()) |
| 757 | mSeamines.erase(mineIter); |
| 758 | removeActor(mine->mMineHead); |
| 759 | delete mine; |
| 760 | |
| 761 | // give damage to submarine |
| 762 | static const PxReal strength = 400.0f; |
| 763 | PxVec3 explosion = subMarinePos - explosionPos; |
| 764 | PxReal len = explosion.normalize(); |
| 765 | PxReal damage = strength * (1.0f/len); |
| 766 | explosion *= damage; |
| 767 | mSubmarineActor->addForce(explosion*300); |
| 768 | gSubmarineHealth = PxMax(gSubmarineHealth-PxI32(damage), 0); |
| 769 | if(gSubmarineHealth == 0) |
| 770 | { |
| 771 | mSubmarineCameraController->init(subMarinePos - getCamera().getViewDir()*10.0f, getCamera().getRot()); |
| 772 | explode(mSubmarineActor, subMarinePos /*- explosion*0.2f*/, damage); |
| 773 | mCameraAttachedToActor = NULL; |
| 774 | mSubmarineCameraController->setFollowingMode(false); |
| 775 | mSubmarineActor = NULL; |
| 776 | break; |
| 777 | } |
| 778 | } |
| 779 | mMinesToExplode.clear(); |
| 780 | } |
| 781 | |
| 782 | // respawn Crabs |
| 783 | const size_t nbCrabs = mCrabs.size(); |
| 784 | for(PxU32 i = 0; i < nbCrabs; i++) |
nothing calls this directly
no test coverage detected