constructor which configures PhysX
| 220 | |
| 221 | //constructor which configures PhysX |
| 222 | PhysicsSolver::PhysicsSolver(){ |
| 223 | if (foundation == nullptr){ |
| 224 | foundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback); |
| 225 | } |
| 226 | if (foundation == nullptr){ |
| 227 | cerr << "PhysX foundation failed!" << endl; |
| 228 | } |
| 229 | bool recordMemoryAllocations = true; |
| 230 | if (pvd == nullptr) { |
| 231 | pvd = PxCreatePvd(*foundation); |
| 232 | PxPvdTransport* transport = PxDefaultPvdSocketTransportCreate(PVD_HOST, 5425, 10); |
| 233 | pvd->connect(*transport, PxPvdInstrumentationFlag::eALL); |
| 234 | if (phys == nullptr) { |
| 235 | phys = PxCreatePhysics(PX_PHYSICS_VERSION, *foundation, PxTolerancesScale(), recordMemoryAllocations, pvd); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | //create PhysX scene |
| 240 | PxSceneDesc desc(phys->getTolerancesScale()); |
| 241 | desc.gravity = PxVec3(0.0f, -9.81f, 0.0f); |
| 242 | |
| 243 | //set the dispatcher (can be CPU or Multithreaded GPU) |
| 244 | auto cpuDispatcher = PxDefaultCpuDispatcherCreate(std::thread::hardware_concurrency()); |
| 245 | if (!cpuDispatcher) { |
| 246 | throw std::runtime_error("PhysX dispatcher failed to create "); |
| 247 | } |
| 248 | desc.cpuDispatcher = cpuDispatcher; |
| 249 | |
| 250 | desc.filterShader = SampleFilterShader; |
| 251 | desc.simulationEventCallback = this; |
| 252 | |
| 253 | //create the scene |
| 254 | scene = phys->createScene(desc); |
| 255 | if (!scene) { |
| 256 | throw std::runtime_error("PhysX scene failed to create"); |
| 257 | } |
| 258 | } |
nothing calls this directly
no test coverage detected