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
64
66{
78
81 {
83 }
84
90
102
104 const RayCast & mRay;
110};
111
152
154{
171
174 {
175 return mCollector.ShouldEarlyOut();
176 }
177
191
194 {
195 JPH_ASSERT(inSubShape.IsValidScale(mScale));
196
197 // Create ID for sub shape
199
200 // Calculate the local transform for this sub shape
202
203 // Transform the center of mass of 2
205
206 // Transform the shape cast
207 ShapeCast shape_cast = mShapeCast.PostTransformed(local_transform.InversedRotationTranslation());
208
210 }
211
224};
225
227{
240
243 {
244 return mCollector.ShouldEarlyOut();
245 }
246
257
260 {
261 JPH_ASSERT(inSubShape.IsValidScale(mScale));
262
263 // Create ID for sub shape
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{
306
309 {
310 return mCollector.ShouldEarlyOut();
311 }
312
323
335
338 const Shape * mShape2;
348};
349
351{
372
375 {
376 return mCollector.ShouldEarlyOut();
377 }
378
389
401
404 const Shape * mShape1;
414};
415
416template <class BoxType>
418{
420 mBox(inBox),
421 mSubShapeIndices(outSubShapeIndices),
422 mMaxSubShapeIndices(inMaxSubShapeIndices)
423 {
424 }
425
428 {
429 return mNumResults >= mMaxSubShapeIndices;
430 }
431
438
441 {
442 JPH_ASSERT(mNumResults < mMaxSubShapeIndices);
443 *mSubShapeIndices++ = inSubShapeIndex;
444 mNumResults++;
445 }
446
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:439
#define JPH_NAMESPACE_END
Definition Core.h:367
std::uint32_t uint32
Definition Core.h:442
#define JPH_NAMESPACE_BEGIN
Definition Core.h:361
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
AllocateFunction Allocate
Definition Memory.cpp:59
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:215
void ExpandBy(Vec3Arg inVector)
Widen the box on both sides by inVector.
Definition AABox.h:98
AABox Transformed(Mat44Arg inMatrix) const
Transform bounding box.
Definition AABox.h:184
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
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:86
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:319
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:178
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:16
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:135
Definition RayCast.h:47
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
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