32#include "geometry/PxCapsuleGeometry.h"
33#include "geometry/PxBoxGeometry.h"
35#include "foundation/PxTransform.h"
36#include "foundation/PxMathUtils.h"
37#include "foundation/PxUtilities.h"
38#include "foundation/PxMat33.h"
40#define GU_EPSILON_SAME_DISTANCE 1e-3f
57 PxPlane getPlane(
const PxTransform& pose);
59 PX_FORCE_INLINE PxVec3 getCapsuleHalfHeightVector(
const PxTransform& transform,
const PxCapsuleGeometry& capsuleGeom)
61 return transform.q.getBasisVector0() * capsuleGeom.halfHeight;
64 PX_FORCE_INLINE void getCapsuleSegment(
const PxTransform& transform,
const PxCapsuleGeometry& capsuleGeom, Gu::Segment& segment)
66 const PxVec3 tmp = getCapsuleHalfHeightVector(transform, capsuleGeom);
71 PX_FORCE_INLINE void getCapsule(Gu::Capsule& capsule,
const PxCapsuleGeometry& capsuleGeom,
const PxTransform& pose)
73 getCapsuleSegment(pose, capsuleGeom, capsule);
74 capsule.radius = capsuleGeom.radius;
77 void computeSweptBox(Gu::Box& box,
const PxVec3& extents,
const PxVec3& center,
const PxMat33& rot,
const PxVec3& unitDir,
const PxReal distance);
95 return -
PxAbs(triNormal.
dot(unitDir));
111 float bestImpactDistance,
float bestAlignmentValue,
float maxDistance)
114 if(triImpactDistance > maxDistance)
118 if(triImpactDistance == 0.0f)
122 float distEpsilon = GU_EPSILON_SAME_DISTANCE;
125 distEpsilon *=
PxMax(1.0f,
PxMax(triImpactDistance, bestImpactDistance));
128 if(triImpactDistance < bestImpactDistance - distEpsilon)
132 if(triImpactDistance < bestImpactDistance+distEpsilon && triAlignmentValue < bestAlignmentValue)
136 if(triAlignmentValue == bestAlignmentValue && triImpactDistance < bestImpactDistance)
142 PX_FORCE_INLINE bool keepTriangleBasic(
float triImpactDistance,
float bestImpactDistance,
float maxDistance)
145 if(triImpactDistance > maxDistance)
149 if(triImpactDistance == 0.0f)
153 if(triImpactDistance < bestImpactDistance)
161 return PxVec3(0.0f, -b.z, b.y);
165 return PxVec3(b.z, 0.0f, -b.x);
169 return PxVec3(-b.y, b.x, 0.0f);
177 const PxF32 w = 1.0f - u - v;
178 return PxVec3(w * p0.x + u * p1.x + v * p2.x, w * p0.y + u * p1.y + v * p2.y, w * p0.z + u * p1.z + v * p2.z);
183 const PxVec3 u1 = x1 - x0;
184 const PxVec3 u2 = x2 - x0;
185 const PxVec3 u3 = x3 - x0;
187 edgeMatrix =
PxMat33(u1, u2, u3);
191 const PxReal volume = det / 6.0f;
195 PX_FORCE_INLINE PxReal computeTetrahedronVolume(
const PxVec3& x0,
const PxVec3& x1,
const PxVec3& x2,
const PxVec3& x3)
198 return computeTetrahedronVolume(x0, x1, x2, x3, edgeMatrix);
202 template<
typename IndexType>
203 PX_FORCE_INLINE PxReal computeTriangleMeshVolume(
const PxVec3* vertices,
const IndexType* indices,
204 const PxU32 numTriangles)
209 for(PxU32 i = 0; i < numTriangles; ++i)
211 PxVec3 v0 = vertices[indices[3*i]];
212 PxVec3 v1 = vertices[indices[3 * i + 1]];
213 PxVec3 v2 = vertices[indices[3 * i + 2]];
215 PxVec3 v0v1 = v0.
cross(v1);
217 volume += v0v1.dot(v2);
219 return volume / 6.0f;
224 template <
typename IndexType>
225 PX_FORCE_INLINE PxReal computeTriangleMeshVolume(
const PxVec4* vertices,
const IndexType* indices,
226 const PxU32 numTriangles)
231 for(PxU32 i = 0; i < numTriangles; ++i)
233 PxVec3 v0 = vertices[indices[3 * i]].getXYZ();
234 PxVec3 v1 = vertices[indices[3 * i + 1]].getXYZ();
235 PxVec3 v2 = vertices[indices[3 * i + 2]].getXYZ();
237 PxVec3 v0v1 = v0.
cross(v1);
239 volume += v0v1.dot(v2);
241 return volume / 6.0f;
254 delta *= fatCoeff / m;
268 const aos::BoolV con = aos::FIsGrtr(m, aos::FZero());
269 const aos::Vec3V fatDelta = aos::V3Scale(aos::V3ScaleInv(delta, m), fatCoeff);
270 p0 = aos::V3Sel(con, aos::V3Sub(p0, fatDelta), p0);
271 p1 = aos::V3Sel(con, aos::V3Add(p1, fatDelta), p1);
278 const PxF32 absPx =
PxAbs(v.x);
279 const PxF32 absNy =
PxAbs(v.y);
280 const PxF32 absNz =
PxAbs(v.z);
285 if (absNy > absPx && absNy > absNz)
292 else if (absNz > absPx)
3x3 matrix class
Definition PxMat33.h:91
PX_CUDA_CALLABLE PX_INLINE float getDeterminant() const
Get determinant.
Definition PxMat33.h:230
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T cross(const PxVec3T &v) const
cross product
Definition PxVec3.h:282
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE float dot(const PxVec3 &v) const
returns the scalar product of this and other.
Definition PxVec3.h:276
PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitude() const
returns the magnitude
Definition PxVec3.h:183
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isNormalized() const
is normalized - used by API parameter validation
Definition PxVec3.h:164
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
transform(pattern)
Definition docopt.py:72
PX_FORCE_INLINE bool keepTriangle(float triImpactDistance, float triAlignmentValue, float bestImpactDistance, float bestAlignmentValue, float maxDistance)
Definition GuInternal.h:110
PX_PHYSX_COMMON_API void computeBoxPoints(const PxBounds3 &bounds, PxVec3 *PX_RESTRICT pts)
Definition GuInternal.cpp:44
PX_FORCE_INLINE void makeFatEdge(PxVec3 &p0, PxVec3 &p1, PxReal fatCoeff)
Definition GuInternal.h:247
PX_FORCE_INLINE PxVec3 computeBarycentricPoint(const PxVec3 &p0, const PxVec3 &p1, const PxVec3 &p2, PxReal u, PxReal v)
Compute point as combination of barycentric coordinates.
Definition GuInternal.h:173
PX_FORCE_INLINE PxReal computeAlignmentValue(const PxVec3 &triNormal, const PxVec3 &unitDir)
Definition GuInternal.h:88
PX_PHYSX_COMMON_API const PxU8 * getBoxEdges()
Definition GuBox.cpp:62
void computeBoxAroundCapsule(const Capsule &capsule, Box &box)
Definition GuCapsule.cpp:40
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxAbs(float a)
abs returns the absolute value of its argument.
Definition PxMath.h:109
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMax(T a, T b)
The return value is the greater of the two specified values.
Definition PxMath.h:72
Definition PxVecMathAoSScalar.h:90
Definition PxVecMathAoSScalar.h:52
Definition PxVecMathAoSScalar.h:77