RavEngine
Loading...
Searching...
No Matches
BpBroadPhaseMBPCommon.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_MBP_COMMON_H
30#define BP_BROADPHASE_MBP_COMMON_H
31
32#include "PxPhysXConfig.h"
33#include "BpBroadPhaseIntegerAABB.h"
34#include "foundation/PxUserAllocated.h"
35
36namespace physx
37{
38namespace Bp
39{
40
41#define MBP_USE_WORDS
42#define MBP_USE_NO_CMP_OVERLAP
43#if PX_INTEL_FAMILY && !defined(PX_SIMD_DISABLED)
44 #define MBP_SIMD_OVERLAP
45#endif
46
47#ifdef MBP_USE_WORDS
48 typedef PxU16 MBP_Index;
49#else
50 typedef PxU32 MBP_Index;
51#endif
52 typedef PxU32 MBP_ObjectIndex; // PT: index in mMBP_Objects
53 typedef PxU32 MBP_Handle; // PT: returned to MBP users, combination of index/flip-flop/static-bit
54
55 struct IAABB : public PxUserAllocated
56 {
57 PX_FORCE_INLINE bool isInside(const IAABB& box) const
58 {
59 if(box.mMinX>mMinX) return false;
60 if(box.mMinY>mMinY) return false;
61 if(box.mMinZ>mMinZ) return false;
62 if(box.mMaxX<mMaxX) return false;
63 if(box.mMaxY<mMaxY) return false;
64 if(box.mMaxZ<mMaxZ) return false;
65 return true;
66 }
67
68 PX_FORCE_INLINE PxIntBool intersects(const IAABB& a) const
69 {
70 if(mMaxX < a.mMinX || a.mMaxX < mMinX
71 || mMaxY < a.mMinY || a.mMaxY < mMinY
72 || mMaxZ < a.mMinZ || a.mMaxZ < mMinZ
73 )
74 return PxIntFalse;
75 return PxIntTrue;
76 }
77
78 PX_FORCE_INLINE PxIntBool intersectNoTouch(const IAABB& a) const
79 {
80 if(mMaxX <= a.mMinX || a.mMaxX <= mMinX
81 || mMaxY <= a.mMinY || a.mMaxY <= mMinY
82 || mMaxZ <= a.mMinZ || a.mMaxZ <= mMinZ
83 )
84 return PxIntFalse;
85 return PxIntTrue;
86 }
87
88 PX_FORCE_INLINE void initFrom2(const PxBounds3& box)
89 {
90 const PxU32* PX_RESTRICT binary = reinterpret_cast<const PxU32*>(&box.minimum.x);
91 mMinX = encodeFloat(binary[0])>>1;
92 mMinY = encodeFloat(binary[1])>>1;
93 mMinZ = encodeFloat(binary[2])>>1;
94 mMaxX = encodeFloat(binary[3])>>1;
95 mMaxY = encodeFloat(binary[4])>>1;
96 mMaxZ = encodeFloat(binary[5])>>1;
97 }
98
99 PX_FORCE_INLINE void decode(PxBounds3& box) const
100 {
101 PxU32* PX_RESTRICT binary = reinterpret_cast<PxU32*>(&box.minimum.x);
102 binary[0] = decodeFloat(mMinX<<1);
103 binary[1] = decodeFloat(mMinY<<1);
104 binary[2] = decodeFloat(mMinZ<<1);
105 binary[3] = decodeFloat(mMaxX<<1);
106 binary[4] = decodeFloat(mMaxY<<1);
107 binary[5] = decodeFloat(mMaxZ<<1);
108 }
109
110 PX_FORCE_INLINE PxU32 getMin(PxU32 i) const { return (&mMinX)[i]; }
111 PX_FORCE_INLINE PxU32 getMax(PxU32 i) const { return (&mMaxX)[i]; }
112
113 PxU32 mMinX;
114 PxU32 mMinY;
115 PxU32 mMinZ;
116 PxU32 mMaxX;
117 PxU32 mMaxY;
118 PxU32 mMaxZ;
119 };
120
122 {
123 PX_FORCE_INLINE void initFrom(const PxBounds3& box)
124 {
125 const PxU32* PX_RESTRICT binary = reinterpret_cast<const PxU32*>(&box.minimum.x);
126 mMinX = encodeFloat(binary[0]);
127 mMinY = encodeFloat(binary[1]);
128 mMinZ = encodeFloat(binary[2]);
129 mMaxX = encodeFloat(binary[3]);
130 mMaxY = encodeFloat(binary[4]);
131 mMaxZ = encodeFloat(binary[5]);
132 }
133
134 PX_FORCE_INLINE void initFrom2(const PxBounds3& box)
135 {
136 const PxU32* PX_RESTRICT binary = reinterpret_cast<const PxU32*>(&box.minimum.x);
137 mMinX = encodeFloat(binary[0])>>1;
138 mMinY = encodeFloat(binary[1])>>1;
139 mMinZ = encodeFloat(binary[2])>>1;
140 mMaxX = encodeFloat(binary[3])>>1;
141 mMaxY = encodeFloat(binary[4])>>1;
142 mMaxZ = encodeFloat(binary[5])>>1;
143 }
144
145 PX_FORCE_INLINE void decode(PxBounds3& box) const
146 {
147 PxU32* PX_RESTRICT binary = reinterpret_cast<PxU32*>(&box.minimum.x);
148 binary[0] = decodeFloat(mMinX<<1);
149 binary[1] = decodeFloat(mMinY<<1);
150 binary[2] = decodeFloat(mMinZ<<1);
151 binary[3] = decodeFloat(mMaxX<<1);
152 binary[4] = decodeFloat(mMaxY<<1);
153 binary[5] = decodeFloat(mMaxZ<<1);
154 }
155
156 PX_FORCE_INLINE bool isInside(const SIMD_AABB& box) const
157 {
158 if(box.mMinX>mMinX) return false;
159 if(box.mMinY>mMinY) return false;
160 if(box.mMinZ>mMinZ) return false;
161 if(box.mMaxX<mMaxX) return false;
162 if(box.mMaxY<mMaxY) return false;
163 if(box.mMaxZ<mMaxZ) return false;
164 return true;
165 }
166
167 PX_FORCE_INLINE PxIntBool intersects(const SIMD_AABB& a) const
168 {
169 if(mMaxX < a.mMinX || a.mMaxX < mMinX
170 || mMaxY < a.mMinY || a.mMaxY < mMinY
171 || mMaxZ < a.mMinZ || a.mMaxZ < mMinZ
172 )
173 return PxIntFalse;
174 return PxIntTrue;
175 }
176
177 PX_FORCE_INLINE PxIntBool intersectNoTouch(const SIMD_AABB& a) const
178 {
179 if(mMaxX <= a.mMinX || a.mMaxX <= mMinX
180 || mMaxY <= a.mMinY || a.mMaxY <= mMinY
181 || mMaxZ <= a.mMinZ || a.mMaxZ <= mMinZ
182 )
183 return PxIntFalse;
184 return PxIntTrue;
185 }
186
187 PxU32 mMinX;
188 PxU32 mMaxX;
189 PxU32 mMinY;
190 PxU32 mMinZ;
191 PxU32 mMaxY;
192 PxU32 mMaxZ;
193 };
194
195}
196} // namespace physx
197
198#endif // BP_BROADPHASE_MBP_COMMON_H
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Definition PxUserAllocated.h:43
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition BpBroadPhaseMBPCommon.h:56
Definition BpBroadPhaseMBPCommon.h:122