RavEngine
Loading...
Searching...
No Matches
GuVecSphere.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_SPHERE_H
30#define GU_VEC_SPHERE_H
35#include "geometry/PxSphereGeometry.h"
36#include "GuVecConvex.h"
37#include "GuConvexSupportTable.h"
38
42namespace physx
43{
44namespace Gu
45{
46 class SphereV : public ConvexV
47 {
48 public:
53 {
54 radius = aos::FZero();
55 bMarginIsRadius = true;
56 }
57
58 PX_INLINE SphereV(const aos::Vec3VArg _center, const aos::FloatV _radius) : ConvexV(ConvexType::eSPHERE, _center)
59 {
60 using namespace aos;
61 radius = _radius;
62 FStore(radius, &margin);
63 FStore(radius, &minMargin);
64 FStore(radius, &sweepMargin);
65 bMarginIsRadius = true;
66 }
67
68
72 PX_INLINE SphereV(const SphereV& sphere) : ConvexV(ConvexType::eSPHERE), radius(sphere.radius)
73 {
74
75 margin = sphere.margin;
76 minMargin = sphere.minMargin;
77 sweepMargin = sphere.sweepMargin;
78 bMarginIsRadius = true;
79 }
80
81 PX_INLINE SphereV(const PxGeometry& geom) : ConvexV(ConvexType::eSPHERE, aos::V3Zero())
82 {
83 using namespace aos;
84 const PxSphereGeometry& sphereGeom = static_cast<const PxSphereGeometry&>(geom);
85 const FloatV r = FLoad(sphereGeom.radius);
86 radius = r;
87 margin = sphereGeom.radius;
88 minMargin = sphereGeom.radius;
89 sweepMargin = sphereGeom.radius;
90 bMarginIsRadius = true;
91 }
92
97 {
98 }
99
100 PX_INLINE void setV(const aos::Vec3VArg _center, const aos::FloatVArg _radius)
101 {
102 center = _center;
103 radius = _radius;
104 }
105
111 PX_INLINE bool isValid() const
112 {
113 // Consistency condition for spheres: Radius >= 0.0f
114 using namespace aos;
115 return BAllEqTTTT(FIsGrtrOrEq(radius, FZero())) != 0;
116 }
117
124 PX_INLINE bool contains(const aos::Vec3VArg p) const
125 {
126 using namespace aos;
127 const FloatV rr = FMul(radius, radius);
128 const FloatV cc = V3LengthSq(V3Sub(center, p));
129 return FAllGrtrOrEq(rr, cc) != 0;
130 }
131
138 PX_INLINE bool contains(const SphereV& sphere) const
139 {
140 using namespace aos;
141
142 const Vec3V centerDif= V3Sub(center, sphere.center);
143 const FloatV radiusDif = FSub(radius, sphere.radius);
144 const FloatV cc = V3Dot(centerDif, centerDif);
145 const FloatV rr = FMul(radiusDif, radiusDif);
146
147 const BoolV con0 = FIsGrtrOrEq(radiusDif, FZero());//might contain
148 const BoolV con1 = FIsGrtr(rr, cc);//return true
149 return BAllEqTTTT(BAnd(con0, con1))==1;
150 }
151
159 PX_INLINE bool contains(const aos::Vec3VArg minimum, const aos::Vec3VArg maximum) const
160 {
161
162 //compute the sphere which wrap around the box
163 using namespace aos;
164 const FloatV zero = FZero();
165 const FloatV half = FHalf();
166
167 const Vec3V boxSphereCenter = V3Scale(V3Add(maximum, minimum), half);
168 const Vec3V v = V3Scale(V3Sub(maximum, minimum), half);
169 const FloatV boxSphereR = V3Length(v);
170
171 const Vec3V w = V3Sub(center, boxSphereCenter);
172 const FloatV wLength = V3Length(w);
173 const FloatV dif = FSub(FSub(radius, wLength), boxSphereR);
174
175 return FAllGrtrOrEq(dif, zero) != 0;
176 }
177
184 PX_INLINE bool intersect(const SphereV& sphere) const
185 {
186 using namespace aos;
187 const Vec3V centerDif = V3Sub(center, sphere.center);
188 const FloatV cc = V3Dot(centerDif, centerDif);
189 const FloatV r = FAdd(radius, sphere.radius);
190 const FloatV rr = FMul(r, r);
191 return FAllGrtrOrEq(rr, cc) != 0;
192 }
193
194 //return point in local space
195 PX_FORCE_INLINE aos::Vec3V getPoint(const PxU8)
196 {
197 return aos::V3Zero();
198 }
199 //
200 //sweep code need to have full version
201 PX_FORCE_INLINE aos::Vec3V supportSweep(const aos::Vec3VArg dir)const
202 {
203 using namespace aos;
204 const Vec3V _dir = V3Normalize(dir);
205 return V3ScaleAdd(_dir, radius, center);
206 }
207
208 //make the support function the same as support margin
209 PX_FORCE_INLINE aos::Vec3V support(const aos::Vec3VArg)const
210 {
211 return center;//_margin is the same as radius
212 }
213
214
215 PX_FORCE_INLINE aos::Vec3V supportMargin(const aos::Vec3VArg dir, const aos::FloatVArg _margin, aos::Vec3V& support)const
216 {
217 PX_UNUSED(_margin);
218 PX_UNUSED(dir);
219
220 support = center;
221 return center;//_margin is the same as radius
222 }
223
224 PX_FORCE_INLINE aos::BoolV isMarginEqRadius()const
225 {
226 return aos::BTTTT();
227 }
228
229 PX_FORCE_INLINE aos::FloatV getSweepMargin() const
230 {
231 return aos::FZero();
232 }
233
234
236
237 };
238}
239
240}
241
242#endif
Definition GuVecConvex.h:58
Definition GuVecSphere.h:47
A geometry object.
Definition PxGeometry.h:79
A class representing the geometry of a sphere.
Definition PxSphereGeometry.h:48
PxReal radius
The radius of the sphere.
Definition PxSphereGeometry.h:88
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
aos::FloatV radius
Sphere's center, w component is radius.
Definition GuVecSphere.h:235
PX_INLINE bool isValid() const
Checks the sphere is valid.
Definition GuVecSphere.h:111
PX_INLINE bool contains(const SphereV &sphere) const
Tests if a sphere is contained within the sphere.
Definition GuVecSphere.h:138
PX_INLINE SphereV()
Constructor.
Definition GuVecSphere.h:52
PX_INLINE bool contains(const aos::Vec3VArg p) const
Tests if a point is contained within the sphere.
Definition GuVecSphere.h:124
PX_INLINE SphereV(const SphereV &sphere)
Copy constructor.
Definition GuVecSphere.h:72
PX_INLINE bool intersect(const SphereV &sphere) const
Tests if the sphere intersects another sphere.
Definition GuVecSphere.h:184
PX_INLINE ~SphereV()
Destructor.
Definition GuVecSphere.h:96
PX_INLINE bool contains(const aos::Vec3VArg minimum, const aos::Vec3VArg maximum) const
Tests if a box is contained within the sphere.
Definition GuVecSphere.h:159
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:90
Definition PxVecMathAoSScalar.h:52
Definition PxVecMathAoSScalar.h:77