Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SimShapeFilterWrapper.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
15{
16public:
18 SimShapeFilterWrapper(const SimShapeFilter *inFilter, const Body *inBody1) :
19 mFilter(inFilter),
20 mBody1(inBody1)
21 {
22 // Fall back to an empty filter if no simulation shape filter is set, this reduces the virtual call to 'return true'
23 mFinalFilter = inFilter != nullptr? this : &mDefault;
24 }
25
27 virtual bool ShouldCollide(const Shape *inShape1, const SubShapeID &inSubShapeIDOfShape1, const Shape *inShape2, const SubShapeID &inSubShapeIDOfShape2) const override
28 {
29 return mFilter->ShouldCollide(*mBody1, inShape1, inSubShapeIDOfShape1, *mBody2, inShape2, inSubShapeIDOfShape2);
30 }
31
33 virtual bool ShouldCollide(const Shape *inShape2, const SubShapeID &inSubShapeIDOfShape2) const override
34 {
35 return mFilter->ShouldCollide(*mBody1, mBody1->GetShape(), SubShapeID(), *mBody2, inShape2, inSubShapeIDOfShape2);
36 }
37
39 void SetBody2(const Body *inBody2)
40 {
41 mBody2 = inBody2;
42 }
43
45 const ShapeFilter & GetFilter() const
46 {
47 return *mFinalFilter;
48 }
49
50private:
51 const ShapeFilter * mFinalFilter;
52 const SimShapeFilter * mFilter;
53 const Body * mBody1;
54 const Body * mBody2 = nullptr;
55 const ShapeFilter mDefault;
56};
57
#define JPH_NAMESPACE_END
Definition Core.h:419
#define JPH_NAMESPACE_BEGIN
Definition Core.h:413
Definition Body.h:39
const Shape * GetShape() const
Get the shape of this body.
Definition Body.h:265
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
Filter class used during the simulation (PhysicsSystem::Update) to filter out collisions at shape lev...
Definition SimShapeFilter.h:17
virtual bool ShouldCollide(const Body &inBody1, const Shape *inShape1, const SubShapeID &inSubShapeIDOfShape1, const Body &inBody2, const Shape *inShape2, const SubShapeID &inSubShapeIDOfShape2) const
Definition SimShapeFilter.h:33
Definition SimShapeFilterWrapper.h:15
const ShapeFilter & GetFilter() const
Returns the actual filter to use for collision detection.
Definition SimShapeFilterWrapper.h:45
SimShapeFilterWrapper(const SimShapeFilter *inFilter, const Body *inBody1)
Constructor.
Definition SimShapeFilterWrapper.h:18
virtual bool ShouldCollide(const Shape *inShape1, const SubShapeID &inSubShapeIDOfShape1, const Shape *inShape2, const SubShapeID &inSubShapeIDOfShape2) const override
Forward to the simulation shape filter.
Definition SimShapeFilterWrapper.h:27
virtual bool ShouldCollide(const Shape *inShape2, const SubShapeID &inSubShapeIDOfShape2) const override
Forward to the simulation shape filter.
Definition SimShapeFilterWrapper.h:33
void SetBody2(const Body *inBody2)
Set the body we're colliding against.
Definition SimShapeFilterWrapper.h:39
A sub shape id contains a path to an element (usually a triangle or other primitive type) of a compou...
Definition SubShapeID.h:23