Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
CompoundShapeVisitors.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
17
19
21{
22 JPH_INLINE CastRayVisitor(const RayCast &inRay, const CompoundShape *inShape, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) :
23 mRay(inRay),
24 mHit(ioHit),
25 mSubShapeIDCreator(inSubShapeIDCreator),
27 {
28 // Determine ray properties of cast
30 }
31
33 JPH_INLINE bool ShouldAbort() const
34 {
35 return mHit.mFraction <= 0.0f;
36 }
37
39 JPH_INLINE Vec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
40 {
41 return RayAABox4(mRay.mOrigin, mInvDirection, inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ);
42 }
43
45 JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
46 {
47 // Create ID for sub shape
48 SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator.PushID(inSubShapeIndex, mSubShapeBits);
49
50 // Transform the ray
51 Mat44 transform = Mat44::sInverseRotationTranslation(inSubShape.GetRotation(), inSubShape.GetPositionCOM());
52 RayCast ray = mRay.Transformed(transform);
53 if (inSubShape.mShape->CastRay(ray, shape2_sub_shape_id, mHit))
54 mReturnValue = true;
55 }
56
58 const RayCast & mRay;
62 bool mReturnValue = false;
63};
64
66{
67 JPH_INLINE CastRayVisitorCollector(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const CompoundShape *inShape, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter) :
68 mRay(inRay),
69 mCollector(ioCollector),
70 mSubShapeIDCreator(inSubShapeIDCreator),
72 mRayCastSettings(inRayCastSettings),
73 mShapeFilter(inShapeFilter)
74 {
75 // Determine ray properties of cast
77 }
78
80 JPH_INLINE bool ShouldAbort() const
81 {
83 }
84
86 JPH_INLINE Vec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
87 {
88 return RayAABox4(mRay.mOrigin, mInvDirection, inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ);
89 }
90
92 JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
93 {
94 // Create ID for sub shape
95 SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator.PushID(inSubShapeIndex, mSubShapeBits);
96
97 // Transform the ray
98 Mat44 transform = Mat44::sInverseRotationTranslation(inSubShape.GetRotation(), inSubShape.GetPositionCOM());
99 RayCast ray = mRay.Transformed(transform);
100 inSubShape.mShape->CastRay(ray, mRayCastSettings, shape2_sub_shape_id, mCollector, mShapeFilter);
101 }
102
104 const RayCast & mRay;
110};
111
113{
114 JPH_INLINE CollidePointVisitor(Vec3Arg inPoint, const CompoundShape *inShape, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter) :
115 mPoint(inPoint),
116 mSubShapeIDCreator(inSubShapeIDCreator),
117 mCollector(ioCollector),
119 mShapeFilter(inShapeFilter)
120 {
121 }
122
124 JPH_INLINE bool ShouldAbort() const
125 {
126 return mCollector.ShouldEarlyOut();
127 }
128
130 JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
131 {
132 return AABox4VsPoint(mPoint, inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ);
133 }
134
136 JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
137 {
138 // Create ID for sub shape
139 SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator.PushID(inSubShapeIndex, mSubShapeBits);
140
141 // Transform the point
142 Mat44 transform = Mat44::sInverseRotationTranslation(inSubShape.GetRotation(), inSubShape.GetPositionCOM());
143 inSubShape.mShape->CollidePoint(transform * mPoint, shape2_sub_shape_id, mCollector, mShapeFilter);
144 }
145
151};
152
154{
155 JPH_INLINE CastShapeVisitor(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const CompoundShape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector) :
156 mBoxCenter(inShapeCast.mShapeWorldBounds.GetCenter()),
157 mBoxExtent(inShapeCast.mShapeWorldBounds.GetExtent()),
158 mScale(inScale),
159 mShapeCast(inShapeCast),
160 mShapeCastSettings(inShapeCastSettings),
161 mShapeFilter(inShapeFilter),
162 mCollector(ioCollector),
163 mCenterOfMassTransform2(inCenterOfMassTransform2),
164 mSubShapeIDCreator1(inSubShapeIDCreator1),
165 mSubShapeIDCreator2(inSubShapeIDCreator2),
167 {
168 // Determine ray properties of cast
169 mInvDirection.Set(inShapeCast.mDirection);
170 }
171
173 JPH_INLINE bool ShouldAbort() const
174 {
175 return mCollector.ShouldEarlyOut();
176 }
177
179 JPH_INLINE Vec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
180 {
181 // Scale the bounding boxes
182 Vec4 bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z;
183 AABox4Scale(mScale, inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z);
184
185 // Enlarge them by the casted shape's box extents
186 AABox4EnlargeWithExtent(mBoxExtent, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z);
187
188 // Test ray against the bounding boxes
189 return RayAABox4(mBoxCenter, mInvDirection, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z);
190 }
191
193 JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
194 {
195 JPH_ASSERT(inSubShape.IsValidScale(mScale));
196
197 // Create ID for sub shape
198 SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator2.PushID(inSubShapeIndex, mSubShapeBits);
199
200 // Calculate the local transform for this sub shape
201 Mat44 local_transform = Mat44::sRotationTranslation(inSubShape.GetRotation(), mScale * inSubShape.GetPositionCOM());
202
203 // Transform the center of mass of 2
204 Mat44 center_of_mass_transform2 = mCenterOfMassTransform2 * local_transform;
205
206 // Transform the shape cast
207 ShapeCast shape_cast = mShapeCast.PostTransformed(local_transform.InversedRotationTranslation());
208
209 CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, mShapeCastSettings, inSubShape.mShape, inSubShape.TransformScale(mScale), mShapeFilter, center_of_mass_transform2, mSubShapeIDCreator1, shape2_sub_shape_id, mCollector);
210 }
211
224};
225
227{
228 JPH_INLINE CollectTransformedShapesVisitor(const AABox &inBox, const CompoundShape *inShape, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, const SubShapeIDCreator &inSubShapeIDCreator, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) :
229 mBox(inBox),
230 mLocalBox(Mat44::sInverseRotationTranslation(inRotation, inPositionCOM), inBox),
231 mPositionCOM(inPositionCOM),
232 mRotation(inRotation),
233 mScale(inScale),
234 mSubShapeIDCreator(inSubShapeIDCreator),
235 mCollector(ioCollector),
237 mShapeFilter(inShapeFilter)
238 {
239 }
240
242 JPH_INLINE bool ShouldAbort() const
243 {
244 return mCollector.ShouldEarlyOut();
245 }
246
248 JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
249 {
250 // Scale the bounding boxes of this node
251 Vec4 bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z;
252 AABox4Scale(mScale, inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z);
253
254 // Test which nodes collide
255 return AABox4VsBox(mLocalBox, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z);
256 }
257
259 JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
260 {
261 JPH_ASSERT(inSubShape.IsValidScale(mScale));
262
263 // Create ID for sub shape
264 SubShapeIDCreator sub_shape_id = mSubShapeIDCreator.PushID(inSubShapeIndex, mSubShapeBits);
265
266 // Calculate world transform for sub shape
267 Vec3 position = mPositionCOM + mRotation * (mScale * inSubShape.GetPositionCOM());
268 Quat rotation = mRotation * inSubShape.GetRotation();
269
270 // Recurse to sub shape
271 inSubShape.mShape->CollectTransformedShapes(mBox, position, rotation, inSubShape.TransformScale(mScale), sub_shape_id, mCollector, mShapeFilter);
272 }
273
283};
284
286{
287 JPH_INLINE CollideCompoundVsShapeVisitor(const CompoundShape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) :
288 mCollideShapeSettings(inCollideShapeSettings),
289 mCollector(ioCollector),
290 mShape2(inShape2),
291 mScale1(inScale1),
292 mScale2(inScale2),
293 mTransform1(inCenterOfMassTransform1),
294 mTransform2(inCenterOfMassTransform2),
295 mSubShapeIDCreator1(inSubShapeIDCreator1),
296 mSubShapeIDCreator2(inSubShapeIDCreator2),
297 mSubShapeBits(inShape1->GetSubShapeIDBits()),
298 mShapeFilter(inShapeFilter)
299 {
300 // Get transform from shape 2 to shape 1
301 Mat44 transform2_to_1 = inCenterOfMassTransform1.InversedRotationTranslation() * inCenterOfMassTransform2;
302
303 // Convert bounding box of 2 into space of 1
304 mBoundsOf2InSpaceOf1 = inShape2->GetLocalBounds().Scaled(inScale2).Transformed(transform2_to_1);
305 }
306
308 JPH_INLINE bool ShouldAbort() const
309 {
310 return mCollector.ShouldEarlyOut();
311 }
312
314 JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
315 {
316 // Scale the bounding boxes
317 Vec4 bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z;
318 AABox4Scale(mScale1, inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z);
319
320 // Test which boxes collide
321 return AABox4VsBox(mBoundsOf2InSpaceOf1, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z);
322 }
323
325 JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
326 {
327 // Get world transform of 1
328 Mat44 transform1 = mTransform1 * inSubShape.GetLocalTransformNoScale(mScale1);
329
330 // Create ID for sub shape
331 SubShapeIDCreator shape1_sub_shape_id = mSubShapeIDCreator1.PushID(inSubShapeIndex, mSubShapeBits);
332
334 }
335
338 const Shape * mShape2;
348};
349
351{
352 JPH_INLINE CollideShapeVsCompoundVisitor(const Shape *inShape1, const CompoundShape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) :
353 mCollideShapeSettings(inCollideShapeSettings),
354 mCollector(ioCollector),
355 mShape1(inShape1),
356 mScale1(inScale1),
357 mScale2(inScale2),
358 mTransform1(inCenterOfMassTransform1),
359 mTransform2(inCenterOfMassTransform2),
360 mSubShapeIDCreator1(inSubShapeIDCreator1),
361 mSubShapeIDCreator2(inSubShapeIDCreator2),
362 mSubShapeBits(inShape2->GetSubShapeIDBits()),
363 mShapeFilter(inShapeFilter)
364 {
365 // Get transform from shape 1 to shape 2
366 Mat44 transform1_to_2 = inCenterOfMassTransform2.InversedRotationTranslation() * inCenterOfMassTransform1;
367
368 // Convert bounding box of 1 into space of 2
369 mBoundsOf1InSpaceOf2 = inShape1->GetLocalBounds().Scaled(inScale1).Transformed(transform1_to_2);
371 }
372
374 JPH_INLINE bool ShouldAbort() const
375 {
376 return mCollector.ShouldEarlyOut();
377 }
378
380 JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
381 {
382 // Scale the bounding boxes
383 Vec4 bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z;
384 AABox4Scale(mScale2, inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z);
385
386 // Test which bounding boxes collide
387 return AABox4VsBox(mBoundsOf1InSpaceOf2, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z);
388 }
389
391 JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
392 {
393 // Create ID for sub shape
394 SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator2.PushID(inSubShapeIndex, mSubShapeBits);
395
396 // Get world transform of 2
397 Mat44 transform2 = mTransform2 * inSubShape.GetLocalTransformNoScale(mScale2);
398
400 }
401
404 const Shape * mShape1;
414};
415
416template <class BoxType>
418{
419 JPH_INLINE GetIntersectingSubShapesVisitor(const BoxType &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) :
420 mBox(inBox),
421 mSubShapeIndices(outSubShapeIndices),
422 mMaxSubShapeIndices(inMaxSubShapeIndices)
423 {
424 }
425
427 JPH_INLINE bool ShouldAbort() const
428 {
429 return mNumResults >= mMaxSubShapeIndices;
430 }
431
433 JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
434 {
435 // Test which bounding boxes collide
436 return AABox4VsBox(mBox, inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ);
437 }
438
440 JPH_INLINE void VisitShape([[maybe_unused]] const SubShape &inSubShape, uint32 inSubShapeIndex)
441 {
442 JPH_ASSERT(mNumResults < mMaxSubShapeIndices);
443 *mSubShapeIndices++ = inSubShapeIndex;
444 mNumResults++;
445 }
446
448 JPH_INLINE int GetNumResults() const
449 {
450 return mNumResults;
451 }
452
453private:
454 BoxType mBox;
455 uint * mSubShapeIndices;
456 int mMaxSubShapeIndices;
457 int mNumResults = 0;
458};
459
JPH_INLINE UVec4 AABox4VsPoint(Vec3Arg inPoint, Vec4Arg inBoxMinX, Vec4Arg inBoxMinY, Vec4Arg inBoxMinZ, Vec4Arg inBoxMaxX, Vec4Arg inBoxMaxY, Vec4Arg inBoxMaxZ)
Test if 4 bounding boxes overlap with a point.
Definition AABox4.h:71
JPH_NAMESPACE_BEGIN JPH_INLINE UVec4 AABox4VsBox(const AABox &inBox1, Vec4Arg inBox2MinX, Vec4Arg inBox2MinY, Vec4Arg inBox2MinZ, Vec4Arg inBox2MaxX, Vec4Arg inBox2MaxY, Vec4Arg inBox2MaxZ)
Definition AABox4.h:13
JPH_INLINE void AABox4EnlargeWithExtent(Vec3Arg inExtent, Vec4 &ioBoundsMinX, Vec4 &ioBoundsMinY, Vec4 &ioBoundsMinZ, Vec4 &ioBoundsMaxX, Vec4 &ioBoundsMaxY, Vec4 &ioBoundsMaxZ)
Enlarge 4 bounding boxes with extent (add to both sides)
Definition AABox4.h:55
JPH_INLINE void AABox4Scale(Vec3Arg inScale, Vec4Arg inBoxMinX, Vec4Arg inBoxMinY, Vec4Arg inBoxMinZ, Vec4Arg inBoxMaxX, Vec4Arg inBoxMaxY, Vec4Arg inBoxMaxZ, Vec4 &outBoundsMinX, Vec4 &outBoundsMinY, Vec4 &outBoundsMinZ, Vec4 &outBoundsMaxX, Vec4 &outBoundsMaxY, Vec4 &outBoundsMaxZ)
Scale 4 axis aligned boxes.
Definition AABox4.h:33
unsigned int uint
Definition Core.h:446
#define JPH_NAMESPACE_END
Definition Core.h:379
std::uint32_t uint32
Definition Core.h:449
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
JPH_INLINE Vec4 RayAABox4(Vec3Arg inOrigin, const RayInvDirection &inInvDirection, Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ)
Definition RayAABox.h:72
Axis aligned box.
Definition AABox.h:16
AABox Scaled(Vec3Arg inScale) const
Scale this bounding box, can handle non-uniform and negative scaling.
Definition AABox.h:223
void ExpandBy(Vec3Arg inVector)
Widen the box on both sides by inVector.
Definition AABox.h:106
AABox Transformed(Mat44Arg inMatrix) const
Transform bounding box.
Definition AABox.h:192
float mFraction
Hit fraction of the ray/object [0, 1], HitPoint = Start + mFraction * (End - Start)
Definition CastResult.h:25
Settings to be passed with a collision query.
Definition CollideShape.h:94
JPH_OVERRIDE_NEW_DELETE float mMaxSeparationDistance
When > 0 contacts in the vicinity of the query shape can be found. All nearest contacts that are not ...
Definition CollideShape.h:99
Virtual interface that allows collecting multiple collision results.
Definition CollisionCollector.h:45
bool ShouldEarlyOut() const
When true, the collector will no longer accept any additional hits and the collision detection routin...
Definition CollisionCollector.h:89
static void sCollideShapeVsShape(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter={ })
Definition CollisionDispatch.h:33
static void sCastShapeVsShapeLocalSpace(const ShapeCast &inShapeCastLocal, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector)
Definition CollisionDispatch.h:53
Base class for a compound shape.
Definition CompoundShape.h:49
uint GetSubShapeIDBits() const
Determine amount of bits needed to encode sub shape id.
Definition CompoundShape.h:325
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
static JPH_INLINE Mat44 sRotationTranslation(QuatArg inR, Vec3Arg inT)
Get matrix that rotates and translates.
Definition Mat44.inl:149
static JPH_INLINE Mat44 sInverseRotationTranslation(QuatArg inR, Vec3Arg inT)
Get inverse matrix of sRotationTranslation.
Definition Mat44.inl:156
JPH_INLINE Mat44 InversedRotationTranslation() const
Inverse 4x4 matrix when it only contains rotation and translation.
Definition Mat44.inl:729
Oriented box.
Definition OrientedBox.h:18
Definition Quat.h:33
Specialization of cast result against a shape.
Definition CastResult.h:30
Settings to be passed with a ray cast.
Definition RayCast.h:70
Helper structure holding the reciprocal of a ray for Ray vs AABox testing.
Definition RayAABox.h:11
void Set(Vec3Arg inDirection)
Set reciprocal from ray direction.
Definition RayAABox.h:18
Settings to be passed with a shape cast.
Definition ShapeCast.h:92
Filter class.
Definition ShapeFilter.h:17
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition Shape.h:186
virtual AABox GetLocalBounds() const =0
Get local bounding box including convex radius, this box is centered around the center of mass rather...
virtual void CollectTransformedShapes(const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, const SubShapeIDCreator &inSubShapeIDCreator, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) const
Definition Shape.cpp:52
virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const =0
virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const =0
Definition SubShapeID.h:108
SubShapeIDCreator PushID(uint inValue, uint inBits) const
Add a new id to the chain of id's and return it.
Definition SubShapeID.h:111
Definition UVec4.h:12
Definition Vec3.h:17
static JPH_INLINE Vec3 sReplicate(float inV)
Replicate inV across all components.
Definition Vec3.inl:118
Definition Vec4.h:14
Definition CompoundShapeVisitors.h:66
const ShapeFilter & mShapeFilter
Definition CompoundShapeVisitors.h:109
RayCastSettings mRayCastSettings
Definition CompoundShapeVisitors.h:108
const RayCast & mRay
Definition CompoundShapeVisitors.h:104
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
Test the ray against a single subshape.
Definition CompoundShapeVisitors.h:92
SubShapeIDCreator mSubShapeIDCreator
Definition CompoundShapeVisitors.h:106
uint mSubShapeBits
Definition CompoundShapeVisitors.h:107
JPH_INLINE Vec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
Test ray against 4 bounding boxes and returns the distance where the ray enters the bounding box.
Definition CompoundShapeVisitors.h:86
CastRayCollector & mCollector
Definition CompoundShapeVisitors.h:105
JPH_INLINE bool ShouldAbort() const
Returns true when collision detection should abort because it's not possible to find a better hit.
Definition CompoundShapeVisitors.h:80
JPH_INLINE CastRayVisitorCollector(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const CompoundShape *inShape, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter)
Definition CompoundShapeVisitors.h:67
RayInvDirection mInvDirection
Definition CompoundShapeVisitors.h:103
Definition CompoundShapeVisitors.h:21
uint mSubShapeBits
Definition CompoundShapeVisitors.h:61
JPH_INLINE Vec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
Test ray against 4 bounding boxes and returns the distance where the ray enters the bounding box.
Definition CompoundShapeVisitors.h:39
SubShapeIDCreator mSubShapeIDCreator
Definition CompoundShapeVisitors.h:60
const RayCast & mRay
Definition CompoundShapeVisitors.h:58
JPH_INLINE bool ShouldAbort() const
Returns true when collision detection should abort because it's not possible to find a better hit.
Definition CompoundShapeVisitors.h:33
JPH_INLINE CastRayVisitor(const RayCast &inRay, const CompoundShape *inShape, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit)
Definition CompoundShapeVisitors.h:22
RayInvDirection mInvDirection
Definition CompoundShapeVisitors.h:57
bool mReturnValue
Definition CompoundShapeVisitors.h:62
RayCastResult & mHit
Definition CompoundShapeVisitors.h:59
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
Test the ray against a single subshape.
Definition CompoundShapeVisitors.h:45
Definition CompoundShapeVisitors.h:154
Vec3 mScale
Definition CompoundShapeVisitors.h:215
JPH_INLINE bool ShouldAbort() const
Returns true when collision detection should abort because it's not possible to find a better hit.
Definition CompoundShapeVisitors.h:173
CastShapeCollector & mCollector
Definition CompoundShapeVisitors.h:219
const ShapeCastSettings & mShapeCastSettings
Definition CompoundShapeVisitors.h:217
SubShapeIDCreator mSubShapeIDCreator2
Definition CompoundShapeVisitors.h:222
Vec3 mBoxExtent
Definition CompoundShapeVisitors.h:214
uint mSubShapeBits
Definition CompoundShapeVisitors.h:223
const ShapeCast & mShapeCast
Definition CompoundShapeVisitors.h:216
const ShapeFilter & mShapeFilter
Definition CompoundShapeVisitors.h:218
SubShapeIDCreator mSubShapeIDCreator1
Definition CompoundShapeVisitors.h:221
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
Test the cast shape against a single subshape.
Definition CompoundShapeVisitors.h:193
JPH_INLINE Vec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
Tests the shape cast against 4 bounding boxes, returns the distance along the shape cast where the sh...
Definition CompoundShapeVisitors.h:179
JPH_INLINE CastShapeVisitor(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const CompoundShape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector)
Definition CompoundShapeVisitors.h:155
Vec3 mBoxCenter
Definition CompoundShapeVisitors.h:213
RayInvDirection mInvDirection
Definition CompoundShapeVisitors.h:212
Mat44 mCenterOfMassTransform2
Definition CompoundShapeVisitors.h:220
Definition CompoundShapeVisitors.h:227
JPH_INLINE bool ShouldAbort() const
Returns true when collision detection should abort because it's not possible to find a better hit.
Definition CompoundShapeVisitors.h:242
Vec3 mPositionCOM
Definition CompoundShapeVisitors.h:276
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
Collect the transformed sub shapes for a single subshape.
Definition CompoundShapeVisitors.h:259
Quat mRotation
Definition CompoundShapeVisitors.h:277
AABox mBox
Definition CompoundShapeVisitors.h:274
SubShapeIDCreator mSubShapeIDCreator
Definition CompoundShapeVisitors.h:279
JPH_INLINE CollectTransformedShapesVisitor(const AABox &inBox, const CompoundShape *inShape, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, const SubShapeIDCreator &inSubShapeIDCreator, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter)
Definition CompoundShapeVisitors.h:228
Vec3 mScale
Definition CompoundShapeVisitors.h:278
TransformedShapeCollector & mCollector
Definition CompoundShapeVisitors.h:280
const ShapeFilter & mShapeFilter
Definition CompoundShapeVisitors.h:282
JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
Tests 4 bounding boxes against the query box, returns true for the ones that collide.
Definition CompoundShapeVisitors.h:248
uint mSubShapeBits
Definition CompoundShapeVisitors.h:281
OrientedBox mLocalBox
Definition CompoundShapeVisitors.h:275
Definition CompoundShapeVisitors.h:286
CollideShapeCollector & mCollector
Definition CompoundShapeVisitors.h:337
Mat44 mTransform1
Definition CompoundShapeVisitors.h:341
JPH_INLINE bool ShouldAbort() const
Returns true when collision detection should abort because it's not possible to find a better hit.
Definition CompoundShapeVisitors.h:308
const CollideShapeSettings & mCollideShapeSettings
Definition CompoundShapeVisitors.h:336
Mat44 mTransform2
Definition CompoundShapeVisitors.h:342
uint mSubShapeBits
Definition CompoundShapeVisitors.h:346
const ShapeFilter & mShapeFilter
Definition CompoundShapeVisitors.h:347
Vec3 mScale1
Definition CompoundShapeVisitors.h:339
SubShapeIDCreator mSubShapeIDCreator2
Definition CompoundShapeVisitors.h:345
Vec3 mScale2
Definition CompoundShapeVisitors.h:340
JPH_INLINE CollideCompoundVsShapeVisitor(const CompoundShape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter)
Definition CompoundShapeVisitors.h:287
AABox mBoundsOf2InSpaceOf1
Definition CompoundShapeVisitors.h:343
JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
Tests the bounds of shape 2 vs 4 bounding boxes, returns true for the ones that intersect.
Definition CompoundShapeVisitors.h:314
const Shape * mShape2
Definition CompoundShapeVisitors.h:338
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
Test the shape against a single subshape.
Definition CompoundShapeVisitors.h:325
SubShapeIDCreator mSubShapeIDCreator1
Definition CompoundShapeVisitors.h:344
Definition CompoundShapeVisitors.h:113
JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
Test if point overlaps with 4 boxes, returns true for the ones that do.
Definition CompoundShapeVisitors.h:130
Vec3 mPoint
Definition CompoundShapeVisitors.h:146
SubShapeIDCreator mSubShapeIDCreator
Definition CompoundShapeVisitors.h:147
JPH_INLINE CollidePointVisitor(Vec3Arg inPoint, const CompoundShape *inShape, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter)
Definition CompoundShapeVisitors.h:114
JPH_INLINE bool ShouldAbort() const
Returns true when collision detection should abort because it's not possible to find a better hit.
Definition CompoundShapeVisitors.h:124
CollidePointCollector & mCollector
Definition CompoundShapeVisitors.h:148
uint mSubShapeBits
Definition CompoundShapeVisitors.h:149
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
Test the point against a single subshape.
Definition CompoundShapeVisitors.h:136
const ShapeFilter & mShapeFilter
Definition CompoundShapeVisitors.h:150
Definition CompoundShapeVisitors.h:351
JPH_INLINE bool ShouldAbort() const
Returns true when collision detection should abort because it's not possible to find a better hit.
Definition CompoundShapeVisitors.h:374
uint mSubShapeBits
Definition CompoundShapeVisitors.h:412
const Shape * mShape1
Definition CompoundShapeVisitors.h:404
const ShapeFilter & mShapeFilter
Definition CompoundShapeVisitors.h:413
SubShapeIDCreator mSubShapeIDCreator2
Definition CompoundShapeVisitors.h:411
const CollideShapeSettings & mCollideShapeSettings
Definition CompoundShapeVisitors.h:402
CollideShapeCollector & mCollector
Definition CompoundShapeVisitors.h:403
Mat44 mTransform1
Definition CompoundShapeVisitors.h:407
AABox mBoundsOf1InSpaceOf2
Definition CompoundShapeVisitors.h:409
Vec3 mScale1
Definition CompoundShapeVisitors.h:405
Vec3 mScale2
Definition CompoundShapeVisitors.h:406
JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
Tests the bounds of shape 1 vs 4 bounding boxes, returns true for the ones that intersect.
Definition CompoundShapeVisitors.h:380
SubShapeIDCreator mSubShapeIDCreator1
Definition CompoundShapeVisitors.h:410
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
Test the shape against a single subshape.
Definition CompoundShapeVisitors.h:391
Mat44 mTransform2
Definition CompoundShapeVisitors.h:408
JPH_INLINE CollideShapeVsCompoundVisitor(const Shape *inShape1, const CompoundShape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter)
Definition CompoundShapeVisitors.h:352
Definition CompoundShapeVisitors.h:418
JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const
Tests the box vs 4 bounding boxes, returns true for the ones that intersect.
Definition CompoundShapeVisitors.h:433
JPH_INLINE bool ShouldAbort() const
Returns true when collision detection should abort because the buffer is full.
Definition CompoundShapeVisitors.h:427
JPH_INLINE GetIntersectingSubShapesVisitor(const BoxType &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices)
Definition CompoundShapeVisitors.h:419
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex)
Records a hit.
Definition CompoundShapeVisitors.h:440
JPH_INLINE int GetNumResults() const
Get the number of indices that were found.
Definition CompoundShapeVisitors.h:448
Definition CompoundShape.h:138
JPH_INLINE Quat GetRotation() const
Uncompress the rotation.
Definition CompoundShape.h:229
JPH_INLINE Mat44 GetLocalTransformNoScale(Vec3Arg inScale) const
Definition CompoundShape.h:184
bool IsValidScale(Vec3Arg inScale) const
Test if inScale is valid for this sub shape.
Definition CompoundShape.h:191
Vec3 TransformScale(Vec3Arg inScale) const
Transform the scale to the local space of the child shape.
Definition CompoundShape.h:201
JPH_INLINE Vec3 GetPositionCOM() const
Uncompress the center of mass position.
Definition CompoundShape.h:217
RefConst< Shape > mShape
Definition CompoundShape.h:234
Definition RayCast.h:47
Vec3 mDirection
Direction and length of the ray (anything beyond this length will not be reported as a hit)
Definition RayCast.h:43
RayCastType Transformed(typename Mat::ArgType inTransform) const
Transform this ray using inTransform.
Definition RayCast.h:23
Vec mOrigin
Origin of the ray.
Definition RayCast.h:42
Definition ShapeCast.h:69
const Vec3 mDirection
Direction and length of the cast (anything beyond this length will not be reported as a hit)
Definition ShapeCast.h:64
ShapeCastType PostTransformed(typename Mat::ArgType inTransform) const
Transform this shape cast using inTransform. Multiply transform on the left left hand side.
Definition ShapeCast.h:42