RavEngine
Loading...
Searching...
No Matches
GuVecBox.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 GU_VEC_BOX_H
30#define GU_VEC_BOX_H
31
35#include "foundation/PxTransform.h"
36#include "common/PxPhysXCommonConfig.h"
37#include "geometry/PxBoxGeometry.h"
38#include "foundation/PxVecTransform.h"
39#include "GuVecConvex.h"
40#include "GuConvexSupportTable.h"
41
42namespace physx
43{
44PX_PHYSX_COMMON_API extern const aos::BoolV boxVertexTable[8];
45
46namespace Gu
47{
48
49#define BOX_MARGIN_RATIO 0.15f
50#define BOX_MIN_MARGIN_RATIO 0.05f
51#define BOX_SWEEP_MARGIN_RATIO 0.05f
52
53#define BOX_MARGIN_CCD_RATIO 0.01f
54#define BOX_MIN_MARGIN_CCD_RATIO 0.005f
55
56
57 class CapsuleV;
58
59
60 PX_FORCE_INLINE void CalculateBoxMargin(const aos::Vec3VArg extent, PxReal& margin, PxReal& minMargin, PxReal& sweepMargin,
61 const PxReal marginR = BOX_MARGIN_RATIO, const PxReal minMarginR = BOX_MIN_MARGIN_RATIO)
62 {
63 using namespace aos;
64
65 PxReal minExtent;
66 const FloatV min = V3ExtractMin(extent);
67 FStore(min, &minExtent);
68
69 margin = minExtent * marginR;
70 minMargin = minExtent * minMarginR;
71 sweepMargin = minExtent * BOX_SWEEP_MARGIN_RATIO;
72 }
73
74 PX_FORCE_INLINE aos::FloatV CalculateBoxTolerance(const aos::Vec3VArg extent)
75 {
76 using namespace aos;
77
78 const FloatV r0 = FLoad(0.01f);
79 const FloatV min = V3ExtractMin(extent);//FMin(V3GetX(extent), FMin(V3GetY(extent), V3GetZ(extent)));
80 return FMul(min, r0);
81 }
82
83 //This method is called in the PCM contact gen for the refreshing contacts
84 PX_FORCE_INLINE aos::FloatV CalculatePCMBoxMargin(const aos::Vec3VArg extent, const PxReal toleranceLength, const PxReal toleranceMarginRatio = BOX_MARGIN_RATIO)
85 {
86 using namespace aos;
87
88 const FloatV min = V3ExtractMin(extent);//FMin(V3GetX(extent), FMin(V3GetY(extent), V3GetZ(extent)));
89 const FloatV toleranceMargin = FLoad(toleranceLength * toleranceMarginRatio);
90 return FMin(FMul(min, FLoad(BOX_MARGIN_RATIO)), toleranceMargin);
91 }
92
93 PX_FORCE_INLINE aos::FloatV CalculateMTDBoxMargin(const aos::Vec3VArg extent)
94 {
95 using namespace aos;
96
97 const FloatV min = V3ExtractMin(extent);//FMin(V3GetX(extent), FMin(V3GetY(extent), V3GetZ(extent)));
98 return FMul(min, FLoad(BOX_MARGIN_RATIO));
99 }
100
101 class BoxV : public ConvexV
102 {
103 public:
104
109 {
110 }
111
112 PX_FORCE_INLINE BoxV(const aos::Vec3VArg origin, const aos::Vec3VArg extent) :
113 ConvexV(ConvexType::eBOX, origin), extents(extent)
114 {
115 CalculateBoxMargin(extent, margin, minMargin, sweepMargin);
116 }
117
118 //this constructor is used by the CCD system
119 PX_FORCE_INLINE BoxV(const PxGeometry& geom) : ConvexV(ConvexType::eBOX, aos::V3Zero())
120 {
121 using namespace aos;
122 const PxBoxGeometry& boxGeom = static_cast<const PxBoxGeometry&>(geom);
123 const Vec3V extent = aos::V3LoadU(boxGeom.halfExtents);
124 extents = extent;
125 CalculateBoxMargin(extent, margin, minMargin, sweepMargin, BOX_MARGIN_CCD_RATIO, BOX_MIN_MARGIN_CCD_RATIO);
126 }
127
132 {
133 }
134
135 PX_FORCE_INLINE void resetMargin(const PxReal toleranceLength)
136 {
137 minMargin = PxMin(toleranceLength * BOX_MIN_MARGIN_RATIO, minMargin);
138 }
139
141 PX_FORCE_INLINE const BoxV& operator=(const BoxV& other)
142 {
143 center = other.center;
144 extents = other.extents;
145 margin = other.margin;
146 minMargin = other.minMargin;
147 sweepMargin = other.sweepMargin;
148 return *this;
149 }
150
151 PX_FORCE_INLINE void populateVerts(const PxU8* inds, PxU32 numInds, const PxVec3* originalVerts, aos::Vec3V* verts)const
152 {
153 using namespace aos;
154
155 for(PxU32 i=0; i<numInds; ++i)
156 verts[i] = V3LoadU_SafeReadW(originalVerts[inds[i]]); // PT: safe because of the way vertex memory is allocated in ConvexHullData (and 'populateVerts' is always called with polyData.mVerts)
157 }
158
159 PX_FORCE_INLINE aos::Vec3V supportPoint(const PxI32 index)const
160 {
161 using namespace aos;
162 const BoolV con = boxVertexTable[index];
163 return V3Sel(con, extents, V3Neg(extents));
164 }
165
166 PX_FORCE_INLINE void getIndex(const aos::BoolV con, PxI32& index)const
167 {
168 using namespace aos;
169 index = PxI32(BGetBitMask(con) & 0x7);
170 }
171
172 PX_FORCE_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir)const
173 {
174 using namespace aos;
175 return V3Sel(V3IsGrtr(dir, V3Zero()), extents, V3Neg(extents));
176 }
177
178 //this is used in the sat test for the full contact gen
179 PX_SUPPORT_INLINE void supportLocal(const aos::Vec3VArg dir, aos::FloatV& min, aos::FloatV& max)const
180 {
181 using namespace aos;
182 const Vec3V point = V3Sel(V3IsGrtr(dir, V3Zero()), extents, V3Neg(extents));
183 max = V3Dot(dir, point);
184 min = FNeg(max);
185 }
186
187 PX_SUPPORT_INLINE aos::Vec3V supportRelative(const aos::Vec3VArg dir, const aos::PxMatTransformV& aTob, const aos::PxMatTransformV& aTobT) const
188 {
189 //a is the current object, b is the other object, dir is in the local space of b
190 using namespace aos;
191// const Vec3V _dir = aTob.rotateInv(dir);//relTra.rotateInv(dir);//from b to a
192 const Vec3V _dir = aTobT.rotate(dir);//relTra.rotateInv(dir);//from b to a
193 const Vec3V p = supportLocal(_dir);
194 //transfer p into the b space
195 return aTob.transform(p);//relTra.transform(p);
196 }
197
198 PX_SUPPORT_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir, PxI32& index)const
199 {
200 using namespace aos;
201 const BoolV comp = V3IsGrtr(dir, V3Zero());
202 getIndex(comp, index);
203 return V3Sel(comp, extents, V3Neg(extents));
204 }
205
206 PX_SUPPORT_INLINE aos::Vec3V supportRelative( const aos::Vec3VArg dir, const aos::PxMatTransformV& aTob,
207 const aos::PxMatTransformV& aTobT, PxI32& index)const
208 {
209 //a is the current object, b is the other object, dir is in the local space of b
210 using namespace aos;
211// const Vec3V _dir = aTob.rotateInv(dir);//relTra.rotateInv(dir);//from b to a
212 const Vec3V _dir = aTobT.rotate(dir);//relTra.rotateInv(dir);//from b to a
213 const Vec3V p = supportLocal(_dir, index);
214 //transfer p into the b space
215 return aTob.transform(p);//relTra.transform(p);
216 }
217
218 aos::Vec3V extents;
219 };
220} //PX_COMPILE_TIME_ASSERT(sizeof(Gu::BoxV) == 96);
221
222}
223
225#endif
Definition GuVecBox.h:102
PX_INLINE ~BoxV()
Destructor.
Definition GuVecBox.h:131
PX_FORCE_INLINE const BoxV & operator=(const BoxV &other)
Assignment operator.
Definition GuVecBox.h:141
PX_INLINE BoxV()
Constructor.
Definition GuVecBox.h:108
Definition GuVecConvex.h:58
Class representing the geometry of a box.
Definition PxBoxGeometry.h:49
PxVec3 halfExtents
Half of the width, height, and depth of the box.
Definition PxBoxGeometry.h:97
A geometry object.
Definition PxGeometry.h:79
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
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 PxMin(T a, T b)
The return value is the lesser of the two specified values.
Definition PxMath.h:88
Definition GuVecConvex.h:43
Definition PxVecMathAoSScalar.h:90
Definition PxVecMathAoSScalar.h:77