RavEngine
Loading...
Searching...
No Matches
GuVecCapsule.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_CAPSULE_H
30#define GU_VEC_CAPSULE_H
31
36#include "geometry/PxCapsuleGeometry.h"
37#include "GuVecConvex.h"
38#include "GuConvexSupportTable.h"
39
40namespace physx
41{
42namespace Gu
43{
44
45 PX_FORCE_INLINE aos::FloatV CalculateCapsuleMinMargin(const aos::FloatVArg radius)
46 {
47 using namespace aos;
48 const FloatV ratio = aos::FLoad(0.05f);
49 return FMul(radius, ratio);
50 }
51
52 class CapsuleV : public ConvexV
53 {
54 public:
60 {
61 bMarginIsRadius = true;
62 }
63
64 //constructor for sphere
65 PX_INLINE CapsuleV(const aos::Vec3VArg p, const aos::FloatVArg radius_) : ConvexV(ConvexType::eCAPSULE)
66 {
67 using namespace aos;
68 center = p;
69 radius = radius_;
70 p0 = p;
71 p1 = p;
72 FStore(radius, &margin);
73 FStore(radius, &minMargin);
74 FStore(radius, &sweepMargin);
75 bMarginIsRadius = true;
76 }
77
78 PX_INLINE CapsuleV(const aos::Vec3VArg center_, const aos::Vec3VArg v_, const aos::FloatVArg radius_) :
79 ConvexV(ConvexType::eCAPSULE, center_)
80 {
81 using namespace aos;
82 radius = radius_;
83 p0 = V3Add(center_, v_);
84 p1 = V3Sub(center_, v_);
85 FStore(radius, &margin);
86 FStore(radius, &minMargin);
87 FStore(radius, &sweepMargin);
88 bMarginIsRadius = true;
89 }
90
91 PX_INLINE CapsuleV(const PxGeometry& geom) : ConvexV(ConvexType::eCAPSULE, aos::V3Zero())
92 {
93 using namespace aos;
94 const PxCapsuleGeometry& capsuleGeom = static_cast<const PxCapsuleGeometry&>(geom);
95
96 const Vec3V axis = V3Scale(V3UnitX(), FLoad(capsuleGeom.halfHeight));
97 const FloatV r = FLoad(capsuleGeom.radius);
98 p0 = axis;
99 p1 = V3Neg(axis);
100 radius = r;
101 FStore(radius, &margin);
102 FStore(radius, &minMargin);
103 FStore(radius, &sweepMargin);
104 bMarginIsRadius = true;
105 }
106
117 {
118 }
119
120 PX_FORCE_INLINE void initialize(const aos::Vec3VArg _p0, const aos::Vec3VArg _p1, const aos::FloatVArg _radius)
121 {
122 using namespace aos;
123 radius = _radius;
124 p0 = _p0;
125 p1 = _p1;
126 FStore(radius, &margin);
127 FStore(radius, &minMargin);
128 FStore(radius, &sweepMargin);
129 center = V3Scale(V3Add(_p0, _p1), FHalf());
130 }
131
132 PX_INLINE aos::Vec3V computeDirection() const
133 {
134 return aos::V3Sub(p1, p0);
135 }
136
137 PX_FORCE_INLINE aos::FloatV getRadius() const
138 {
139 return radius;
140 }
141
142 PX_FORCE_INLINE aos::Vec3V supportPoint(const PxI32 index)const
143 {
144 return (&p0)[1-index];
145 }
146
147 PX_FORCE_INLINE void getIndex(const aos::BoolV con, PxI32& index)const
148 {
149 using namespace aos;
150 const VecI32V v = VecI32V_From_BoolV(con);
151 const VecI32V t = VecI32V_And(v, VecI32V_One());
152 PxI32_From_VecI32V(t, &index);
153 }
154
155 PX_FORCE_INLINE void setCenter(const aos::Vec3VArg _center)
156 {
157 using namespace aos;
158 Vec3V offset = V3Sub(_center, center);
159 center = _center;
160
161 p0 = V3Add(p0, offset);
162 p1 = V3Add(p1, offset);
163 }
164
165 //dir, p0 and p1 are in the local space of dir
166 PX_FORCE_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir)const
167 {
168 using namespace aos;
169 //const Vec3V _dir = V3Normalize(dir);
170 const FloatV dist0 = V3Dot(p0, dir);
171 const FloatV dist1 = V3Dot(p1, dir);
172 return V3Sel(FIsGrtr(dist0, dist1), p0, p1);
173 }
174
175 PX_FORCE_INLINE aos::Vec3V supportRelative(const aos::Vec3VArg dir, const aos::PxMatTransformV& aToB, const aos::PxMatTransformV& aTobT) const
176 {
177 using namespace aos;
178 //transform dir into the local space of a
179// const Vec3V _dir = aToB.rotateInv(dir);
180 const Vec3V _dir = aTobT.rotate(dir);
181 const Vec3V p = supportLocal(_dir);
182 //transform p back to the local space of b
183 return aToB.transform(p);
184 }
185
186 //dir, p0 and p1 are in the local space of dir
187 PX_FORCE_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir, PxI32& index)const
188 {
189 using namespace aos;
190
191 const FloatV dist0 = V3Dot(p0, dir);
192 const FloatV dist1 = V3Dot(p1, dir);
193 const BoolV comp = FIsGrtr(dist0, dist1);
194 getIndex(comp, index);
195 return V3Sel(comp, p0, p1);
196 }
197
198 PX_FORCE_INLINE aos::Vec3V supportRelative( const aos::Vec3VArg dir, const aos::PxMatTransformV& aToB,
199 const aos::PxMatTransformV& aTobT, PxI32& index)const
200 {
201 using namespace aos;
202 //transform dir into the local space of a
203// const Vec3V _dir = aToB.rotateInv(dir);
204 const Vec3V _dir = aTobT.rotate(dir);
205
206 const Vec3V p = supportLocal(_dir, index);
207 //transform p back to the local space of b
208 return aToB.transform(p);
209 }
210
211
212 PX_FORCE_INLINE aos::Vec3V supportLocal(aos::Vec3V& support, const PxI32& index, const aos::BoolV comp)const
213 {
214 PX_UNUSED(index);
215
216 using namespace aos;
217 const Vec3V p = V3Sel(comp, p0, p1);
218 support = p;
219 return p;
220 }
221
222 PX_FORCE_INLINE aos::FloatV getSweepMargin() const
223 {
224 return aos::FZero();
225 }
226
227 //don't change the order of p0 and p1, the getPoint function depend on the order
230 aos::FloatV radius;
231 };
232}
233
234}
235
236#endif
Definition GuVecCapsule.h:53
Definition GuVecConvex.h:58
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
PX_INLINE CapsuleV()
Constructor.
Definition GuVecCapsule.h:59
PX_INLINE ~CapsuleV()
Constructor.
Definition GuVecCapsule.h:116
aos::Vec3V p0
Start of segment.
Definition GuVecCapsule.h:228
aos::Vec3V p1
End of segment.
Definition GuVecCapsule.h:229
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition GuVecConvex.h:43
Definition PxVecMathAoSScalar.h:52
Definition PxVecMathAoSScalar.h:77