RavEngine
Loading...
Searching...
No Matches
GuVecTetrahedron.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_TETRAHEDRON_H
30#define GU_VEC_TETRAHEDRON_H
35#include "GuVecConvex.h"
36#include "GuConvexSupportTable.h"
37#include "GuDistancePointTriangleSIMD.h"
38
39namespace physx
40{
41 namespace Gu
42 {
43
44
45 class TetrahedronV : public ConvexV
46 {
47 public:
52 {
53 margin = 0.02f;
54 minMargin = PX_MAX_REAL;
55 sweepMargin = PX_MAX_REAL;
56 }
66 PX_FORCE_INLINE TetrahedronV(const aos::Vec3VArg p0, const aos::Vec3VArg p1, const aos::Vec3VArg p2,
67 const aos::Vec3VArg p3) : ConvexV(ConvexType::eTETRAHEDRON)
68 {
69 using namespace aos;
70 //const FloatV zero = FZero();
71 const FloatV num = FLoad(0.25f);
72 center = V3Scale(V3Add(V3Add(p0, p1), V3Add(p2, p3)), num);
73 //vertsX store all the x elements form those four point
74 vertsX = V4SetW(V4SetZ(V4SetY(Vec4V_From_Vec3V(p0), V3GetX(p1)), V3GetX(p2)), V3GetX(p3));
75 //vertsY store all the y elements from those four point
76 vertsY = V4SetW(V4SetZ(V4SetY(V4Splat(V3GetY(p0)), V3GetY(p1)), V3GetY(p2)), V3GetY(p3));
77 //vertsZ store all the z elements from those four point
78 vertsZ = V4SetW(V4SetZ(V4SetY(V4Splat(V3GetZ(p0)), V3GetZ(p1)), V3GetZ(p2)), V3GetZ(p3));
79
80 verts[0] = p0; verts[1] = p1; verts[2] = p2; verts[3] = p3;
81 margin = 0.f;
82 minMargin = PX_MAX_REAL;
83 sweepMargin = PX_MAX_REAL;
84 }
85
86 PX_FORCE_INLINE TetrahedronV(const PxVec3* pts) : ConvexV(ConvexType::eTETRAHEDRON)
87 {
88 using namespace aos;
89 const Vec3V p0 = V3LoadU(pts[0]);
90 const Vec3V p1 = V3LoadU(pts[1]);
91 const Vec3V p2 = V3LoadU(pts[2]);
92 const Vec3V p3 = V3LoadU(pts[3]);
93 const FloatV num = FLoad(0.25f);
94 center = V3Scale(V3Add(V3Add(p0, p1), V3Add(p2, p3)), num);
95
96 vertsX = V4SetW(V4SetZ(V4SetY(Vec4V_From_Vec3V(p0), V3GetX(p1)), V3GetX(p2)), V3GetX(p3));
97 vertsY = V4SetW(V4SetZ(V4SetY(V4Splat(V3GetY(p0)), V3GetY(p1)), V3GetY(p2)), V3GetY(p3));
98 vertsZ = V4SetW(V4SetZ(V4SetY(V4Splat(V3GetZ(p0)), V3GetZ(p1)), V3GetZ(p2)), V3GetZ(p3));
99
100 verts[0] = p0; verts[1] = p1; verts[2] = p2; verts[3] = p3;
101 margin = 0.f;
102 minMargin = PX_MAX_REAL;
103 sweepMargin = PX_MAX_REAL;
104 }
105
112 {
113 using namespace aos;
114 vertsX = tetrahedron.vertsX;
115 vertsY = tetrahedron.vertsY;
116 vertsZ = tetrahedron.vertsZ;
117
118 verts[0] = tetrahedron.verts[0];
119 verts[1] = tetrahedron.verts[1];
120 verts[2] = tetrahedron.verts[2];
121 verts[3] = tetrahedron.verts[3];
122
123 center = tetrahedron.center;
124 margin = 0.f;
125 minMargin = PX_MAX_REAL;
126 sweepMargin = PX_MAX_REAL;
127 }
134
135
136 PX_FORCE_INLINE aos::FloatV getSweepMargin() const
137 {
138 return aos::FMax();
139 }
140
141 PX_FORCE_INLINE void setCenter(const aos::Vec3VArg _center)
142 {
143 using namespace aos;
144 Vec3V offset = V3Sub(_center, center);
145 center = _center;
146 vertsX = V4Add(vertsX, V4Splat(V3GetX(offset)));
147 vertsY = V4Add(vertsY, V4Splat(V3GetY(offset)));
148 vertsZ = V4Add(vertsZ, V4Splat(V3GetZ(offset)));
149
150 verts[0] = V3Add(verts[0], offset);
151 verts[1] = V3Add(verts[1], offset);
152 verts[2] = V3Add(verts[2], offset);
153 verts[3] = V3Add(verts[3], offset);
154 }
155
156 PX_FORCE_INLINE aos::Vec4V getProjection(const aos::Vec3VArg dir) const
157 {
158 using namespace aos;
159
160 const Vec4V dx = V4Scale(vertsX, V3GetX(dir));
161 const Vec4V dy = V4Scale(vertsY, V3GetY(dir));
162 const Vec4V dz = V4Scale(vertsZ, V3GetZ(dir));
163
164 return V4Add(dx, V4Add(dy, dz));
165 }
166
167 //dir is in local space, verts in the local space
168 PX_FORCE_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir) const
169 {
170 using namespace aos;
171
172 const Vec4V d = getProjection(dir);
173
174 const FloatV d0 = V4GetX(d);
175 const FloatV d1 = V4GetY(d);
176 const FloatV d2 = V4GetZ(d);
177 const FloatV d3 = V4GetW(d);
178
179 const BoolV con0 = BAnd(BAnd(FIsGrtr(d0, d1), FIsGrtr(d0, d2)), FIsGrtr(d0, d3));
180 const BoolV con1 = BAnd(FIsGrtr(d1, d2), FIsGrtr(d1, d3));
181 const BoolV con2 = FIsGrtr(d2, d3);
182 return V3Sel(con0, verts[0], V3Sel(con1, verts[1], V3Sel(con2, verts[2], verts[3])));
183 }
184
185
186 //dir is in b space
187 PX_FORCE_INLINE aos::Vec3V supportRelative(const aos::Vec3VArg dir, const aos::PxMatTransformV& aToB, const aos::PxMatTransformV& aTobT) const
188 {
189 using namespace aos;
190 //verts are in local space
191 // const Vec3V _dir = aToB.rotateInv(dir); //transform dir back to a space
192 const Vec3V _dir = aTobT.rotate(dir); //transform dir back to a space
193 const Vec3V maxPoint = supportLocal(_dir);
194 return aToB.transform(maxPoint);//transform maxPoint to the b space
195 }
196
197 PX_FORCE_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir, PxI32& index) const
198 {
199
200 using namespace aos;
201
202 const Vec4V d = getProjection(dir);
203 const FloatV d0 = V4GetX(d);
204 const FloatV d1 = V4GetY(d);
205 const FloatV d2 = V4GetZ(d);
206 const FloatV d3 = V4GetW(d);
207
208 const BoolV con0 = BAnd(BAnd(FIsGrtr(d0, d1), FIsGrtr(d0, d2)), FIsGrtr(d0, d3));
209 const BoolV con1 = BAnd(FIsGrtr(d1, d2), FIsGrtr(d1, d3));
210 const BoolV con2 = FIsGrtr(d2, d3);
211
212
213 const VecI32V vIndex = VecI32V_Sel(con0, I4Load(0), VecI32V_Sel(con1, I4Load(1), VecI32V_Sel(con2, I4Load(2), I4Load(3))));
214 PxI32_From_VecI32V(vIndex, &index);
215
216 //return V3Sel(con0, v0, V3Sel(con1, v1, v2));
217 return verts[index];
218 }
219
220 PX_FORCE_INLINE aos::Vec3V supportRelative(const aos::Vec3VArg dir, const aos::PxMatTransformV& aToB,
221 const aos::PxMatTransformV& aTobT, PxI32& index)const
222 {
223 //don't put margin in the triangle
224 using namespace aos;
225 //transfer dir into the local space of triangle
226 // const Vec3V _dir = aToB.rotateInv(dir);
227 const Vec3V _dir = aTobT.rotate(dir);
228 return aToB.transform(supportLocal(_dir, index));//transform the support poin to b space
229 }
230
231 PX_FORCE_INLINE aos::Vec3V supportPoint(const PxI32 index)const
232 {
233 return verts[index];
234 }
235
240 aos::Vec4V vertsX;
241 aos::Vec4V vertsY;
242 aos::Vec4V vertsZ;
243 };
244 }
245
246}
247
248#endif
Definition GuVecConvex.h:58
Definition GuVecTetrahedron.h:46
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
PX_FORCE_INLINE TetrahedronV(const Gu::TetrahedronV &tetrahedron)
Copy constructor.
Definition GuVecTetrahedron.h:111
PX_FORCE_INLINE TetrahedronV(const aos::Vec3VArg p0, const aos::Vec3VArg p1, const aos::Vec3VArg p2, const aos::Vec3VArg p3)
Constructor.
Definition GuVecTetrahedron.h:66
aos::Vec3V verts[4]
Array of Vertices.
Definition GuVecTetrahedron.h:239
PX_FORCE_INLINE ~TetrahedronV()
Destructor.
Definition GuVecTetrahedron.h:131
PX_FORCE_INLINE TetrahedronV()
Constructor.
Definition GuVecTetrahedron.h:51
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
Definition PxVecMathAoSScalar.h:65