| 261 | |
| 262 | |
| 263 | void Crab::create(const PxVec3& _crabPos) |
| 264 | { |
| 265 | static const PxReal scale = 0.8f; |
| 266 | static const PxReal crabDepth = 2.0f; |
| 267 | static const PxVec3 crabBodyDim = PxVec3(0.8f, 0.8f, crabDepth*0.5f)*scale; |
| 268 | static const PxReal legMass = 0.03f; |
| 269 | static const PxReal velocity = 0.0f; |
| 270 | static const PxReal maxForce = 4000.0f; |
| 271 | |
| 272 | LegParameters params; // check edge ascii art in Crab.h |
| 273 | params.a = 0.5f; |
| 274 | params.b = 0.6f; |
| 275 | params.c = 0.5f; |
| 276 | params.d = 0.5f; |
| 277 | params.e = 1.5f; |
| 278 | params.m = 0.3f; |
| 279 | params.n = 0.1f; |
| 280 | |
| 281 | mLegHeight = scale*2.0f*(params.d+params.c); |
| 282 | mLegHeight += 0.5f; |
| 283 | PxVec3 crabPos = getPlaceOnFloor(_crabPos); |
| 284 | mCrabBody = mSampleSubmarine->createBox(crabPos, crabBodyDim, NULL, mMaterial, 1.0f)->is<PxRigidDynamic>(); |
| 285 | if(!mCrabBody) mSampleSubmarine->fatalError("createBox failed!"); |
| 286 | PxShape* shape; mCrabBody->getShapes(&shape, 1); |
| 287 | shape->setLocalPose(PxTransform(PxQuat(PxHalfPi*0.5f, PxVec3(0,0,1)))); |
| 288 | PxRigidBodyExt::setMassAndUpdateInertia(*mCrabBody, legMass*10.0f); |
| 289 | PxTransform cmPose = mCrabBody->getCMassLocalPose(); |
| 290 | cmPose.p.y -= 0.8f; |
| 291 | mCrabBody->setCMassLocalPose(cmPose); |
| 292 | mCrabBody->setAngularDamping(100.0f); |
| 293 | mCrabBody->userData = this; |
| 294 | mActors.push_back(mCrabBody); |
| 295 | |
| 296 | // legs |
| 297 | static const PxU32 numLegs = 4; |
| 298 | PxReal recipNumLegs = 1.0f/PxReal(numLegs); |
| 299 | PxReal recipNumLegsMinus1 = 1.0f/PxReal(numLegs-1); |
| 300 | PX_COMPILE_TIME_ASSERT((numLegs&1) == 0); |
| 301 | |
| 302 | PxRigidDynamic* motor[2]; |
| 303 | { |
| 304 | static const PxReal density = 1.0f; |
| 305 | static const PxReal m = params.m * scale; |
| 306 | static const PxReal n = params.n * scale; |
| 307 | static const PxBoxGeometry boxGeomM = PxBoxGeometry(m, m, crabBodyDim.z * 0.5f); |
| 308 | |
| 309 | // create left and right motor |
| 310 | PxVec3 motorPos = crabPos+PxVec3(0,n,0); |
| 311 | for(PxU32 i = 0; i < 2; i++) |
| 312 | { |
| 313 | PxVec3 motorOfs = i==0 ? PxVec3(0,0, boxGeomM.halfExtents.z) : -PxVec3(0,0,boxGeomM.halfExtents.z); |
| 314 | motor[i] = mSampleSubmarine->createBox(motorPos+motorOfs, boxGeomM.halfExtents, NULL, mMaterial, density)->is<PxRigidDynamic>(); |
| 315 | if(!motor[i]) mSampleSubmarine->fatalError("createBox failed!"); |
| 316 | |
| 317 | PxRigidBodyExt::setMassAndUpdateInertia(*motor[i], legMass); |
| 318 | motor[i]->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, true); |
| 319 | setShapeFlag(motor[i], PxShapeFlag::eSIMULATION_SHAPE, false); |
| 320 |
nothing calls this directly
no test coverage detected