void NpSpatialIndex::update(PxSpatialIndexItemId id, const PxBounds3& bounds) { PX_SIMD_GUARD; PX_CHECK_AND_RETURN(bounds.isValid(), "PxSpatialIndex::update: bounds are not valid."); mPruner->updateObjects(&id, &bounds); mPendingUpdates = true; }
PxBounds3 NpCloth::getWorldBounds(float inflation) const { NP_READ_CHECK(NpActor::getOwnerScene(*this)); const PxBounds3 bounds = mCloth.getWorldBounds(); PX_ASSERT(bounds.isValid()); // PT: unfortunately we can't just scale the min/max vectors, we need to go through center/extents. const PxVec3 center = bounds.getCenter(); const PxVec3 inflatedExtents = bounds.getExtents() * inflation; return PxBounds3::centerExtents(center, inflatedExtents); }
PxSpatialIndexItemId NpSpatialIndex::insert(PxSpatialIndexItem& item, const PxBounds3& bounds) { PX_SIMD_GUARD; PX_CHECK_AND_RETURN_VAL(bounds.isValid(), "PxSpatialIndex::insert: bounds are not valid.", PX_SPATIAL_INDEX_INVALID_ITEM_ID); Sq::PrunerHandle output; Sq::PrunerPayload payload; payload.data[0] = reinterpret_cast<size_t>(&item); mPruner->addObjects(&output, &bounds, &payload); mPendingUpdates = true; return output; }
void NpSpatialIndex::overlap(const PxBounds3& aabb, PxSpatialOverlapCallback& callback) const { PX_SIMD_GUARD; PX_CHECK_AND_RETURN(aabb.isValid(), "PxSpatialIndex::overlap: aabb is not valid."); flushUpdates(); OverlapCallback cb(callback); PxBoxGeometry boxGeom(aabb.getExtents()); PxTransform xf(aabb.getCenter()); Sq::ShapeData shapeData(boxGeom, xf, 0.0f); // temporary rvalue not compatible with PX_NOCOPY mPruner->overlap(shapeData, cb); }
PxBounds3 NpArticulation::getWorldBounds(float inflation) const { NP_READ_CHECK(getOwnerScene()); PxBounds3 bounds = PxBounds3::empty(); for(PxU32 i=0; i < mArticulationLinks.size(); i++) { bounds.include(mArticulationLinks[i]->getWorldBounds()); } PX_ASSERT(bounds.isValid()); // PT: unfortunately we can't just scale the min/max vectors, we need to go through center/extents. const PxVec3 center = bounds.getCenter(); const PxVec3 inflatedExtents = bounds.getExtents() * inflation; return PxBounds3::centerExtents(center, inflatedExtents); }
void NpSpatialIndex::sweep(const PxBounds3& aabb, const PxVec3& unitDir, PxReal maxDist, PxSpatialLocationCallback& callback) const { PX_SIMD_GUARD; PX_CHECK_AND_RETURN(aabb.isValid(), "PxSpatialIndex::sweep: aabb is not valid."); PX_CHECK_AND_RETURN(unitDir.isFinite() && unitDir.isNormalized(), "PxSpatialIndex::sweep: unitDir is not valid."); PX_CHECK_AND_RETURN(maxDist > 0.0f, "PxSpatialIndex::sweep: distance must be positive"); flushUpdates(); LocationCallback cb(callback); PxBoxGeometry boxGeom(aabb.getExtents()); PxTransform xf(aabb.getCenter()); Sq::ShapeData shapeData(boxGeom, xf, 0.0f); // temporary rvalue not compatible with PX_NOCOPY mPruner->sweep(shapeData, unitDir, maxDist, cb); }
PxU32 PxBroadPhaseExt::createRegionsFromWorldBounds(PxBounds3* regions, const PxBounds3& globalBounds, PxU32 nbSubdiv, PxU32 upAxis) { PX_CHECK_MSG(globalBounds.isValid(), "PxBroadPhaseExt::createRegionsFromWorldBounds(): invalid bounds provided!"); PX_CHECK_MSG(upAxis<3, "PxBroadPhaseExt::createRegionsFromWorldBounds(): invalid up-axis provided!"); const PxVec3& min = globalBounds.minimum; const PxVec3& max = globalBounds.maximum; const float dx = (max.x - min.x) / float(nbSubdiv); const float dy = (max.y - min.y) / float(nbSubdiv); const float dz = (max.z - min.z) / float(nbSubdiv); PxU32 nbRegions = 0; PxVec3 currentMin, currentMax; for(PxU32 j=0;j<nbSubdiv;j++) { for(PxU32 i=0;i<nbSubdiv;i++) { if(upAxis==0) { currentMin = PxVec3(min.x, min.y + dy * float(i), min.z + dz * float(j)); currentMax = PxVec3(max.x, min.y + dy * float(i+1), min.z + dz * float(j+1)); } else if(upAxis==1) { currentMin = PxVec3(min.x + dx * float(i), min.y, min.z + dz * float(j)); currentMax = PxVec3(min.x + dx * float(i+1), max.y, min.z + dz * float(j+1)); } else if(upAxis==2) { currentMin = PxVec3(min.x + dx * float(i), min.y + dy * float(j), min.z); currentMax = PxVec3(min.x + dx * float(i+1), min.y + dy * float(j+1), max.z); } regions[nbRegions++] = PxBounds3(currentMin, currentMax); } } return nbRegions; }