public static void initPhysics(bool interactive) { gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, ref gAllocator.Value, ref gErrorCallback.Value); gPvd = PxCreatePvd(ref *gFoundation); PxPvdTransport *transport = PxDefaultPvdSocketTransportCreate(PVD_HOST, 5425, 10); gPvd->connect(ref *transport, PxPvdInstrumentationFlags.eALL); gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, ref *gFoundation, new PxTolerancesScale(), true, gPvd); PxInitExtensions(ref *gPhysics, gPvd); PxSceneDesc sceneDesc = new(*gPhysics->getTolerancesScale()); sceneDesc.gravity = new PxVec3(0.0f, -9.81f, 0.0f); uint numCores = SnippetUtils.getNbPhysicalCores(); gDispatcher = PxDefaultCpuDispatcherCreate(numCores == 0 ? 0 : numCores - 1); sceneDesc.cpuDispatcher = (PxCpuDispatcher *)gDispatcher; //BIOQUIRK: Base cast sceneDesc.filterShader = PxDefaultSimulationFilterShader; #if USE_REDUCED_COORDINATE_ARTICULATION sceneDesc.solverType = PxSolverType.eTGS; #if CREATE_SCISSOR_LIFT sceneDesc.filterShader = &scissorFilter; #endif #endif gScene = gPhysics->createScene(sceneDesc); PxPvdSceneClient *pvdClient = gScene->getScenePvdClient(); if (pvdClient != null) { pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_CONSTRAINTS, true); pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_CONTACTS, true); pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_SCENEQUERIES, true); } gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0f); PxRigidStatic *groundPlane = PxCreatePlane(ref *gPhysics, new PxPlane(0, 1, 0, 0), ref *gMaterial); gScene->addActor(ref *groundPlane); #if USE_REDUCED_COORDINATE_ARTICULATION gArticulation = gPhysics->createArticulationReducedCoordinate(); #else gArticulation = gPhysics->createArticulation(); // Stabilization can create artefacts on jointed objects so we just disable it gArticulation->setStabilizationThreshold(0.0f); gArticulation->setMaxProjectionIterations(16); gArticulation->setSeparationTolerance(0.001f); #endif #if USE_REDUCED_COORDINATE_ARTICULATION && CREATE_SCISSOR_LIFT createScissorLift(); #else createLongChain(); #endif }
public static void initPhysics(bool interactive) { gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, ref gAllocator.Value, ref gErrorCallback.Value); gPvd = PxCreatePvd(ref *gFoundation); PxPvdTransport *transport = PxDefaultPvdSocketTransportCreate(PVD_HOST, 5425, 10); gPvd->connect(ref *transport, PxPvdInstrumentationFlags.eALL); gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, ref *gFoundation, new PxTolerancesScale(), true, gPvd); PxSceneDesc sceneDesc = new(*gPhysics->getTolerancesScale()); sceneDesc.gravity = new PxVec3(0.0f, -9.81f, 0.0f); gDispatcher = PxDefaultCpuDispatcherCreate(2); sceneDesc.cpuDispatcher = (PxCpuDispatcher *)gDispatcher; //BIOQUIRK: Base cast sceneDesc.filterShader = PxDefaultSimulationFilterShader; gScene = gPhysics->createScene(sceneDesc); PxPvdSceneClient *pvdClient = gScene->getScenePvdClient(); if (pvdClient != null) { pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_CONSTRAINTS, true); pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_CONTACTS, true); pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_SCENEQUERIES, true); } gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f); PxRigidStatic *groundPlane = PxCreatePlane(ref *gPhysics, new PxPlane(0, 1, 0, 0), ref *gMaterial); gScene->addActor(ref *groundPlane); createKinematics(); createDynamics(); }
static void createGroudPlane() { PxTransform pose = new PxTransform(new PxVec3(0.0f, 0.0f, 0.0f), new PxQuat(MathF.PI * 0.5f, new PxVec3(0.0f, 0.0f, 1.0f))); PxRigidStatic *actor = gPhysics->createRigidStatic(pose); PxShape * shape = PxRigidActorExt.createExclusiveShape(ref *actor, new PxPlaneGeometry(), *gMaterial, PxShapeFlags.eVISUALIZATION | PxShapeFlags.eSCENE_QUERY_SHAPE | PxShapeFlags.eSIMULATION_SHAPE); //BIOQUIRK: Missing default gScene->addActor(ref *actor); }
public static void Main(string[] args) { Console.WriteLine($"PhysX native runtime build information: '{MochiPhysX.BuildInfo}'..."); //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Initializing error callback"); // Switch between these to use PhysX's default error callback or one implemented from C# PxDefaultErrorCallback errorCallback = new(); //PxErrorCallback errorCallback = ErrorCallback.Create(); //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Initializing allocator callback"); // Switch between these to use PhysX's default allocator callback or one implemented from C# PxDefaultAllocator allocator = new(); //PxAllocatorCallback allocator = BasicAllocator.Create(); //PxAllocatorCallback allocator = LoggingAllocator.Create(); //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Initializing foundation"); //BIOQUIRK: PhysX owns both of these references, which means both the allocator and error callback must remain pinned for the lifetime of the foundation. // (In our case they're stack allocated and implicitly pinned.) // This seems somewhat unobvious since C# references don't normally care. Should we emit this function differently to convey the unsafe-ness here? PxFoundation *foundation = PxCreateFoundation(PX_PHYSICS_VERSION, ref allocator, ref errorCallback); if (foundation == null) { Console.Error.WriteLine("Failed to create foundation."); return; } //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Initializing Pvd..."); //BIOQUIRK: This pattern comes up a lot in PhysX. It does technically match how it is in C++ though, not sure if it's a problem. // I experimentally enabled having C++ reference returns translate as C# reference returns, but that creates a weird situation when you need to store them. PxPvd *pvd = PxCreatePvd(ref *foundation); PxPvdTransport *transport; byte[] host = Encoding.ASCII.GetBytes("127.0.0.1"); fixed(byte *hostP = host) { transport = PxDefaultPvdSocketTransportCreate(hostP, 5425, 10); } Console.WriteLine("Connecting to Pvd..."); pvd->connect(ref *transport, PxPvdInstrumentationFlags.eALL); //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Initializing physics"); PxPhysics *physics = PxCreatePhysics(PX_PHYSICS_VERSION, ref *foundation, new PxTolerancesScale(), trackOutstandingAllocations: true, pvd); if (physics == null) { Console.Error.WriteLine("Failed to create physics."); return; } //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Creating dispatcher"); PxDefaultCpuDispatcher *dispatcher = PxDefaultCpuDispatcherCreate(2, null); //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Creating scene"); PxSceneDesc sceneDescription = new(*physics->getTolerancesScale()); sceneDescription.gravity = new PxVec3() { x = 0f, y = -9.81f, z = 0f }; sceneDescription.cpuDispatcher = (PxCpuDispatcher *)dispatcher; sceneDescription.filterShader = PxDefaultSimulationFilterShader; PxScene *scene = physics->createScene(sceneDescription); //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Configuring scene Pvd client"); PxPvdSceneClient *pvdClient = scene->getScenePvdClient(); if (pvdClient != null) { pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_CONSTRAINTS, true); pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_CONTACTS, true); pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_SCENEQUERIES, true); } //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Creating a basic material"); PxMaterial *material = physics->createMaterial(0.5f, 0.5f, 0.6f); //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Adding a ground plane"); PxPlane planeDescription = new PxPlane() { n = new PxVec3() { x = 0f, y = 1f, z = 0f }, d = 0f }; PxRigidStatic *groundPlane = PxCreatePlane(ref *physics, planeDescription, ref *material); scene->addActor(ref *groundPlane, null); //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Adding stacks"); { const float halfExtent = 2f; PxBoxGeometry stackBoxGeometry = new PxBoxGeometry(halfExtent, halfExtent, halfExtent); PxShapeFlags shapeFlags = PxShapeFlags.eVISUALIZATION | PxShapeFlags.eSCENE_QUERY_SHAPE | PxShapeFlags.eSIMULATION_SHAPE; //BIOQUIRK: shapeFlags should be able to be defaulted now but it isn't. PxShape *shape = physics->createShape(stackBoxGeometry, *material, isExclusive: false, shapeFlags); float stackZ = 10f; for (int stackNum = 0; stackNum < 5; stackNum++) { const int size = 10; PxVec3 transformPosition = new PxVec3() { x = 0f, y = 0f, z = stackZ -= 10f }; PxTransform transform = new(transformPosition); for (int i = 0; i < size; i++) { for (int j = 0; j < size - i; j++) { PxVec3 position = new PxVec3() { x = ((float)(j * 2) - (float)(size - i)) * halfExtent, y = ((float)(i * 2 + 1)) * halfExtent, z = 0f }; PxTransform localTransform = new(position); PxTransform bodyTransform = transform.transform(localTransform); PxRigidDynamic *body = physics->createRigidDynamic(bodyTransform); body->attachShape(ref *shape); PxRigidBodyExt.updateMassAndInertia(ref *body, 10f); scene->addActor(ref *body); } } } shape->release(); } //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Throwing a ball at the stacks"); { PxVec3 position = new PxVec3() { x = 0f, y = 40f, z = 100f, }; PxTransform transform = new(position); PxSphereGeometry geometry = new(10f); PxVec3 velocity = new PxVec3() { x = 0f, y = -50f, z = -100f }; PxTransform identity = new(default(PxIDENTITY)); //BIOQUIRK: This could be a special generated property instead. Also missing default. PxRigidDynamic *dynamic = PxCreateDynamic(ref *physics, transform, geometry, ref *material, 10f, identity); dynamic->setAngularDamping(0.5f); dynamic->setLinearVelocity(velocity); scene->addActor(ref *dynamic); } //--------------------------------------------------------------------------------------------------------------------------------------- const int noInputFrameCount = 100; Console.WriteLine($"Simulating the world{(Console.IsInputRedirected ? $" for {noInputFrameCount} frames." : "... (Press escape to stop.)")}"); Stopwatch sw = new Stopwatch(); int frameNum = 0; const uint scratchMemoryBlockSize = 16 * 1024; const uint scratchMemoryBlockCount = 4; uint scratchMemorySize = scratchMemoryBlockSize * scratchMemoryBlockCount; void * scratchMemory = allocator.allocate(scratchMemorySize, null, null, 0); while (true) { double msSinceLastTick = sw.Elapsed.TotalMilliseconds; string consoleTitle = $"Simulating frame {frameNum} -- {msSinceLastTick:0.00} ms -- {1.0 / (msSinceLastTick / 1000.0):00.0} FPS"; if (BasicAllocator.AllocationCount > 0) // This is only applicable when a allocator implemented in C# is in use, assume 0 allocations implies the PhysX one is being used { consoleTitle += $" -- {BasicAllocator.AllocationCount} allocations"; BasicAllocator.AllocationCount = 0; } Console.Title = consoleTitle; frameNum++; sw.Restart(); scene->simulate(1f / 60f, scratchMemBlock: scratchMemory, scratchMemBlockSize: scratchMemorySize); uint errors; scene->fetchResults(true, &errors); if (errors != 0) { Console.WriteLine($"fetchResults error: {errors}"); } if (Console.IsInputRedirected) { if (frameNum > noInputFrameCount) { break; } } else if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape) { break; } } //--------------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Shutting down"); allocator.deallocate(scratchMemory); physics->release(); foundation->release(); }
/** * Deserialize shared data and use resulting collection to deserialize and instance actor collections */ public static void deserializeObjects(ref PxInputData sharedData, ref PxInputData actorData) { PxSerializationRegistry *sr = PxSerialization.createSerializationRegistry(ref *gPhysics); PxCollection *sharedCollection = null; { if (gUseBinarySerialization) { void *alignedBlock = createAlignedBlock(sharedData.getLength()); sharedData.read(alignedBlock, sharedData.getLength()); sharedCollection = PxSerialization.createCollectionFromBinary(alignedBlock, ref *sr); } else { sharedCollection = PxSerialization.createCollectionFromXml(ref sharedData, ref *gCooking, ref *sr); } } // Deserialize collection and instantiate objects twice, each time with a different transform PxTransform *transforms = stackalloc PxTransform[2] { new PxTransform(new PxVec3(-5.0f, 0.0f, 0.0f)), new PxTransform(new PxVec3(5.0f, 0.0f, 0.0f)) }; for (uint i = 0; i < 2; i++) { PxCollection *collection = null; // If the PxInputData actorData would refer to a file, it would be better to avoid reading from it twice. // This could be achieved by reading the file once to memory, and then working with copies. // This is particulary practical when using binary serialization, where the data can be directly // converted to physics objects. actorData.seek(0); if (gUseBinarySerialization) { void *alignedBlock = createAlignedBlock(actorData.getLength()); actorData.read(alignedBlock, actorData.getLength()); collection = PxSerialization.createCollectionFromBinary(alignedBlock, ref *sr, sharedCollection); } else { collection = PxSerialization.createCollectionFromXml(ref actorData, ref *gCooking, ref *sr, sharedCollection); } for (uint o = 0; o < collection->getNbObjects(); o++) { //BIOQUIRK: is<T> is not translated https://github.com/MochiLibraries/Mochi.PhysX/issues/11 //PxRigidActor* rigidActor = collection->getObject(o).is<PxRigidActor>(); PxRigidActor *rigidActor = null; { PxBase *obj = collection->getObject(o); //BIOQUIRK: Because PxRigidActor is not concrete, this ends up going down the isKindOf path, which is not publicly accessible. // This is special-cased for this snippet, ideally we should just expose is<T> in a more C#-friendly way. if ((PxConcreteType)obj->getConcreteType() is PxConcreteType.eRIGID_STATIC or PxConcreteType.eARTICULATION_LINK or PxConcreteType.eRIGID_DYNAMIC) { rigidActor = (PxRigidActor *)obj; } } if (rigidActor != null) { PxTransform globalPose = rigidActor->getGlobalPose(); globalPose = globalPose.transform(transforms[i]); rigidActor->setGlobalPose(globalPose); } } gScene->addCollection(*collection); collection->release(); } sharedCollection->release(); PxMaterial *material; gPhysics->getMaterials(&material, 1); PxRigidStatic *groundPlane = PxCreatePlane(ref *gPhysics, new PxPlane(0, 1, 0, 0), ref *material); gScene->addActor(ref *groundPlane); sr->release(); }
static void createLongChain() { const float scale = 0.25f; const float radius = 0.5f * scale; const float halfHeight = 1.0f * scale; const uint nbCapsules = 40; const float capsuleMass = 1.0f; PxVec3 initPos = new(0.0f, 24.0f, 0.0f); PxVec3 pos = initPos; PxShape *capsuleShape = gPhysics->createShape(new PxCapsuleGeometry(radius, halfHeight), *gMaterial, false, PxShapeFlags.eVISUALIZATION | PxShapeFlags.eSCENE_QUERY_SHAPE | PxShapeFlags.eSIMULATION_SHAPE); //BIOQUIRK: Missing defaults PxArticulationLink *firstLink = null; PxArticulationLink *parent = null; const bool overlappingLinks = true; // Change this for another kind of rope gArticulation->setSolverIterationCounts(16); // Create rope for (uint i = 0; i < nbCapsules; i++) { PxArticulationLink *link = gArticulation->createLink(parent, new PxTransform(pos)); if (firstLink == null) { firstLink = link; } link->attachShape(ref *capsuleShape); PxRigidBodyExt.setMassAndUpdateInertia(ref *link, capsuleMass); link->setLinearDamping(0.1f); link->setAngularDamping(0.1f); link->setMaxAngularVelocity(30f); link->setMaxLinearVelocity(100f); PxArticulationJointBase *joint = link->getInboundJoint(); if (joint != null) // Will be null for root link { #if USE_REDUCED_COORDINATE_ARTICULATION PxArticulationJointReducedCoordinate *rcJoint = static_cast <PxArticulationJointReducedCoordinate>(joint); rcJoint->setJointType(PxArticulationJointType.eSPHERICAL); rcJoint->setMotion(PxArticulationAxis.eSWING2, PxArticulationMotions.eFREE); rcJoint->setMotion(PxArticulationAxis.eSWING1, PxArticulationMotions.eFREE); rcJoint->setMotion(PxArticulationAxis.eTWIST, PxArticulationMotions.eFREE); rcJoint->setFrictionCoefficient(1f); rcJoint->setMaxJointVelocity(1000000f); #endif if (overlappingLinks) { joint->setParentPose(new PxTransform(new PxVec3(halfHeight, 0.0f, 0.0f))); joint->setChildPose(new PxTransform(new PxVec3(-halfHeight, 0.0f, 0.0f))); } else { joint->setParentPose(new PxTransform(new PxVec3(radius + halfHeight, 0.0f, 0.0f))); joint->setChildPose(new PxTransform(new PxVec3(-radius - halfHeight, 0.0f, 0.0f))); } } if (overlappingLinks) { pos.x += (radius + halfHeight * 2.0f); } else { pos.x += (radius + halfHeight) * 2.0f; } parent = link; } //Attach large & heavy box at the end of the rope { const float boxMass = 50.0f; const float boxSize = 1.0f; PxShape * boxShape = gPhysics->createShape(new PxBoxGeometry(boxSize, boxSize, boxSize), *gMaterial, false, PxShapeFlags.eVISUALIZATION | PxShapeFlags.eSCENE_QUERY_SHAPE | PxShapeFlags.eSIMULATION_SHAPE); //BIOQUIRK: Missing defaults pos.x -= (radius + halfHeight) * 2.0f; pos.x += (radius + halfHeight) + boxSize; PxArticulationLink *link = gArticulation->createLink(parent, new PxTransform(pos)); link->setLinearDamping(0.1f); link->setAngularDamping(0.1f); link->setMaxAngularVelocity(30f); link->setMaxLinearVelocity(100f); link->attachShape(ref *boxShape); PxRigidBodyExt.setMassAndUpdateInertia(ref *link, boxMass); PxArticulationJointBase *joint = link->getInboundJoint(); #if USE_REDUCED_COORDINATE_ARTICULATION PxArticulationJointReducedCoordinate *rcJoint = static_cast <PxArticulationJointReducedCoordinate>(joint); rcJoint->setJointType(PxArticulationJointType.eSPHERICAL); rcJoint->setMotion(PxArticulationAxis.eSWING2, PxArticulationMotions.eFREE); rcJoint->setMotion(PxArticulationAxis.eSWING1, PxArticulationMotions.eFREE); rcJoint->setMotion(PxArticulationAxis.eTWIST, PxArticulationMotions.eFREE); rcJoint->setFrictionCoefficient(1f); rcJoint->setMaxJointVelocity(1000000f); #endif if (joint != null) // Will be null for root link { joint->setParentPose(new PxTransform(new PxVec3(radius + halfHeight, 0.0f, 0.0f))); joint->setChildPose(new PxTransform(new PxVec3(-boxSize, 0.0f, 0.0f))); } } gScene->addArticulation(ref *gArticulation); #if USE_REDUCED_COORDINATE_ARTICULATION gArticulation->setArticulationFlags(PxArticulationFlags.eFIX_BASE); #else // Attach articulation to static world { PxShape *anchorShape = gPhysics->createShape(new PxSphereGeometry(0.05f), *gMaterial, false, PxShapeFlags.eVISUALIZATION | PxShapeFlags.eSCENE_QUERY_SHAPE | PxShapeFlags.eSIMULATION_SHAPE); //BIOQUIRK: Missing defaults PxRigidStatic *anchor = PxCreateStatic(ref *gPhysics, new PxTransform(initPos), ref *anchorShape); gScene->addActor(ref *anchor); PxSphericalJoint *j = PxSphericalJointCreate(ref *gPhysics, anchor, new PxTransform(new PxVec3(0.0f)), firstLink, new PxTransform(new PxVec3(0.0f))); } #endif // Create obstacle { PxShape *boxShape = gPhysics->createShape(new PxBoxGeometry(1.0f, 0.1f, 2.0f), *gMaterial, false, PxShapeFlags.eVISUALIZATION | PxShapeFlags.eSCENE_QUERY_SHAPE | PxShapeFlags.eSIMULATION_SHAPE); //BIOQUIRK: Missing defaults PxRigidStatic *obstacle = PxCreateStatic(ref *gPhysics, new PxTransform(initPos.operator_Plus(new PxVec3(10.0f, -3.0f, 0.0f))), ref *boxShape); //BIOQUIRK: Overloaded operator gScene->addActor(ref *obstacle); } }
public static void initPhysics() { gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, ref gAllocator.Value, ref gErrorCallback.Value); gPvd = PxCreatePvd(ref *gFoundation); PxPvdTransport *transport = PxDefaultPvdSocketTransportCreate(PVD_HOST, 5425, 10); gPvd->connect(ref *transport, PxPvdInstrumentationFlags.eALL); gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, ref *gFoundation, new PxTolerancesScale(), true, gPvd); PxSceneDesc sceneDesc = new(*gPhysics->getTolerancesScale()); sceneDesc.gravity = new PxVec3(0.0f, -9.81f, 0.0f); uint numWorkers = 1; gDispatcher = PxDefaultCpuDispatcherCreate(numWorkers); sceneDesc.cpuDispatcher = (PxCpuDispatcher *)gDispatcher; //BIOQUIRK: Base cast sceneDesc.filterShader = &VehicleFilterShader; gScene = gPhysics->createScene(sceneDesc); PxPvdSceneClient *pvdClient = gScene->getScenePvdClient(); if (pvdClient != null) { pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_CONSTRAINTS, true); pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_CONTACTS, true); pvdClient->setScenePvdFlag(PxPvdSceneFlags.eTRANSMIT_SCENEQUERIES, true); } gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f); gCooking = PxCreateCooking(PX_PHYSICS_VERSION, ref *gFoundation, new PxCookingParams(new PxTolerancesScale())); ///////////////////////////////////////////// PxInitVehicleSDK(ref *gPhysics); PxVehicleSetBasisVectors(new PxVec3(0, 1, 0), new PxVec3(0, 0, 1)); PxVehicleSetUpdateMode(PxVehicleUpdateMode.eVELOCITY_CHANGE); //Create the batched scene queries for the suspension raycasts. gVehicleSceneQueryData = VehicleSceneQueryData.allocate(1, PX_MAX_NB_WHEELS, 1, 1, &WheelSceneQueryPreFilterBlocking, null, ref gAllocator.Value); gBatchQuery = VehicleSceneQueryData.setUpBatchedSceneQuery(0, *gVehicleSceneQueryData, gScene); //Create the friction table for each combination of tire and surface type. gFrictionPairs = createFrictionPairs(gMaterial); //Create a plane to drive on. PxFilterData groundPlaneSimFilterData = new((uint)COLLISION_FLAG_GROUND, (uint)COLLISION_FLAG_GROUND_AGAINST, 0, 0); gGroundPlane = createDrivablePlane(groundPlaneSimFilterData, gMaterial, gPhysics); gScene->addActor(ref *gGroundPlane); //Create a vehicle that will drive on the plane. VehicleDesc vehicleDesc = initVehicleDesc(); gVehicleNoDrive = createVehicleNoDrive(vehicleDesc, gPhysics, gCooking); PxTransform startTransform = new(new PxVec3(0, (vehicleDesc.chassisDims.y * 0.5f + vehicleDesc.wheelRadius + 1.0f), 0), new PxQuat(PxIdentity)); gVehicleNoDrive->getRigidDynamicActor()->setGlobalPose(startTransform); gScene->addActor(ref *gVehicleNoDrive->getRigidDynamicActor()); //Set the vehicle to rest in first gear. //Set the vehicle to use auto-gears. gVehicleNoDrive->setToRestState(); gVehicleModeTimer = 0.0f; gVehicleOrderProgress = 0; startBrakeMode(); }