RavEngine
Loading...
Searching...
No Matches
BpBroadPhase.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef BP_BROADPHASE_H
30#define BP_BROADPHASE_H
31
32#include "foundation/PxUserAllocated.h"
33#include "PxBroadPhase.h"
34#include "BpBroadPhaseUpdate.h"
35
36namespace physx
37{
38 class PxcScratchAllocator;
39 class PxBaseTask;
40
41namespace Bp
42{
43
44class BroadPhaseUpdateData;
45
50{
51 public:
53 virtual ~BroadPhaseBase() {}
54
60 virtual void getCaps(PxBroadPhaseCaps& caps) const
61 {
62 caps.mMaxNbRegions = 0;
63 }
64
65 // PxBroadPhaseRegions
66 virtual PxU32 getNbRegions() const PX_OVERRIDE { return 0; }
67 virtual PxU32 getRegions(PxBroadPhaseRegionInfo*, PxU32, PxU32) const PX_OVERRIDE { return 0; }
68 virtual PxU32 addRegion(const PxBroadPhaseRegion&, bool, const PxBounds3*, const PxReal*) PX_OVERRIDE { return 0xffffffff;}
69 virtual bool removeRegion(PxU32) PX_OVERRIDE { return false; }
70 virtual PxU32 getNbOutOfBoundsObjects() const PX_OVERRIDE { return 0; }
71 virtual const PxU32* getOutOfBoundsObjects() const PX_OVERRIDE { return NULL; }
72 //~PxBroadPhaseRegions
73};
74
75/*
76\brief Structure used to report created and deleted broadphase pairs
77\note The indices mVolA and mVolB correspond to the bounds indices
78BroadPhaseUpdateData::mCreated used by BroadPhase::update
79@see BroadPhase::getCreatedPairs, BroadPhase::getDeletedPairs
80*/
82{
83 BroadPhasePair(ShapeHandle volA, ShapeHandle volB) :
84 mVolA (PxMin(volA, volB)),
85 mVolB (PxMax(volA, volB))
86 {
87 }
89 mVolA (BP_INVALID_BP_HANDLE),
90 mVolB (BP_INVALID_BP_HANDLE)
91 {
92 }
93
94 ShapeHandle mVolA; // NB: mVolA < mVolB
95 ShapeHandle mVolB;
96};
97
99{
100public:
101
114 static BroadPhase* create(
115 const PxBroadPhaseType::Enum bpType,
116 const PxU32 maxNbRegions,
117 const PxU32 maxNbBroadPhaseOverlaps,
118 const PxU32 maxNbStaticShapes,
119 const PxU32 maxNbDynamicShapes,
120 PxU64 contextID);
121
122 virtual PxBroadPhaseType::Enum getType() const = 0;
123
127 virtual void release() = 0;
128
147 virtual void update(PxcScratchAllocator* scratchAllocator, const BroadPhaseUpdateData& updateData, physx::PxBaseTask* continuation) = 0;
148
152 virtual void preBroadPhase(const Bp::BroadPhaseUpdateData& updateData) = 0;
153
157 virtual void fetchBroadPhaseResults() = 0;
158
159 /*
160 \brief Get created pairs.
161
162 Note that each overlap pair is reported only on the frame when the overlap first occurs. The overlap persists
163 until the pair appears in the list of deleted pairs or either of the bounds in the pair is removed from the broadphase.
164 A created overlap must involve at least one of the bounds of the overlap pair appearing in either the created or updated list.
165 It is impossible for the same pair to appear simultaneously in the list of created and deleted overlap pairs.
166 An overlap is defined as a pair of bounds that overlap on all three axes; that is when maxA > minB and maxB > minA for all three axes.
167
168 \param nbCreatedPairs [out] The number of created aabb overlap pairs computed in the execution of update() that has just completed.
169 \return The array of created aabb overlap pairs computed in the execution of update() that has just completed.
170 */
171 virtual const BroadPhasePair* getCreatedPairs(PxU32& nbCreatedPairs) const = 0;
172
185 virtual const BroadPhasePair* getDeletedPairs(PxU32& nbDeletedPairs) const = 0;
186
192 virtual void freeBuffers() = 0;
193
197 virtual void shiftOrigin(const PxVec3& shift, const PxBounds3* boundsArray, const PxReal* contactDistances) = 0;
198
199#if PX_CHECKED
206 virtual bool isValid(const BroadPhaseUpdateData& updateData) const = 0;
207#endif
208};
209
210} //namespace Bp
211
212} //namespace physx
213
214#endif //BP_BROADPHASE_H
Base broad phase class. Functions only relevant to MBP.
Definition BpBroadPhase.h:50
virtual PxU32 getNbRegions() const PX_OVERRIDE
Returns number of regions currently registered in the broad-phase.
Definition BpBroadPhase.h:66
virtual PxU32 addRegion(const PxBroadPhaseRegion &, bool, const PxBounds3 *, const PxReal *) PX_OVERRIDE
Adds a new broad-phase region.
Definition BpBroadPhase.h:68
virtual bool removeRegion(PxU32) PX_OVERRIDE
Removes a broad-phase region.
Definition BpBroadPhase.h:69
virtual void getCaps(PxBroadPhaseCaps &caps) const
Gets broad-phase caps.
Definition BpBroadPhase.h:60
virtual PxU32 getRegions(PxBroadPhaseRegionInfo *, PxU32, PxU32) const PX_OVERRIDE
Gets broad-phase regions.
Definition BpBroadPhase.h:67
Definition BpBroadPhaseUpdate.h:47
Definition BpBroadPhase.h:99
virtual void fetchBroadPhaseResults()=0
Fetch the results of any asynchronous broad phase work.
virtual void shiftOrigin(const PxVec3 &shift, const PxBounds3 *boundsArray, const PxReal *contactDistances)=0
Adjust internal structures after all bounds have been adjusted due to a scene origin shift.
virtual void preBroadPhase(const Bp::BroadPhaseUpdateData &updateData)=0
prepare broad phase data.
virtual void freeBuffers()=0
After the broadphase has completed its update() function and the created/deleted pairs have been quer...
virtual void release()=0
Shutdown of the broadphase.
virtual void update(PxcScratchAllocator *scratchAllocator, const BroadPhaseUpdateData &updateData, physx::PxBaseTask *continuation)=0
Updates the broadphase and computes the lists of created/deleted pairs.
static BroadPhase * create(const PxBroadPhaseType::Enum bpType, const PxU32 maxNbRegions, const PxU32 maxNbBroadPhaseOverlaps, const PxU32 maxNbStaticShapes, const PxU32 maxNbDynamicShapes, PxU64 contextID)
Instantiate a BroadPhase instance.
Definition BpBroadPhase.cpp:37
virtual const BroadPhasePair * getDeletedPairs(PxU32 &nbDeletedPairs) const =0
Get deleted pairs.
Base class of all task types.
Definition PxTask.h:45
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Broadphase regions.
Definition PxBroadPhase.h:325
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
Definition PxcScratchAllocator.h:42
#define PX_OVERRIDE
Definition PxPreprocessor.h:375
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMax(T a, T b)
The return value is the greater of the two specified values.
Definition PxMath.h:72
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMin(T a, T b)
The return value is the lesser of the two specified values.
Definition PxMath.h:88
Definition BpBroadPhase.h:82
Caps class for broad phase.
Definition PxBroadPhase.h:131
PxU32 mMaxNbRegions
Max number of regions supported by the broad-phase (0 = explicit regions not needed)
Definition PxBroadPhase.h:132
Information & stats structure for a region.
Definition PxBroadPhase.h:119
"Region of interest" for the broad-phase.
Definition PxBroadPhase.h:110
Enum
Definition PxBroadPhase.h:79