-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathRNPhysXWorld.cpp
More file actions
627 lines (526 loc) · 19.8 KB
/
RNPhysXWorld.cpp
File metadata and controls
627 lines (526 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
//
// RNPhysXWorld.cpp
// Rayne-PhysX
//
// Copyright 2017 by Überpixel. All rights reserved.
// Unauthorized use is punishable by torture, mutilation, and vivisection.
//
#include "RNPhysXWorld.h"
#include "PxPhysicsAPI.h"
#include "RNPhysXInternals.h"
namespace RN
{
RNDefineMeta(PhysXWorld, SceneAttachment)
physx::PxDefaultErrorCallback gDefaultErrorCallback;
physx::PxDefaultAllocator gDefaultAllocatorCallback;
PhysXWorld *PhysXWorld::_sharedInstance = nullptr;
void PhysXWorld::EnqueuePoseChange(PhysXCollisionObject *collisionObject)
{
if(!collisionObject) return;
if(collisionObject->IsPoseUpdateQueued()) return;
size_t slot = 0;
if(!_pendingPoseChanges.PushWithIndex(collisionObject, slot))
{
RN_ASSERT(false, "PhysXWorld pose queue is full, dropping collision object transform update.");
return;
}
if(!collisionObject->TryMarkPoseUpdateQueued(slot))
{
_pendingPoseChanges.NullSlot(slot);
return;
}
collisionObject->Retain();
}
void PhysXWorld::FlushQueuedPoseChanges()
{
PhysXCollisionObject *collisionObject;
size_t slot = 0;
while(_pendingPoseChanges.PopWithIndex(collisionObject, slot))
{
if(!collisionObject) continue;
if(collisionObject->ClearPoseUpdateQueued(slot))
{
collisionObject->ApplyPose();
collisionObject->Release();
}
}
}
void PhysXWorld::ClearPoseQueueSlot(size_t slot)
{
_pendingPoseChanges.NullSlot(slot);
}
PhysXWorld::PhysXWorld(const Vector3 &gravity, String *pvdServerIP) :
_pvd(nullptr), _hasVehicles(false), _substeps(1), _paused(false), _isSimulating(false)
{
RN_ASSERT(!_sharedInstance, "There can only be one PhysX instance at a time!");
_sharedInstance = this;
_foundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback);
RN_ASSERT(_foundation, "PxCreateFoundation failed!");
if(pvdServerIP)
{
_pvd = physx::PxCreatePvd(*_foundation);
physx::PxPvdTransport *transport = physx::PxDefaultPvdSocketTransportCreate(pvdServerIP->GetUTF8String(), 5425, 1000); //First parameter is ip of system running the physx visual debugger
const bool connected = _pvd->connect(*transport, physx::PxPvdInstrumentationFlag::eALL);
RNDebug("PVD connected: " << connected);
}
bool recordMemoryAllocations = true;
physx::PxTolerancesScale scale;
_physics = PxCreatePhysics(PX_PHYSICS_VERSION, *_foundation, scale, recordMemoryAllocations, _pvd);
RN_ASSERT(_physics, "PxCreatePhysics failed!");
RN_ASSERT(PxInitExtensions(*_physics, _pvd), "PxInitExtensions failed!");
_cooking = PxCreateCooking(PX_PHYSICS_VERSION, *_foundation, physx::PxCookingParams(scale));
RN_ASSERT(_cooking, "PxCreateCooking failed!");
_simulationCallback = new PhysXSimulationCallback();
physx::PxSceneDesc sceneDesc(_physics->getTolerancesScale());
sceneDesc.solverType = physx::PxSolverType::eTGS; //Enables the better, but somewhat slower solver
sceneDesc.gravity = physx::PxVec3(gravity.x, gravity.y, gravity.z);
_dispatcher = physx::PxDefaultCpuDispatcherCreate(2);
sceneDesc.cpuDispatcher = _dispatcher;
sceneDesc.filterShader = PhysXCallback::CollisionFilterShader;
sceneDesc.simulationEventCallback = _simulationCallback;
//sceneDesc.kineKineFilteringMode = physx::PxPairFilteringMode::eKEEP;
//sceneDesc.staticKineFilteringMode = physx::PxPairFilteringMode::eKEEP;
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_ACTIVE_ACTORS | physx::PxSceneFlag::eENABLE_CCD /*| physx::PxSceneFlag::eREQUIRE_RW_LOCK*/ | physx::PxSceneFlag::eADAPTIVE_FORCE /* | physx::PxSceneFlag::eENABLE_STABILIZATION*/; // adaptive force and stabilization can not both be enabled!
_scene = _physics->createScene(sceneDesc);
physx::PxPvdSceneClient *pvdClient = _scene->getScenePvdClient();
if(pvdClient)
{
pvdClient->setScenePvdFlag(physx::PxPvdSceneFlag::eTRANSMIT_CONSTRAINTS, true);
pvdClient->setScenePvdFlag(physx::PxPvdSceneFlag::eTRANSMIT_CONTACTS, true);
pvdClient->setScenePvdFlag(physx::PxPvdSceneFlag::eTRANSMIT_SCENEQUERIES, true);
}
_controllerManagerFilterCallback = new PhysXKinematicControllerCallback();
_controllerManager = PxCreateControllerManager(*_scene);
}
PhysXWorld::~PhysXWorld()
{
//TODO: delete all collision objects
_controllerManager->release();
delete _controllerManagerFilterCallback;
_scene->release();
_dispatcher->release();
delete _simulationCallback;
_cooking->release();
if(_hasVehicles)
{
physx::PxCloseVehicleSDK();
}
PxCloseExtensions();
_physics->release();
if(_pvd)
{
physx::PxPvdTransport *transport = _pvd->getTransport();
_pvd->release();
transport->release();
}
_foundation->release();
_sharedInstance = nullptr;
}
void PhysXWorld::SetGravity(const Vector3 &gravity)
{
Lock();
_scene->setGravity(physx::PxVec3(gravity.x, gravity.y, gravity.z));
Unlock();
}
Vector3 PhysXWorld::GetGravity()
{
Lock();
const physx::PxVec3 &gravity = _scene->getGravity();
Unlock();
return Vector3(gravity.x, gravity.y, gravity.z);
}
void PhysXWorld::InitializeVehicles()
{
PxInitVehicleSDK(*_physics);
PxVehicleSetBasisVectors(physx::PxVec3(0.0f, 1.0f, 0.0f), physx::PxVec3(0.0f, 0.0f, -1.0f));
PxVehicleSetUpdateMode(physx::PxVehicleUpdateMode::eVELOCITY_CHANGE);
_hasVehicles = true;
}
void PhysXWorld::SetSubsteps(uint8 substeps)
{
_substeps = substeps;
}
void PhysXWorld::SetPaused(bool paused)
{
_paused = paused;
}
void PhysXWorld::Update(float delta)
{
FlushQueuedPoseChanges();
if(_paused)
{
return;
}
if(delta > 0.1f || delta < k::EpsilonFloat)
{
return;
}
if(_substeps > 1 && delta > RN::k::EpsilonFloat)
{
for(int i = 0; i < _substeps; i++)
{
_isSimulating = true;
_scene->simulate(delta / static_cast<double>(_substeps)); //TODO: Fix this to use fixed steps with interpolation...
_scene->fetchResults(true);
_isSimulating = false;
}
}
else if(_substeps == 1 && _isSimulating)
{
_scene->fetchResults(true); //This blocks and waits for the physics simulation to finish
_isSimulating = false;
}
physx::PxU32 actorCount = 0;
physx::PxActor **actors = _scene->getActiveActors(actorCount);
for(int i = 0; i < actorCount; i++)
{
void *userData = actors[i]->userData;
if(userData)
{
PhysXCollisionObject *collisionObject = static_cast<PhysXCollisionObject *>(userData);
collisionObject->UpdatePosition();
}
}
}
void PhysXWorld::WillUpdate(float delta)
{
SceneAttachment::WillUpdate(delta);
if(delta > RN::k::EpsilonFloat)
{
_controllerManager->computeInteractions(delta, _controllerManagerFilterCallback);
if(_substeps == 1 && !_isSimulating)
{
_isSimulating = true;
_scene->simulate(delta / static_cast<double>(_substeps)); //This returns immediately and kicks off the physics simulation BEFORE updating any scene nodes, this makes the physics simulation lag behind one frame, but allows running it in parallel to the scene node updates. Direct transform changes will immediately be reflected, others only a frame later
}
}
}
PhysXContactInfo PhysXWorld::CastRay(const Vector3 &from, const Vector3 &to, uint32 filterGroup, uint32 filterMask)
{
PhysXContactInfo hit;
hit.distance = -1.0f;
hit.node = nullptr;
hit.collisionObject = nullptr;
hit.shapeSelf = nullptr;
hit.shapeOther = nullptr;
Vector3 diff = to - from;
float distance = diff.GetLength();
diff.Normalize();
physx::PxRaycastBuffer callback;
physx::PxFilterData filterData;
filterData.word0 = filterGroup;
filterData.word1 = filterMask;
filterData.word2 = 0;
filterData.word3 = 0;
PhysXQueryFilterCallback queryFilter;
bool didHit = _scene->raycast(physx::PxVec3(from.x, from.y, from.z), physx::PxVec3(diff.x, diff.y, diff.z), distance, callback, physx::PxHitFlags(physx::PxHitFlag::eDEFAULT), physx::PxQueryFilterData(filterData, physx::PxQueryFlag::eDYNAMIC | physx::PxQueryFlag::eSTATIC | physx::PxQueryFlag::ePREFILTER), &queryFilter);
if(didHit)
{
hit.distance = callback.block.distance;
hit.position = from + diff * hit.distance;
hit.normal.x = callback.block.normal.x;
hit.normal.y = callback.block.normal.y;
hit.normal.z = callback.block.normal.z;
if(callback.block.actor)
{
void *userData = callback.block.actor->userData;
if(userData)
{
hit.collisionObject = static_cast<PhysXCollisionObject *>(userData);
hit.node = hit.collisionObject->GetParent();
if(hit.node) hit.node->Retain()->Autorelease();
}
}
if(callback.block.shape)
{
hit.shapeOther = static_cast<PhysXShape *>(callback.block.shape->userData);
}
}
return hit;
}
std::vector<PhysXContactInfo> PhysXWorld::CastRayAll(const Vector3 &from, const Vector3 &to, uint32 filterGroup, uint32 filterMask, uint32 maxNumberOfHits)
{
Vector3 diff = to - from;
float distance = diff.GetLength();
diff.Normalize();
const physx::PxU32 bufferSize = maxNumberOfHits;
physx::PxRaycastHit *hitBuffer = new physx::PxRaycastHit[bufferSize];
physx::PxRaycastBuffer callback(hitBuffer, bufferSize);
physx::PxFilterData filterData;
filterData.word0 = filterGroup;
filterData.word1 = filterMask;
filterData.word2 = 0;
filterData.word3 = 0;
PhysXQueryFilterCallback queryFilter;
std::vector<PhysXContactInfo> results;
bool didHit = _scene->raycast(physx::PxVec3(from.x, from.y, from.z), physx::PxVec3(diff.x, diff.y, diff.z), distance, callback, physx::PxHitFlags(physx::PxHitFlag::eDEFAULT), physx::PxQueryFilterData(filterData, physx::PxQueryFlag::eDYNAMIC | physx::PxQueryFlag::eSTATIC | physx::PxQueryFlag::eNO_BLOCK | physx::PxQueryFlag::ePREFILTER), &queryFilter);
if(didHit)
{
for(uint32 i = 0; i < callback.nbTouches; i++)
{
PhysXContactInfo hit;
hit.distance = callback.touches[i].distance;
hit.node = nullptr;
hit.collisionObject = nullptr;
hit.position = from + diff * hit.distance;
hit.normal.x = callback.touches[i].normal.x;
hit.normal.y = callback.touches[i].normal.y;
hit.normal.z = callback.touches[i].normal.z;
if(callback.touches[i].actor)
{
void *userData = callback.touches[i].actor->userData;
if(userData)
{
hit.collisionObject = static_cast<PhysXCollisionObject *>(userData);
hit.node = hit.collisionObject->GetParent();
if(hit.node) hit.node->Retain()->Autorelease();
}
}
hit.shapeSelf = nullptr;
hit.shapeOther = callback.touches[i].shape ? static_cast<PhysXShape *>(callback.touches[i].shape->userData) : nullptr;
results.push_back(hit);
}
}
return results;
}
PhysXContactInfo PhysXWorld::CastSweep(PhysXShape *shape, const Quaternion &rotation, const Vector3 &from, const Vector3 &to, float inflation, uint32 filterGroup, uint32 filterMask)
{
PhysXContactInfo hit;
hit.distance = -1.0f;
hit.node = nullptr;
hit.collisionObject = nullptr;
hit.shapeSelf = shape;
hit.shapeOther = nullptr;
Vector3 diff = to - from;
float distance = diff.GetLength();
if(distance < RN::k::EpsilonFloat) return hit;
diff.Normalize();
physx::PxFilterData filterData;
filterData.word0 = filterGroup;
filterData.word1 = filterMask;
filterData.word2 = 0;
filterData.word3 = 0;
PhysXQueryFilterCallback queryFilter;
const physx::PxTransform pose(
physx::PxVec3(from.x, from.y, from.z),
physx::PxQuat(rotation.x, rotation.y, rotation.z, rotation.w));
const physx::PxVec3 dir(diff.x, diff.y, diff.z);
auto sweep = [&](PhysXShape *testShape) {
if(!testShape) return;
physx::PxShape *pxShape = testShape->GetPhysXShape();
if(!pxShape) return;
queryFilter.ignoreActor = pxShape->getActor();
physx::PxSweepBuffer callback;
const bool didHit = _scene->sweep(pxShape->getGeometry().any(), pose, dir, distance, callback, physx::PxHitFlags(physx::PxHitFlag::eDEFAULT), physx::PxQueryFilterData(filterData, physx::PxQueryFlag::eDYNAMIC | physx::PxQueryFlag::eSTATIC | physx::PxQueryFlag::ePREFILTER), &queryFilter, 0, inflation);
if(!didHit)
return;
// Keep closest blocking hit across all children
if(hit.distance < 0.0f || callback.block.distance < hit.distance)
{
hit.distance = callback.block.distance;
hit.position.x = callback.block.position.x;
hit.position.y = callback.block.position.y;
hit.position.z = callback.block.position.z;
hit.normal.x = callback.block.normal.x;
hit.normal.y = callback.block.normal.y;
hit.normal.z = callback.block.normal.z;
hit.node = nullptr;
hit.collisionObject = nullptr;
if(callback.block.actor)
{
void *userData = callback.block.actor->userData;
if(userData)
{
hit.collisionObject = static_cast<PhysXCollisionObject *>(userData);
hit.node = hit.collisionObject->GetParent();
if(hit.node) hit.node->Retain()->Autorelease();
}
}
hit.shapeSelf = testShape; // the child that hit
hit.shapeOther = callback.block.shape ? static_cast<PhysXShape *>(callback.block.shape->userData) : nullptr;
}
};
if(shape->GetPhysXShape())
{
sweep(shape);
}
else if(shape->IsKindOfClass(PhysXCompoundShape::GetMetaClass()))
{
PhysXCompoundShape *compound = shape->Downcast<PhysXCompoundShape>();
for(size_t i = 0; i < compound->GetNumberOfShapes(); i++)
{
PhysXShape *child = compound->GetShape(i);
sweep(child);
}
// todo(OJ) or return compound shape? if(bestHit.distance >= 0.0f) bestHit.shapeSelf = shape;
}
else
{
RNDebug("CastSweep does not currently support this shape type!");
}
return hit;
}
std::vector<PhysXContactInfo> PhysXWorld::CheckOverlap(PhysXShape *shape, const Vector3 &position, const Quaternion &rotation, float inflation, uint32 filterGroup, uint32 filterMask, uint32 maxNumberOfOverlaps)
{
const physx::PxU32 bufferSize = maxNumberOfOverlaps;
physx::PxSweepHit *hitBuffer = new physx::PxSweepHit[bufferSize];
physx::PxSweepBuffer callback(hitBuffer, bufferSize);
physx::PxFilterData filterData;
filterData.word0 = filterGroup;
filterData.word1 = filterMask;
filterData.word2 = 0;
filterData.word3 = 0;
PhysXQueryFilterCallback queryFilter;
physx::PxTransform pose = physx::PxTransform(physx::PxVec3(position.x, position.y, position.z), physx::PxQuat(rotation.x, rotation.y, rotation.z, rotation.w));
std::vector<PhysXContactInfo> results;
if(shape->GetPhysXShape())
{
if(_scene->sweep(shape->GetPhysXShape()->getGeometry().any(), pose, physx::PxVec3(0.0f, 1.0f, 0.0f), 0.0f, callback, physx::PxHitFlags(physx::PxHitFlag::eDEFAULT), physx::PxQueryFilterData(filterData, physx::PxQueryFlag::eDYNAMIC | physx::PxQueryFlag::eSTATIC | physx::PxQueryFlag::eNO_BLOCK | physx::PxQueryFlag::ePREFILTER), &queryFilter, 0, inflation))
{
for(uint32 i = 0; i < callback.nbTouches; i++)
{
PhysXContactInfo hit;
hit.distance = 0.0f;
hit.node = nullptr;
hit.collisionObject = nullptr;
hit.position = position;
if(callback.touches[i].actor)
{
void *userData = callback.touches[i].actor->userData;
if(userData)
{
hit.collisionObject = static_cast<PhysXCollisionObject *>(userData);
hit.node = hit.collisionObject->GetParent();
if(hit.node) hit.node->Retain()->Autorelease();
}
}
hit.shapeSelf = shape;
hit.shapeOther = callback.touches[i].shape ? static_cast<PhysXShape *>(callback.touches[i].shape->userData) : nullptr;
results.push_back(hit);
}
}
}
else if(shape->IsKindOfClass(PhysXCompoundShape::GetMetaClass()))
{
PhysXCompoundShape *compoundShape = shape->Downcast<PhysXCompoundShape>();
for(size_t i = 0; i < compoundShape->GetNumberOfShapes(); i++)
{
PhysXShape *tempShape = compoundShape->GetShape(i);
if(_scene->sweep(tempShape->GetPhysXShape()->getGeometry().any(), pose, physx::PxVec3(0.0f, 1.0f, 0.0f), 0.0f, callback, physx::PxHitFlags(physx::PxHitFlag::eDEFAULT), physx::PxQueryFilterData(filterData, physx::PxQueryFlag::eDYNAMIC | physx::PxQueryFlag::eSTATIC | physx::PxQueryFlag::eNO_BLOCK | physx::PxQueryFlag::ePREFILTER), &queryFilter, 0, inflation))
{
for(uint32 i = 0; i < callback.nbTouches; i++)
{
PhysXContactInfo hit;
hit.distance = 0.0f;
hit.node = nullptr;
hit.collisionObject = nullptr;
hit.position = position;
if(callback.touches[i].actor)
{
void *userData = callback.touches[i].actor->userData;
if(userData)
{
hit.collisionObject = static_cast<PhysXCollisionObject *>(userData);
hit.node = hit.collisionObject->GetParent();
if(hit.node) hit.node->Retain()->Autorelease();
}
}
hit.shapeSelf = tempShape;
hit.shapeOther = callback.touches[i].shape ? static_cast<PhysXShape *>(callback.touches[i].shape->userData) : nullptr;
results.push_back(hit);
}
}
}
}
else
{
RNDebug("CheckOverlap does not currently support this shape type!");
}
delete[] hitBuffer;
return results;
}
bool PhysXWorld::ComputePenetration(PhysXShape *shape0, const Vector3 &position0, const Quaternion &rotation0,
PhysXShape *shape1, const Vector3 &position1, const Quaternion &rotation1,
Vector3 &outDirection, float &outDepth)
{
outDepth = 0.0f;
outDirection = Vector3(0.0f, 0.0f, 0.0f);
if(!shape0 || !shape1)
return false;
const physx::PxTransform pose0(
physx::PxVec3(position0.x, position0.y, position0.z),
physx::PxQuat(rotation0.x, rotation0.y, rotation0.z, rotation0.w));
const physx::PxTransform pose1(
physx::PxVec3(position1.x, position1.y, position1.z),
physx::PxQuat(rotation1.x, rotation1.y, rotation1.z, rotation1.w));
bool hasPenetration = false;
physx::PxVec3 bestDirection(0.0f, 0.0f, 0.0f);
physx::PxF32 bestDepth = 0.0f;
// Small helper that tests one shape pair and keeps the deepest penetration
auto testPair = [&](PhysXShape *s0, const physx::PxTransform &p0,
PhysXShape *s1, const physx::PxTransform &p1) {
if(!s0 || !s1) return;
physx::PxShape *pxShape0 = s0->GetPhysXShape();
physx::PxShape *pxShape1 = s1->GetPhysXShape();
if(!pxShape0 || !pxShape1) return;
physx::PxGeometryHolder geomHolder0 = pxShape0->getGeometry();
physx::PxGeometryHolder geomHolder1 = pxShape1->getGeometry();
const physx::PxGeometry &geom0 = geomHolder0.any();
const physx::PxGeometry &geom1 = geomHolder1.any();
physx::PxVec3 direction;
physx::PxF32 depth = 0.0f;
if(physx::PxGeometryQuery::computePenetration(direction, depth, geom0, p0, geom1, p1))
{
if(depth > bestDepth || !hasPenetration)
{
bestDepth = depth;
bestDirection = direction;
hasPenetration = true;
}
}
};
const bool shape0IsCompound = shape0->IsKindOfClass(PhysXCompoundShape::GetMetaClass());
const bool shape1IsCompound = shape1->IsKindOfClass(PhysXCompoundShape::GetMetaClass());
if(!shape0IsCompound && !shape1IsCompound)
{
testPair(shape0, pose0, shape1, pose1);
}
else if(shape0IsCompound && !shape1IsCompound)
{
PhysXCompoundShape *compound0 = shape0->Downcast<PhysXCompoundShape>();
for(size_t i = 0; i < compound0->GetNumberOfShapes(); ++i)
{
PhysXShape *child0 = compound0->GetShape(i);
testPair(child0, pose0, shape1, pose1);
}
}
else if(!shape0IsCompound && shape1IsCompound)
{
PhysXCompoundShape *compound1 = shape1->Downcast<PhysXCompoundShape>();
for(size_t i = 0; i < compound1->GetNumberOfShapes(); ++i)
{
PhysXShape *child1 = compound1->GetShape(i);
testPair(shape0, pose0, child1, pose1);
}
}
else
{
PhysXCompoundShape *compound0 = shape0->Downcast<PhysXCompoundShape>();
PhysXCompoundShape *compound1 = shape1->Downcast<PhysXCompoundShape>();
for(size_t i = 0; i < compound0->GetNumberOfShapes(); ++i)
{
PhysXShape *child0 = compound0->GetShape(i);
for(size_t j = 0; j < compound1->GetNumberOfShapes(); ++j)
{
PhysXShape *child1 = compound1->GetShape(j);
testPair(child0, pose0, child1, pose1);
}
}
}
if(!hasPenetration)
return false;
outDirection = RN::Vector3(bestDirection.x, bestDirection.y, bestDirection.z);
outDepth = bestDepth;
return true;
}
} // namespace RN