RavEngine
Loading...
Searching...
No Matches
GuVecConvexHullNoScale.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_CONVEXHULL_NOSCALE_H
30#define GU_VEC_CONVEXHULL_NOSCALE_H
31
32#include "foundation/PxUnionCast.h"
33#include "common/PxPhysXCommonConfig.h"
34#include "GuVecConvexHull.h"
35
36namespace physx
37{
38namespace Gu
39{
41 {
42 public:
46 PX_SUPPORT_INLINE ConvexHullNoScaleV(): ConvexHullV()
47 {
48 }
49
50 PX_FORCE_INLINE aos::Vec3V supportPoint(const PxI32 index)const
51 {
52 using namespace aos;
53 return V3LoadU_SafeReadW(verts[index]); // PT: safe because of the way vertex memory is allocated in ConvexHullData (and 'verts' is initialized with ConvexHullData::getHullVertices())
54 }
55
56 //This funcation is just to load the PxVec3 to Vec3V. However, for GuVecConvexHul.h, this is used to transform all the verts from vertex space to shape space
57 PX_SUPPORT_INLINE void populateVerts(const PxU8* inds, PxU32 numInds, const PxVec3* originalVerts, aos::Vec3V* verts_)const
58 {
59 using namespace aos;
60
61 for(PxU32 i=0; i<numInds; ++i)
62 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)
63 }
64
65 //This function is used in epa
66 //dir is in the shape space
67 PX_SUPPORT_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir)const
68 {
69 using namespace aos;
70 const PxU32 maxIndex = supportVertexIndex(dir);
71 return V3LoadU_SafeReadW(verts[maxIndex]); // PT: safe because of the way vertex memory is allocated in ConvexHullData (and 'verts' is initialized with ConvexHullData::getHullVertices())
72 }
73
74 //this is used in the sat test for the full contact gen
75 PX_SUPPORT_INLINE void supportLocal(const aos::Vec3VArg dir, aos::FloatV& min, aos::FloatV& max)const
76 {
77 supportVertexMinMax(dir, min, max);
78 }
79
80 //This function is used in epa
81 PX_SUPPORT_INLINE aos::Vec3V supportRelative(const aos::Vec3VArg dir, const aos::PxMatTransformV& aTob, const aos::PxMatTransformV& aTobT) const
82 {
83 using namespace aos;
84
85 //transform dir into the shape space
86 const Vec3V _dir = aTobT.rotate(dir);//relTra.rotateInv(dir);
87 const Vec3V maxPoint = supportLocal(_dir);
88 //translate maxPoint from shape space of a back to the b space
89 return aTob.transform(maxPoint);//relTra.transform(maxPoint);
90 }
91
92 //dir in the shape space, this function is used in gjk
93 PX_SUPPORT_INLINE aos::Vec3V supportLocal(const aos::Vec3VArg dir, PxI32& index)const
94 {
95 using namespace aos;
96 //scale dir and put it in the vertex space, for non-uniform scale, we don't want the scale in the dir, therefore, we are using
97 //the transpose of the inverse of shape2Vertex(which is vertex2shape). This will allow us igore the scale and keep the rotation
98 //get the extreme point index
99 const PxU32 maxIndex = supportVertexIndex(dir);
100 index = PxI32(maxIndex);
101 return V3LoadU_SafeReadW(verts[index]); // PT: safe because of the way vertex memory is allocated in ConvexHullData (and 'verts' is initialized with ConvexHullData::getHullVertices())
102 }
103
104 //this function is used in gjk
105 PX_SUPPORT_INLINE aos::Vec3V supportRelative( const aos::Vec3VArg dir, const aos::PxMatTransformV& aTob,
106 const aos::PxMatTransformV& aTobT, PxI32& index)const
107 {
108 using namespace aos;
109
110 //transform dir from b space to the shape space of a space
111 const Vec3V _dir = aTobT.rotate(dir);//relTra.rotateInv(dir);//M33MulV3(skewInvRot, dir);
112 const Vec3V p = supportLocal(_dir, index);
113 //transfrom from a to b space
114 return aTob.transform(p);
115 }
116
117 PX_SUPPORT_INLINE void bruteForceSearchMinMax(const aos::Vec3VArg _dir, aos::FloatV& min, aos::FloatV& max)const
118 {
119 using namespace aos;
120 //brute force
121 //get the support point from the orignal margin
122 FloatV _max = V3Dot(V3LoadU_SafeReadW(verts[0]), _dir); // PT: safe because of the way vertex memory is allocated in ConvexHullData (and 'verts' is initialized with ConvexHullData::getHullVertices())
123 FloatV _min = _max;
124
125 for(PxU32 i = 1; i < numVerts; ++i)
126 {
127 PxPrefetchLine(&verts[i], 128);
128 const Vec3V vertex = V3LoadU_SafeReadW(verts[i]); // PT: safe because of the way vertex memory is allocated in ConvexHullData (and 'verts' is initialized with ConvexHullData::getHullVertices())
129 const FloatV dist = V3Dot(vertex, _dir);
130
131 _max = FMax(dist, _max);
132 _min = FMin(dist, _min);
133 }
134
135 min = _min;
136 max = _max;
137 }
138
139 //This function support no scaling, dir is in the shape space(the same as vertex space)
140 PX_SUPPORT_INLINE void supportVertexMinMax(const aos::Vec3VArg dir, aos::FloatV& min, aos::FloatV& max)const
141 {
142 using namespace aos;
143
144 if(data)
145 {
146 const PxU32 maxIndex= hillClimbing(dir);
147 const PxU32 minIndex= hillClimbing(V3Neg(dir));
148 const Vec3V maxPoint= V3LoadU_SafeReadW(verts[maxIndex]); // PT: safe because of the way vertex memory is allocated in ConvexHullData (and 'verts' is initialized with ConvexHullData::getHullVertices())
149 const Vec3V minPoint= V3LoadU_SafeReadW(verts[minIndex]); // PT: safe because of the way vertex memory is allocated in ConvexHullData (and 'verts' is initialized with ConvexHullData::getHullVertices())
150 min = V3Dot(dir, minPoint);
151 max = V3Dot(dir, maxPoint);
152 }
153 else
154 {
155 bruteForceSearchMinMax(dir, min, max);
156 }
157 }
158 };
159
160 #define PX_CONVEX_TO_NOSCALECONVEX(x) (static_cast<const ConvexHullNoScaleV*>(x))
161}
162
163}
164
165#endif //
Definition GuVecConvexHullNoScale.h:41
PX_SUPPORT_INLINE ConvexHullNoScaleV()
Constructor.
Definition GuVecConvexHullNoScale.h:46
Definition GuVecConvexHull.h:184
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_FORCE_INLINE void PxPrefetchLine(const void *ptr, uint32_t offset=0)
Definition PxUnixIntrinsics.h:83
Definition PxVecMathAoSScalar.h:77