PT: very crude attempt here, just to have something running
| 617 | |
| 618 | // PT: very crude attempt here, just to have something running |
| 619 | static void applyBombForce(PxRigidActor* actor, const PxVec3& actorPos, const PxVec3& bombPos, PxReal bombRange) |
| 620 | { |
| 621 | PxRigidDynamic* dyna = actor->is<PxRigidDynamic>(); |
| 622 | if(dyna) |
| 623 | { |
| 624 | PxVec3 dir = (actorPos - bombPos); |
| 625 | const PxReal m = dir.magnitude(); |
| 626 | if(m<bombRange) |
| 627 | { |
| 628 | const PxReal coeff = (1.0f - m/bombRange) * 50.0f; |
| 629 | dir /= m; |
| 630 | // dyna->addForce(dir*coeff); |
| 631 | |
| 632 | PxBounds3 worldBounds = dyna->getWorldBounds(); |
| 633 | |
| 634 | const PxVec3 center = worldBounds.getCenter(); |
| 635 | const PxVec3 extents = worldBounds.getExtents(); |
| 636 | const PxVec3 axis0(extents.x, 0.0f, 0.0f); |
| 637 | const PxVec3 axis1(0.0f, extents.y, 0.0f); |
| 638 | const PxVec3 axis2(0.0f, 0.0f, extents.z); |
| 639 | |
| 640 | PxVec3 pts[8]; |
| 641 | pts[0] = pts[3] = pts[4] = pts[7] = center - axis0; |
| 642 | pts[1] = pts[2] = pts[5] = pts[6] = center + axis0; |
| 643 | |
| 644 | PxVec3 tmp = axis1 + axis2; |
| 645 | pts[0] -= tmp; |
| 646 | pts[1] -= tmp; |
| 647 | pts[6] += tmp; |
| 648 | pts[7] += tmp; |
| 649 | |
| 650 | tmp = axis1 - axis2; |
| 651 | pts[2] += tmp; |
| 652 | pts[3] += tmp; |
| 653 | pts[4] -= tmp; |
| 654 | pts[5] -= tmp; |
| 655 | |
| 656 | PxReal minDist = 1e+30f; |
| 657 | PxU32 index = 0; |
| 658 | for(PxU32 i=0;i<8;i++) |
| 659 | { |
| 660 | PxReal d2 = (pts[i] - bombPos).magnitudeSquared(); |
| 661 | if(d2<minDist) |
| 662 | { |
| 663 | minDist = d2; |
| 664 | index = i; |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | PxRigidBodyExt::addForceAtPos(*dyna, dir*coeff, pts[index]); |
| 669 | // PxRigidBodyExt::addForceAtPos(*dyna, dir*coeff, actorPos); |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | template<class T> |
| 675 | bool findAndReplaceWithLast(std::vector<T*>& array, T* ptr) |
no test coverage detected