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

Method createLeg

physx/samples/samplesubmarine/Crab.cpp:356–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354}
355
356void Crab::createLeg(PxRigidDynamic* mainBody, PxVec3 localPos, PxReal mass, const LegParameters& params, PxReal scale, PxRigidDynamic* motor, PxVec3 motorAttachmentPos)
357{
358 PxVec3 crabLegPos = mainBody->getGlobalPose().p + localPos;
359
360 // params for Theo Jansen's machine
361 // check edge ascii art in Crab.h
362 static const PxReal stickExt = 0.125f * 0.5f * scale;
363 const PxReal a = params.a * scale;
364 const PxReal b = params.b * scale;
365 const PxReal c = params.c * scale;
366 const PxReal d = params.d * scale;
367 const PxReal e = params.e * scale;
368 const PxReal m = params.m * scale;
369 const PxReal n = params.n * scale;
370
371 const PxReal density = 1.0f;
372
373 std::vector<PxTransform> poses;
374 std::vector<const PxGeometry*> geometries;
375
376 PxBoxGeometry boxGeomA = PxBoxGeometry(a, stickExt, stickExt);
377 PxBoxGeometry boxGeomB = PxBoxGeometry(stickExt, b, stickExt);
378 PxBoxGeometry boxGeomC = PxBoxGeometry(stickExt, c, stickExt);
379
380 PxCapsuleGeometry capsGeomD = PxCapsuleGeometry(stickExt*2.0f, d);
381
382 for(PxU32 leg = 0; leg < 2; leg++)
383 {
384 bool left = (leg==0);
385 #define MIRROR(X) left ? -1.0f*(X) : (X)
386 PxVec3 startPos = crabLegPos + PxVec3(MIRROR(e), 0, 0);
387
388 // create upper triangle from boxes
389 PxRigidDynamic* upperTriangle = NULL;
390 {
391 PxTransform poseA = PxTransform(PxVec3(MIRROR(a), 0, 0));
392 PxTransform poseB = PxTransform(PxVec3(MIRROR(0), b, 0));
393 poses.clear(); geometries.clear();
394 poses.push_back(poseA); poses.push_back(poseB);
395 geometries.push_back(&boxGeomA); geometries.push_back(&boxGeomB);
396 upperTriangle = mSampleSubmarine->createCompound(startPos, poses, geometries, NULL, mMaterial, density)->is<PxRigidDynamic>();
397 if(!upperTriangle) mSampleSubmarine->fatalError("createCompound failed!");
398 mActors.push_back(upperTriangle);
399 }
400
401 // create lower triangle from boxes
402 PxRigidDynamic* lowerTriangle = NULL;
403 {
404 PxTransform poseA = PxTransform(PxVec3(MIRROR(a), 0, 0));
405 //PxTransform poseD = PxTransform(PxVec3(MIRROR(0), -d, 0));
406 PxTransform poseD = PxTransform(PxVec3(MIRROR(0), -d, 0), PxQuat(PxHalfPi, PxVec3(0,0,1)));
407 poses.clear(); geometries.clear();
408 poses.push_back(poseA); poses.push_back(poseD);
409 //geometries.push_back(&boxGeomA); geometries.push_back(&boxGeomD);
410 geometries.push_back(&boxGeomA); geometries.push_back(&capsGeomD);
411 lowerTriangle = mSampleSubmarine->createCompound(startPos + PxVec3(0, -2.0f*c, 0), poses, geometries, NULL, mMaterial, density)->is<PxRigidDynamic>();
412 if(!lowerTriangle) mSampleSubmarine->fatalError("createCompound failed!");
413 mActors.push_back(lowerTriangle);

Callers

nothing calls this directly

Calls 15

setMassAndUpdateInertiaFunction · 0.85
PxSqrtFunction · 0.85
setMaxDistanceMethod · 0.80
setMinDistanceMethod · 0.80
setDistanceJointFlagsMethod · 0.80
setShapeFlagFunction · 0.70
PxBoxGeometryClass · 0.50
PxCapsuleGeometryClass · 0.50
PxVec3Class · 0.50
PxTransformClass · 0.50
PxQuatClass · 0.50
getGlobalPoseMethod · 0.45

Tested by

no test coverage detected