RavEngine
Loading...
Searching...
No Matches
GuVecTriangle.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_TRIANGLE_H
30#define GU_VEC_TRIANGLE_H
35#include "GuVecConvex.h"
36#include "GuConvexSupportTable.h"
37#include "GuDistancePointTriangleSIMD.h"
38
39namespace physx
40{
41namespace Gu
42{
43
44
45 class TriangleV : public ConvexV
46 {
47 public:
52 {
53 margin = 0.02f;
54 minMargin = PX_MAX_REAL;
55 sweepMargin = PX_MAX_REAL;
56 }
65 PX_FORCE_INLINE TriangleV(const aos::Vec3VArg p0, const aos::Vec3VArg p1, const aos::Vec3VArg p2): ConvexV(ConvexType::eTRIANGLE)
66 {
67 using namespace aos;
68 //const FloatV zero = FZero();
69 const FloatV num = FLoad(0.333333f);
70 center = V3Scale(V3Add(V3Add(p0, p1), p2), num);
71 verts[0] = p0;
72 verts[1] = p1;
73 verts[2] = p2;
74 margin = 0.f;
75 minMargin = PX_MAX_REAL;
76 sweepMargin = PX_MAX_REAL;
77 }
78
79 PX_FORCE_INLINE TriangleV(const PxVec3* pts) : ConvexV(ConvexType::eTRIANGLE)
80 {
81 using namespace aos;
82 const Vec3V p0 = V3LoadU(pts[0]);
83 const Vec3V p1 = V3LoadU(pts[1]);
84 const Vec3V p2 = V3LoadU(pts[2]);
85 const FloatV num = FLoad(0.333333f);
86 center = V3Scale(V3Add(V3Add(p0, p1), p2), num);
87 verts[0] = p0;
88 verts[1] = p1;
89 verts[2] = p2;
90 margin = 0.f;
91 minMargin = PX_MAX_REAL;
92 sweepMargin = PX_MAX_REAL;
93 }
94
101 {
102 using namespace aos;
103 verts[0] = triangle.verts[0];
104 verts[1] = triangle.verts[1];
105 verts[2] = triangle.verts[2];
106
107 center = triangle.center;
108 margin = 0.f;
109 minMargin = PX_MAX_REAL;
110 sweepMargin = PX_MAX_REAL;
111 }
118
119 PX_FORCE_INLINE void populateVerts(const PxU8* inds, PxU32 numInds, const PxVec3* originalVerts, aos::Vec3V* vertexs)const
120 {
121 using namespace aos;
122
123 for(PxU32 i=0; i<numInds; ++i)
124 {
125 vertexs[i] = V3LoadU(originalVerts[inds[i]]);
126 }
127 }
128
129 PX_FORCE_INLINE aos::FloatV getSweepMargin() const
130 {
131 return aos::FMax();
132 }
133
134 PX_FORCE_INLINE void setCenter(const aos::Vec3VArg _center)
135 {
136 using namespace aos;
137 Vec3V offset = V3Sub(_center, center);
138 center = _center;
139 verts[0] = V3Add(verts[0], offset);
140 verts[1] = V3Add(verts[1], offset);
141 verts[2] = V3Add(verts[2], offset);
142 }
143
150 {
151 using namespace aos;
152 const Vec3V ab = V3Sub(verts[1], verts[0]);
153 const Vec3V ac = V3Sub(verts[2], verts[0]);
154 const Vec3V n = V3Cross(ab, ac);
155 return V3Normalize(n);
156 }
157
164 {
165 using namespace aos;
166 const Vec3V ab = V3Sub(verts[1], verts[0]);
167 const Vec3V ac = V3Sub(verts[2], verts[0]);
168 _normal = V3Cross(ab, ac);
169 }
170
171 PX_FORCE_INLINE aos::FloatV area() const
172 {
173 using namespace aos;
174 const FloatV half = FLoad(0.5f);
175 const Vec3V ba = V3Sub(verts[0], verts[1]);
176 const Vec3V ca = V3Sub(verts[0], verts[2]);
177 const Vec3V v = V3Cross(ba, ca);
178 return FMul(V3Length(v), half);
179 }
180
181 //dir is in local space, verts in the local space
182 PX_FORCE_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir) const
183 {
184 using namespace aos;
185 const Vec3V v0 = verts[0];
186 const Vec3V v1 = verts[1];
187 const Vec3V v2 = verts[2];
188 const FloatV d0 = V3Dot(v0, dir);
189 const FloatV d1 = V3Dot(v1, dir);
190 const FloatV d2 = V3Dot(v2, dir);
191
192 const BoolV con0 = BAnd(FIsGrtr(d0, d1), FIsGrtr(d0, d2));
193 const BoolV con1 = FIsGrtr(d1, d2);
194 return V3Sel(con0, v0, V3Sel(con1, v1, v2));
195 }
196
197 PX_FORCE_INLINE void supportLocal(const aos::Vec3VArg dir, aos::FloatV& min, aos::FloatV& max) const
198 {
199 using namespace aos;
200 const Vec3V v0 = verts[0];
201 const Vec3V v1 = verts[1];
202 const Vec3V v2 = verts[2];
203 FloatV d0 = V3Dot(v0, dir);
204 FloatV d1 = V3Dot(v1, dir);
205 FloatV d2 = V3Dot(v2, dir);
206
207 max = FMax(d0, FMax(d1, d2));
208 min = FMin(d0, FMin(d1, d2));
209 }
210
211 //dir is in b space
212 PX_FORCE_INLINE aos::Vec3V supportRelative(const aos::Vec3VArg dir, const aos::PxMatTransformV& aToB, const aos::PxMatTransformV& aTobT) const
213 {
214 using namespace aos;
215 //verts are in local space
216// const Vec3V _dir = aToB.rotateInv(dir); //transform dir back to a space
217 const Vec3V _dir = aTobT.rotate(dir); //transform dir back to a space
218 const Vec3V maxPoint = supportLocal(_dir);
219 return aToB.transform(maxPoint);//transform maxPoint to the b space
220 }
221
222 PX_FORCE_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir, PxI32& index) const
223 {
224
225 using namespace aos;
226 const VecI32V vZero = VecI32V_Zero();
227 const VecI32V vOne = VecI32V_One();
228 const VecI32V vTwo = VecI32V_Two();
229 const Vec3V v0 = verts[0];
230 const Vec3V v1 = verts[1];
231 const Vec3V v2 = verts[2];
232 const FloatV d0 = V3Dot(v0, dir);
233 const FloatV d1 = V3Dot(v1, dir);
234 const FloatV d2 = V3Dot(v2, dir);
235 const BoolV con0 = BAnd(FIsGrtr(d0, d1), FIsGrtr(d0, d2));
236 const BoolV con1 = FIsGrtr(d1, d2);
237 const VecI32V vIndex = VecI32V_Sel(con0, vZero, VecI32V_Sel(con1, vOne, vTwo));
238 PxI32_From_VecI32V(vIndex, &index);
239 return V3Sel(con0, v0, V3Sel(con1, v1, v2));
240 }
241
242 PX_FORCE_INLINE aos::Vec3V supportRelative( const aos::Vec3VArg dir, const aos::PxMatTransformV& aToB,
243 const aos::PxMatTransformV& aTobT, PxI32& index)const
244 {
245 //don't put margin in the triangle
246 using namespace aos;
247 //transfer dir into the local space of triangle
248// const Vec3V _dir = aToB.rotateInv(dir);
249 const Vec3V _dir = aTobT.rotate(dir);
250 return aToB.transform(supportLocal(_dir, index));//transform the support poin to b space
251 }
252
253 PX_FORCE_INLINE aos::Vec3V supportPoint(const PxI32 index)const
254 {
255 return verts[index];
256 }
257
262 };
263}
264
265}
266
267#endif
Definition GuVecConvex.h:58
Definition GuVecTriangle.h:46
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
PX_FORCE_INLINE void denormalizedNormal(aos::Vec3V &_normal) const
Compute the unnormalized normal of the Triangle.
Definition GuVecTriangle.h:163
PX_FORCE_INLINE ~TriangleV()
Destructor.
Definition GuVecTriangle.h:115
aos::Vec3V verts[3]
Array of Vertices.
Definition GuVecTriangle.h:261
PX_FORCE_INLINE TriangleV(const Gu::TriangleV &triangle)
Copy constructor.
Definition GuVecTriangle.h:100
PX_FORCE_INLINE TriangleV()
Constructor.
Definition GuVecTriangle.h:51
PX_FORCE_INLINE TriangleV(const aos::Vec3VArg p0, const aos::Vec3VArg p1, const aos::Vec3VArg p2)
Constructor.
Definition GuVecTriangle.h:65
PX_FORCE_INLINE aos::Vec3V normal() const
Compute the normal of the Triangle.
Definition GuVecTriangle.h:149
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