RavEngine
Loading...
Searching...
No Matches
GuCCDSweepConvexMesh.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_CCD_SWEEP_CONVEX_MESH_H
30#define GU_CCD_SWEEP_CONVEX_MESH_H
31
32#include "common/PxPhysXCommonConfig.h"
33#include "foundation/PxVecTransform.h"
34#include "CmScaling.h"
35
36#define GU_TRIANGLE_SWEEP_METHOD_ARGS \
37 const PxGeometry& shape0, \
38 const PxGeometry& shape1, \
39 const PxTransform& transform0, \
40 const PxTransform& transform1, \
41 const PxTransform& lastTm0, \
42 const PxTransform& lastTm1, \
43 PxReal restDistance, \
44 PxVec3& worldNormal, \
45 PxVec3& worldPoint, \
46 const Cm::FastVertex2ShapeScaling& meshScaling, \
47 Gu::TriangleV& triangle, \
48 const PxF32 toiEstimate
49
50#define GU_SWEEP_METHOD_ARGS \
51 const Gu::CCDShape& shape0, \
52 const Gu::CCDShape& shape1, \
53 const PxTransform& transform0, \
54 const PxTransform& transform1, \
55 const PxTransform& lastTm0, \
56 const PxTransform& lastTm1, \
57 PxReal restDistance, \
58 PxVec3& worldNormal, \
59 PxVec3& worldPoint, \
60 const PxF32 toiEstimate, \
61 PxU32& outCCDFaceIndex, \
62 const PxReal fastMovingThreshold
63
64#define GU_SWEEP_ESTIMATE_ARGS \
65 const CCDShape& shape0, \
66 const CCDShape& shape1, \
67 const PxReal restDistance, \
68 const PxReal fastMovingThreshold
69
70#define GU_SWEEP_METHOD_ARGS_UNUSED \
71 const Gu::CCDShape& /*shape0*/, \
72 const Gu::CCDShape& /*shape1*/, \
73 const PxTransform& /*transform0*/, \
74 const PxTransform& /*transform1*/, \
75 const PxTransform& /*lastTm0*/, \
76 const PxTransform& /*lastTm1*/, \
77 PxReal /*restDistance*/, \
78 PxVec3& /*worldNormal*/, \
79 PxVec3& /*worldPoint*/, \
80 const PxF32 /*toiEstimate*/, \
81 PxU32& /*outCCDFaceIndex*/, \
82 const PxReal /*fastMovingThreshold*/
83
84namespace physx
85{
86namespace Gu
87{
88 struct CCDShape
89 {
90 const PxGeometry* mGeometry;
91 PxReal mFastMovingThreshold; //The CCD threshold for this shape
92 PxTransform mPrevTransform; //This shape's previous transform
93 PxTransform mCurrentTransform; //This shape's current transform
94 PxVec3 mExtents; //The extents of this shape's AABB
95 PxVec3 mCenter; //The center of this shape's AABB
96 PxU32 mUpdateCount; //How many times this shape has been updated in the CCD. This is correlated with the CCD body's update count.
97 };
98
99 PX_FORCE_INLINE PxF32 sweepAABBAABB(const PxVec3& centerA, const PxVec3& extentsA, const PxVec3& centerB, const PxVec3& extentsB, const PxVec3& trA, const PxVec3& trB)
100 {
101 //Sweep 2 AABBs against each other, return the TOI when they hit else PX_MAX_REAL if they don't hit
102 const PxVec3 cAcB = centerA - centerB;
103 const PxVec3 sumExtents = extentsA + extentsB;
104
105 //Initial hit
106 if(PxAbs(cAcB.x) <= sumExtents.x &&
107 PxAbs(cAcB.y) <= sumExtents.y &&
108 PxAbs(cAcB.z) <= sumExtents.z)
109 return 0.f;
110
111 //No initial hit - perform the sweep
112 const PxVec3 relTr = trB - trA;
113 PxF32 tfirst = 0.f;
114 PxF32 tlast = 1.f;
115
116 const PxVec3 aMax = centerA + extentsA;
117 const PxVec3 aMin = centerA - extentsA;
118 const PxVec3 bMax = centerB + extentsB;
119 const PxVec3 bMin = centerB - extentsB;
120
121 const PxF32 eps = 1e-6f;
122
123 for(PxU32 a = 0; a < 3; ++a)
124 {
125 if(relTr[a] < -eps)
126 {
127 if(bMax[a] < aMin[a])
128 return PX_MAX_REAL;
129 if(aMax[a] < bMin[a])
130 tfirst = PxMax((aMax[a] - bMin[a])/relTr[a], tfirst);
131 if(bMax[a] > aMin[a])
132 tlast = PxMin((aMin[a] - bMax[a])/relTr[a], tlast);
133 }
134 else if(relTr[a] > eps)
135 {
136 if(bMin[a] > aMax[a])
137 return PX_MAX_REAL;
138 if(bMax[a] < aMin[a])
139 tfirst = PxMax((aMin[a] - bMax[a])/relTr[a], tfirst);
140 if(aMax[a] > bMin[a])
141 tlast = PxMin((aMax[a] - bMin[a])/relTr[a], tlast);
142 }
143 else
144 {
145 if(bMax[a] < aMin[a] || bMin[a] > aMax[a])
146 return PX_MAX_REAL;
147 }
148
149 //No hit
150 if(tfirst > tlast)
151 return PX_MAX_REAL;
152 }
153 //There was a hit so return the TOI
154 return tfirst;
155 }
156
157 PX_PHYSX_COMMON_API PxReal SweepShapeShape(GU_SWEEP_METHOD_ARGS);
158
159 PX_PHYSX_COMMON_API PxReal SweepEstimateAnyShapeHeightfield(GU_SWEEP_ESTIMATE_ARGS);
160
161 PX_PHYSX_COMMON_API PxReal SweepEstimateAnyShapeMesh(GU_SWEEP_ESTIMATE_ARGS);
162}
163}
164#endif
165
A geometry object.
Definition PxGeometry.h:79
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
PxReal SweepEstimateAnyShapeMesh(GU_SWEEP_ESTIMATE_ARGS)
This code performs a conservative estimate of the TOI of a shape v mesh.
Definition GuCCDSweepConvexMesh.cpp:605
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
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMin(T a, T b)
The return value is the lesser of the two specified values.
Definition PxMath.h:88
Definition GuCCDSweepConvexMesh.h:89