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

Method newShape

physx/samples/samplebridges/SampleBridges.cpp:380–474  ·  view source on GitHub ↗

PT: this is a callback from the RAW-loader, used to import a new shape. We use simple segment shapes in the MAX scene to define where our bridges should be.

Source from the content-addressed store, hash-verified

378// PT: this is a callback from the RAW-loader, used to import a new shape. We use
379// simple segment shapes in the MAX scene to define where our bridges should be.
380void SampleBridges::newShape(const RAWShape& data)
381{
382 if(data.mName)
383 {
384 if(::strcmp(data.mName, "Bridge")==0)
385 {
386 PX_ASSERT(data.mNbVerts==2);
387 const PxVec3 p0 = data.mTransform.transform(data.mVerts[0]);
388 const PxVec3 p1 = data.mTransform.transform(data.mVerts[1]);
389 const PxVec3 center = (p0 + p1)*0.5f;
390
391 PxVec3 dir, right, up;
392 Ps::computeBasis(p0, p1, dir, right, up);
393
394 PxMat33 m(right, up, dir);
395 PxTransform tr;
396 tr.p = center;
397 tr.q = PxQuat(m);
398
399 const float l = (p1 - p0).magnitude();
400 const float coeff = l / 80.0f;
401
402 float scale = 2.0f * coeff;
403 // float scale = 4.0f * coeff;
404 // float scale = 1.0f;
405
406 BridgeJoint type = BRIDGE_REVOLUTE;
407 {
408 static int count=0;
409 if(count==0)
410 type = BRIDGE_REVOLUTE;
411 else if(count==1)
412 type = BRIDGE_SPHERICAL;
413 else if(count==2)
414 type = BRIDGE_FIXED;
415 else PX_ASSERT(0);
416
417 count++;
418 if(count==BRIDGE_COUNT)
419 count = 0;
420 }
421
422 std::vector<PxRigidActor*> bridgeActors;
423 buildBridge(getActiveScene(), getPhysics(), getDefaultMaterial(), bridgeActors, mJoints, tr, scale, type);
424
425 for(PxU32 i=0;i<bridgeActors.size();i++)
426 {
427 RenderMaterial* m = (i==0 || i==bridgeActors.size()-1) ? mRockMaterial : mWoodMaterial;
428
429 PX_ASSERT(bridgeActors[i]->getNbShapes()==1);
430 PxShape* boxShape;
431 PxU32 nb = bridgeActors[i]->getShapes(&boxShape, 1);
432 PX_ASSERT(nb==1);
433 PX_UNUSED(nb);
434 createRenderBoxFromShape(bridgeActors[i], boxShape, m, gBoxUVs);
435 }
436 }
437 else if(::strcmp(data.mName, "Platform")==0)

Callers

nothing calls this directly

Calls 15

strcmpFunction · 0.85
computeBasisFunction · 0.85
buildBridgeFunction · 0.85
PX_UNUSEDFunction · 0.85
setRigidBodyFlagMethod · 0.80
setPhysicsShapeMethod · 0.80
setMaximalMethod · 0.80
setWorldBoundsMethod · 0.80
createBoxFunction · 0.70
PxQuatClass · 0.50
PxTransformClass · 0.50
PxVec3Class · 0.50

Tested by

no test coverage detected