| 360 | /////////////////////////////////////////////////////////////////////////////// |
| 361 | |
| 362 | Seamine* SampleSubmarine::createSeamine(const PxVec3& inPosition, PxReal inHeight) |
| 363 | { |
| 364 | static const PxReal chainLinkLength = 2.0f; |
| 365 | static const PxReal linkSpacing = 0.05f; |
| 366 | static const PxReal mineHeadRadius = 1.5f; |
| 367 | const PxVec3 mineStartPos = inPosition; |
| 368 | static const PxVec3 linkOffset = PxVec3(0, chainLinkLength + linkSpacing, 0); |
| 369 | static const PxVec3 halfLinkOffset = linkOffset * 0.5f; |
| 370 | static const PxVec3 linkDim = PxVec3(chainLinkLength*0.125f, chainLinkLength*0.5f, chainLinkLength*0.125f); |
| 371 | PxU32 numLinks = PxU32((inHeight - 2.0f*mineHeadRadius) / (chainLinkLength + linkSpacing)); |
| 372 | numLinks = numLinks ? numLinks : 1; |
| 373 | |
| 374 | Seamine* seamine = SAMPLE_NEW(Seamine); |
| 375 | mSeamines.push_back(seamine); |
| 376 | |
| 377 | // create links from floor |
| 378 | PxVec3 linkPos = mineStartPos + halfLinkOffset; |
| 379 | PxRigidActor* prevActor = NULL; |
| 380 | for(PxU32 i = 0; i < numLinks; i++) |
| 381 | { |
| 382 | // create the link actor |
| 383 | PxRigidDynamic* link = createBox(linkPos, linkDim, NULL, mSeamineMaterial, 1.0f)->is<PxRigidDynamic>(); |
| 384 | if(!link) fatalError("createBox failed!"); |
| 385 | // back reference to mineHead |
| 386 | link->userData = seamine; |
| 387 | seamine->mLinks.push_back(link); |
| 388 | |
| 389 | setupFiltering(link, FilterGroup::eMINE_LINK, FilterGroup::eSUBMARINE); |
| 390 | link->setLinearDamping(0.5f); |
| 391 | link->setAngularDamping(0.5f); |
| 392 | link->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, true); |
| 393 | |
| 394 | // create distance joint between link and prevActor |
| 395 | PxTransform linkFrameA = prevActor ? PxTransform(halfLinkOffset, PxQuat(PxIdentity)) : PxTransform(mineStartPos, PxQuat(PxIdentity)); |
| 396 | PxTransform linkFrameB = PxTransform(-halfLinkOffset, PxQuat(PxIdentity)); |
| 397 | PxDistanceJoint *joint = PxDistanceJointCreate(getPhysics(), prevActor, linkFrameA, link, linkFrameB); |
| 398 | if(!joint) fatalError("PxDistanceJointCreate failed!"); |
| 399 | |
| 400 | // set min & max distance to 0 |
| 401 | joint->setMaxDistance(0.0f); |
| 402 | joint->setMinDistance(0.0f); |
| 403 | // setup damping & spring |
| 404 | joint->setDamping(1.0f * link->getMass()); |
| 405 | joint->setStiffness(400.0f * link->getMass()); |
| 406 | joint->setDistanceJointFlags(PxDistanceJointFlag::eMAX_DISTANCE_ENABLED | PxDistanceJointFlag::eMIN_DISTANCE_ENABLED | PxDistanceJointFlag::eSPRING_ENABLED); |
| 407 | |
| 408 | // add to joints array for cleanup |
| 409 | mJoints.push_back(joint); |
| 410 | |
| 411 | prevActor = link; |
| 412 | linkPos += linkOffset; |
| 413 | } |
| 414 | |
| 415 | // create mine head |
| 416 | linkPos.y += mineHeadRadius - (chainLinkLength*0.5f); |
| 417 | PxRigidDynamic* mineHead = createSphere(linkPos, mineHeadRadius, NULL, mSeamineMaterial, 1.0f)->is<PxRigidDynamic>(); |
| 418 | mineHead->userData = seamine; |
| 419 | seamine->mMineHead = mineHead; |
nothing calls this directly
no test coverage detected