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

Method createObstacles

physx/samples/samplevehicle/SampleVehicle.cpp:1528–1715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1526}
1527
1528void SampleVehicle::createObstacles()
1529{
1530 PxSceneWriteLock scopedLock(*mScene);
1531 //Create some giant pendula
1532 {
1533 PxTransform shapeTransforms[3]={PxTransform(PxIdentity),PxTransform(PxIdentity),PxTransform(PxIdentity)};
1534 PxMaterial* shapeMaterials[3]={NULL,NULL,NULL};
1535 PxGeometry* shapeGeometries[3]={NULL,NULL,NULL};
1536 PxShape* shapes[3]={NULL,NULL,NULL};
1537
1538 gNumRevoluteJoints=0;
1539
1540 for(PxU32 i=0;i<MAX_NUM_PENDULA;i++)
1541 {
1542 //Get the transform to position the next pendulum ball.
1543 const PxTransform& ballStartTransform=gPendulaBallStartTransforms[i];
1544
1545 //Pendulum made of two shapes : a sphere for the ball and a cylinder for the shaft.
1546 //In the absence of a special material for pendula just use the tarmac material.
1547 PxSphereGeometry geomBall(gPendulumBallRadius);
1548 shapeGeometries[0]=&geomBall;
1549 shapeTransforms[0]=PxTransform(PxIdentity);
1550 shapeMaterials[0]=mStandardMaterials[SURFACE_TYPE_TARMAC];
1551 PxConvexMeshGeometry geomShaft(createCylinderConvexMesh(gPendulumShaftLength, gPendulumShaftWidth, 8, getPhysics(), getCooking()));
1552 shapeGeometries[1]=&geomShaft;
1553 shapeTransforms[1]=PxTransform(PxVec3(0, 0.5f*gPendulumShaftLength, 0), PxQuat(PxHalfPi, PxVec3(0,0,1))),
1554 shapeMaterials[1]=mStandardMaterials[SURFACE_TYPE_TARMAC];
1555
1556 //Ready to add the pendulum as a dynamic object.
1557 PxRigidDynamic* actor=addDynamicObstacle(ballStartTransform,gPendulumBallMass,2,shapeTransforms,shapeGeometries,shapeMaterials);
1558
1559 //As an optimization we don't want pendulum to intersect with static geometry because the position and
1560 //limits on joint rotation will ensure that this is already impossible.
1561 actor->getShapes(shapes,2);
1562 PxFilterData simFilterData=shapes[0]->getSimulationFilterData();
1563 simFilterData.word1 &= ~COLLISION_FLAG_GROUND;
1564 shapes[0]->setSimulationFilterData(simFilterData);
1565 shapes[1]->setSimulationFilterData(simFilterData);
1566 //As a further optimization lets set the pendulum shapes to be non-drivable surfaces.
1567 PxFilterData qryFilterData;
1568 SampleVehicleSetupNonDrivableShapeQueryFilterData(&qryFilterData);
1569 shapes[0]->setQueryFilterData(qryFilterData);
1570 shapes[1]->setQueryFilterData(qryFilterData);
1571
1572 //Add static geometry to give the appearance that something is physically supporting the pendulum.
1573 //This supporting geometry is just a vertical bar and two horizontal bars.
1574 const PxF32 groundClearance=3.0f;
1575 PxConvexMeshGeometry geomHorizontalBar(createCylinderConvexMesh(gPendulumSuspensionStructureWidth, gPendulumShaftWidth, 8, getPhysics(), getCooking()));
1576 PxConvexMeshGeometry geomVerticalBar(createCylinderConvexMesh(gPendulumShaftLength+groundClearance, gPendulumShaftWidth, 8, getPhysics(), getCooking()));
1577 shapeGeometries[0]=&geomHorizontalBar;
1578 shapeMaterials[0]=mStandardMaterials[SURFACE_TYPE_TARMAC];
1579 shapeTransforms[0]=PxTransform(PxVec3(0, gPendulumShaftLength, 0), PxQuat(PxIdentity));
1580 shapeGeometries[1]=&geomVerticalBar;
1581 shapeMaterials[1]=mStandardMaterials[SURFACE_TYPE_TARMAC];
1582 shapeTransforms[1]=PxTransform(PxVec3(0.5f*gPendulumSuspensionStructureWidth, 0.5f*(gPendulumShaftLength-groundClearance), 0), PxQuat(PxHalfPi, PxVec3(0,0,1)));
1583 shapeGeometries[2]=&geomVerticalBar;
1584 shapeMaterials[2]=mStandardMaterials[SURFACE_TYPE_TARMAC];
1585 shapeTransforms[2]=PxTransform(PxVec3(-0.5f*gPendulumSuspensionStructureWidth, 0.5f*(gPendulumShaftLength-groundClearance), 0), PxQuat(PxHalfPi, PxVec3(0,0,1)));

Callers

nothing calls this directly

Calls 15

PxAsinFunction · 0.85
setQueryFilterDataMethod · 0.80
setRevoluteJointFlagMethod · 0.80
createCylinderConvexMeshFunction · 0.70
createPrismConvexMeshFunction · 0.70
createSquashedCuboidMeshFunction · 0.70
createWedgeConvexMeshFunction · 0.70
PxTransformClass · 0.50
PxVec3Class · 0.50

Tested by

no test coverage detected