| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Collision/Shape/CompoundShape.h> |
| 8 |
#include <Jolt/Physics/Collision/Shape/SubShapeID.h> |
| 9 |
#include <Jolt/Physics/Collision/RayCast.h> |
| 10 |
#include <Jolt/Physics/Collision/CastResult.h> |
| 11 |
#include <Jolt/Physics/Collision/ShapeCast.h> |
| 12 |
#include <Jolt/Physics/Collision/TransformedShape.h> |
| 13 |
#include <Jolt/Physics/Collision/CollisionDispatch.h> |
| 14 |
#include <Jolt/Geometry/RayAABox.h> |
| 15 |
#include <Jolt/Geometry/AABox4.h> |
| 16 |
#include <Jolt/Geometry/OrientedBox.h> |
| 17 |
|
| 18 |
JPH_NAMESPACE_BEGIN |
| 19 |
|
| 20 |
struct CompoundShape::CastRayVisitor |
| 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), |
| 26 |
mSubShapeBits(inShape->GetSubShapeIDBits()) |
| 27 |
{ |
| 28 |
|
| 29 |
mInvDirection.Set(inRay.mDirection); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
JPH_INLINE bool ShouldAbort() const |
| 34 |
{ |
| 35 |
return mHit.mFraction <= 0.0f; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 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 |
|
| 44 |
|
| 45 |
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex) |
| 46 |
{ |
| 47 |
|
| 48 |
SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator.PushID(inSubShapeIndex, mSubShapeBits); |
| 49 |
|
| 50 |
|
| 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 |
|
| 57 |
RayInvDirection mInvDirection; |
| 58 |
const RayCast & mRay; |
| 59 |
RayCastResult & mHit; |
| 60 |
SubShapeIDCreator mSubShapeIDCreator; |
| 61 |
uint mSubShapeBits; |
| 62 |
bool mReturnValue = false; |
| 63 |
}; |
| 64 |
|
| 65 |
struct CompoundShape::CastRayVisitorCollector |
| 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), |
| 71 |
mSubShapeBits(inShape->GetSubShapeIDBits()), |
| 72 |
mRayCastSettings(inRayCastSettings), |
| 73 |
mShapeFilter(inShapeFilter) |
| 74 |
{ |
| 75 |
|
| 76 |
mInvDirection.Set(inRay.mDirection); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
JPH_INLINE bool ShouldAbort() const |
| 81 |
{ |
| 82 |
return mCollector.ShouldEarlyOut(); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 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 |
|
| 91 |
|
| 92 |
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex) |
| 93 |
{ |
| 94 |
|
| 95 |
SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator.PushID(inSubShapeIndex, mSubShapeBits); |
| 96 |
|
| 97 |
|
| 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 |
|
| 103 |
RayInvDirection mInvDirection; |
| 104 |
const RayCast & mRay; |
| 105 |
CastRayCollector & mCollector; |
| 106 |
SubShapeIDCreator mSubShapeIDCreator; |
| 107 |
uint mSubShapeBits; |
| 108 |
RayCastSettings mRayCastSettings; |
| 109 |
const ShapeFilter & mShapeFilter; |
| 110 |
}; |
| 111 |
|
| 112 |
struct CompoundShape::CollidePointVisitor |
| 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), |
| 118 |
mSubShapeBits(inShape->GetSubShapeIDBits()), |
| 119 |
mShapeFilter(inShapeFilter) |
| 120 |
{ |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
JPH_INLINE bool ShouldAbort() const |
| 125 |
{ |
| 126 |
return mCollector.ShouldEarlyOut(); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 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 |
|
| 135 |
|
| 136 |
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex) |
| 137 |
{ |
| 138 |
|
| 139 |
SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator.PushID(inSubShapeIndex, mSubShapeBits); |
| 140 |
|
| 141 |
|
| 142 |
Mat44 transform = Mat44::sInverseRotationTranslation(inSubShape.GetRotation(), inSubShape.GetPositionCOM()); |
| 143 |
inSubShape.mShape->CollidePoint(transform * mPoint, shape2_sub_shape_id, mCollector, mShapeFilter); |
| 144 |
} |
| 145 |
|
| 146 |
Vec3 mPoint; |
| 147 |
SubShapeIDCreator mSubShapeIDCreator; |
| 148 |
CollidePointCollector & mCollector; |
| 149 |
uint mSubShapeBits; |
| 150 |
const ShapeFilter & mShapeFilter; |
| 151 |
}; |
| 152 |
|
| 153 |
struct CompoundShape::CastShapeVisitor |
| 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), |
| 166 |
mSubShapeBits(inShape->GetSubShapeIDBits()) |
| 167 |
{ |
| 168 |
|
| 169 |
mInvDirection.Set(inShapeCast.mDirection); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
JPH_INLINE bool ShouldAbort() const |
| 174 |
{ |
| 175 |
return mCollector.ShouldEarlyOut(); |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
JPH_INLINE Vec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const |
| 180 |
{ |
| 181 |
|
| 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 |
|
| 186 |
AABox4EnlargeWithExtent(mBoxExtent, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z); |
| 187 |
|
| 188 |
|
| 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 |
|
| 192 |
|
| 193 |
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex) |
| 194 |
{ |
| 195 |
JPH_ASSERT(inSubShape.IsValidScale(mScale)); |
| 196 |
|
| 197 |
|
| 198 |
SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator2.PushID(inSubShapeIndex, mSubShapeBits); |
| 199 |
|
| 200 |
|
| 201 |
Mat44 local_transform = Mat44::sRotationTranslation(inSubShape.GetRotation(), mScale * inSubShape.GetPositionCOM()); |
| 202 |
|
| 203 |
|
| 204 |
Mat44 center_of_mass_transform2 = mCenterOfMassTransform2 * local_transform; |
| 205 |
|
| 206 |
|
| 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 |
|
| 212 |
RayInvDirection mInvDirection; |
| 213 |
Vec3 mBoxCenter; |
| 214 |
Vec3 mBoxExtent; |
| 215 |
Vec3 mScale; |
| 216 |
const ShapeCast & mShapeCast; |
| 217 |
const ShapeCastSettings & mShapeCastSettings; |
| 218 |
const ShapeFilter & mShapeFilter; |
| 219 |
CastShapeCollector & mCollector; |
| 220 |
Mat44 mCenterOfMassTransform2; |
| 221 |
SubShapeIDCreator mSubShapeIDCreator1; |
| 222 |
SubShapeIDCreator mSubShapeIDCreator2; |
| 223 |
uint mSubShapeBits; |
| 224 |
}; |
| 225 |
|
| 226 |
struct CompoundShape::CollectTransformedShapesVisitor |
| 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), |
| 236 |
mSubShapeBits(inShape->GetSubShapeIDBits()), |
| 237 |
mShapeFilter(inShapeFilter) |
| 238 |
{ |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
JPH_INLINE bool ShouldAbort() const |
| 243 |
{ |
| 244 |
return mCollector.ShouldEarlyOut(); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const |
| 249 |
{ |
| 250 |
|
| 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 |
|
| 255 |
return AABox4VsBox(mLocalBox, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex) |
| 260 |
{ |
| 261 |
JPH_ASSERT(inSubShape.IsValidScale(mScale)); |
| 262 |
|
| 263 |
|
| 264 |
SubShapeIDCreator sub_shape_id = mSubShapeIDCreator.PushID(inSubShapeIndex, mSubShapeBits); |
| 265 |
|
| 266 |
|
| 267 |
Vec3 position = mPositionCOM + mRotation * (mScale * inSubShape.GetPositionCOM()); |
| 268 |
Quat rotation = mRotation * inSubShape.GetRotation(); |
| 269 |
|
| 270 |
|
| 271 |
inSubShape.mShape->CollectTransformedShapes(mBox, position, rotation, inSubShape.TransformScale(mScale), sub_shape_id, mCollector, mShapeFilter); |
| 272 |
} |
| 273 |
|
| 274 |
AABox mBox; |
| 275 |
OrientedBox mLocalBox; |
| 276 |
Vec3 mPositionCOM; |
| 277 |
Quat mRotation; |
| 278 |
Vec3 mScale; |
| 279 |
SubShapeIDCreator mSubShapeIDCreator; |
| 280 |
TransformedShapeCollector & mCollector; |
| 281 |
uint mSubShapeBits; |
| 282 |
const ShapeFilter & mShapeFilter; |
| 283 |
}; |
| 284 |
|
| 285 |
struct CompoundShape::CollideCompoundVsShapeVisitor |
| 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 |
|
| 301 |
Mat44 transform2_to_1 = inCenterOfMassTransform1.InversedRotationTranslation() * inCenterOfMassTransform2; |
| 302 |
|
| 303 |
|
| 304 |
mBoundsOf2InSpaceOf1 = inShape2->GetLocalBounds().Scaled(inScale2).Transformed(transform2_to_1); |
| 305 |
mBoundsOf2InSpaceOf1.ExpandBy(Vec3::sReplicate(inCollideShapeSettings.mMaxSeparationDistance)); |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
JPH_INLINE bool ShouldAbort() const |
| 310 |
{ |
| 311 |
return mCollector.ShouldEarlyOut(); |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const |
| 316 |
{ |
| 317 |
|
| 318 |
Vec4 bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z; |
| 319 |
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); |
| 320 |
|
| 321 |
|
| 322 |
return AABox4VsBox(mBoundsOf2InSpaceOf1, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex) |
| 327 |
{ |
| 328 |
|
| 329 |
Mat44 transform1 = mTransform1 * inSubShape.GetLocalTransformNoScale(mScale1); |
| 330 |
|
| 331 |
|
| 332 |
SubShapeIDCreator shape1_sub_shape_id = mSubShapeIDCreator1.PushID(inSubShapeIndex, mSubShapeBits); |
| 333 |
|
| 334 |
CollisionDispatch::sCollideShapeVsShape(inSubShape.mShape, mShape2, inSubShape.TransformScale(mScale1), mScale2, transform1, mTransform2, shape1_sub_shape_id, mSubShapeIDCreator2, mCollideShapeSettings, mCollector, mShapeFilter); |
| 335 |
} |
| 336 |
|
| 337 |
const CollideShapeSettings & mCollideShapeSettings; |
| 338 |
CollideShapeCollector & mCollector; |
| 339 |
const Shape * mShape2; |
| 340 |
Vec3 mScale1; |
| 341 |
Vec3 mScale2; |
| 342 |
Mat44 mTransform1; |
| 343 |
Mat44 mTransform2; |
| 344 |
AABox mBoundsOf2InSpaceOf1; |
| 345 |
SubShapeIDCreator mSubShapeIDCreator1; |
| 346 |
SubShapeIDCreator mSubShapeIDCreator2; |
| 347 |
uint mSubShapeBits; |
| 348 |
const ShapeFilter & mShapeFilter; |
| 349 |
}; |
| 350 |
|
| 351 |
struct CompoundShape::CollideShapeVsCompoundVisitor |
| 352 |
{ |
| 353 |
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) : |
| 354 |
mCollideShapeSettings(inCollideShapeSettings), |
| 355 |
mCollector(ioCollector), |
| 356 |
mShape1(inShape1), |
| 357 |
mScale1(inScale1), |
| 358 |
mScale2(inScale2), |
| 359 |
mTransform1(inCenterOfMassTransform1), |
| 360 |
mTransform2(inCenterOfMassTransform2), |
| 361 |
mSubShapeIDCreator1(inSubShapeIDCreator1), |
| 362 |
mSubShapeIDCreator2(inSubShapeIDCreator2), |
| 363 |
mSubShapeBits(inShape2->GetSubShapeIDBits()), |
| 364 |
mShapeFilter(inShapeFilter) |
| 365 |
{ |
| 366 |
|
| 367 |
Mat44 transform1_to_2 = inCenterOfMassTransform2.InversedRotationTranslation() * inCenterOfMassTransform1; |
| 368 |
|
| 369 |
|
| 370 |
mBoundsOf1InSpaceOf2 = inShape1->GetLocalBounds().Scaled(inScale1).Transformed(transform1_to_2); |
| 371 |
mBoundsOf1InSpaceOf2.ExpandBy(Vec3::sReplicate(inCollideShapeSettings.mMaxSeparationDistance)); |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
JPH_INLINE bool ShouldAbort() const |
| 376 |
{ |
| 377 |
return mCollector.ShouldEarlyOut(); |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const |
| 382 |
{ |
| 383 |
|
| 384 |
Vec4 bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z; |
| 385 |
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); |
| 386 |
|
| 387 |
|
| 388 |
return AABox4VsBox(mBoundsOf1InSpaceOf2, bounds_min_x, bounds_min_y, bounds_min_z, bounds_max_x, bounds_max_y, bounds_max_z); |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
JPH_INLINE void VisitShape(const SubShape &inSubShape, uint32 inSubShapeIndex) |
| 393 |
{ |
| 394 |
|
| 395 |
SubShapeIDCreator shape2_sub_shape_id = mSubShapeIDCreator2.PushID(inSubShapeIndex, mSubShapeBits); |
| 396 |
|
| 397 |
|
| 398 |
Mat44 transform2 = mTransform2 * inSubShape.GetLocalTransformNoScale(mScale2); |
| 399 |
|
| 400 |
CollisionDispatch::sCollideShapeVsShape(mShape1, inSubShape.mShape, mScale1, inSubShape.TransformScale(mScale2), mTransform1, transform2, mSubShapeIDCreator1, shape2_sub_shape_id, mCollideShapeSettings, mCollector, mShapeFilter); |
| 401 |
} |
| 402 |
|
| 403 |
const CollideShapeSettings & mCollideShapeSettings; |
| 404 |
CollideShapeCollector & mCollector; |
| 405 |
const Shape * mShape1; |
| 406 |
Vec3 mScale1; |
| 407 |
Vec3 mScale2; |
| 408 |
Mat44 mTransform1; |
| 409 |
Mat44 mTransform2; |
| 410 |
AABox mBoundsOf1InSpaceOf2; |
| 411 |
SubShapeIDCreator mSubShapeIDCreator1; |
| 412 |
SubShapeIDCreator mSubShapeIDCreator2; |
| 413 |
uint mSubShapeBits; |
| 414 |
const ShapeFilter & mShapeFilter; |
| 415 |
}; |
| 416 |
|
| 417 |
template <class BoxType> |
| 418 |
struct CompoundShape::GetIntersectingSubShapesVisitor |
| 419 |
{ |
| 420 |
JPH_INLINE GetIntersectingSubShapesVisitor(const BoxType &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) : |
| 421 |
mBox(inBox), |
| 422 |
mSubShapeIndices(outSubShapeIndices), |
| 423 |
mMaxSubShapeIndices(inMaxSubShapeIndices) |
| 424 |
{ |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
JPH_INLINE bool ShouldAbort() const |
| 429 |
{ |
| 430 |
return mNumResults >= mMaxSubShapeIndices; |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
JPH_INLINE UVec4 TestBounds(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const |
| 435 |
{ |
| 436 |
|
| 437 |
return AABox4VsBox(mBox, inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ); |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
JPH_INLINE void VisitShape([[maybe_unused]] const SubShape &inSubShape, uint32 inSubShapeIndex) |
| 442 |
{ |
| 443 |
JPH_ASSERT(mNumResults < mMaxSubShapeIndices); |
| 444 |
*mSubShapeIndices++ = inSubShapeIndex; |
| 445 |
mNumResults++; |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
JPH_INLINE int GetNumResults() const |
| 450 |
{ |
| 451 |
return mNumResults; |
| 452 |
} |
| 453 |
|
| 454 |
private: |
| 455 |
BoxType mBox; |
| 456 |
uint * mSubShapeIndices; |
| 457 |
int mMaxSubShapeIndices; |
| 458 |
int mNumResults = 0; |
| 459 |
}; |
| 460 |
|
| 461 |
JPH_NAMESPACE_END |