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 }
23
25 virtual bool ShouldCollide(const Shape *inShape1, const SubShapeID &inSubShapeIDOfShape1, const Shape *inShape2, const SubShapeID &inSubShapeIDOfShape2) const override
26 {
27 return mFilter->ShouldCollide(*mBody1, inShape1, inSubShapeIDOfShape1, *mBody2, inShape2, inSubShapeIDOfShape2);
28 }
29
31 virtual bool ShouldCollide(const Shape *inShape2, const SubShapeID &inSubShapeIDOfShape2) const override
32 {
33 return mFilter->ShouldCollide(*mBody1, mBody1->GetShape(), SubShapeID(), *mBody2, inShape2, inSubShapeIDOfShape2);
34 }
35
37 void SetBody2(const Body *inBody2)
38 {
39 mBody2 = inBody2;
40 }
41
42private:
43 const SimShapeFilter * mFilter;
44 const Body * mBody1;
45 const Body * mBody2;
46};
47
51{
52public:
54 SimShapeFilterWrapperUnion(const SimShapeFilter *inFilter, const Body *inBody1)
55 {
56 // Dirty trick: if we don't have a filter, placement new a standard ShapeFilter so that we
57 // don't have to check for nullptr in the ShouldCollide function
58 if (inFilter != nullptr)
59 new (&mSimShapeFilterWrapper) SimShapeFilterWrapper(inFilter, inBody1);
60 else
61 new (&mSimShapeFilterWrapper) ShapeFilter();
62 }
63
66 {
67 // Doesn't need to be destructed
68 }
69
72 {
73 return mSimShapeFilterWrapper;
74 }
75
76private:
77 SimShapeFilterWrapper mSimShapeFilterWrapper;
78 ShapeFilter mShapeFilter;
79};
80
#define JPH_NAMESPACE_END
Definition Core.h:414
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
Definition Body.h:35
const Shape * GetShape() const
Get the shape of this body.
Definition Body.h:261
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
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:25
virtual bool ShouldCollide(const Shape *inShape2, const SubShapeID &inSubShapeIDOfShape2) const override
Forward to the simulation shape filter.
Definition SimShapeFilterWrapper.h:31
void SetBody2(const Body *inBody2)
Set the body we're colliding against.
Definition SimShapeFilterWrapper.h:37
A sub shape id contains a path to an element (usually a triangle or other primitive type) of a compou...
Definition SubShapeID.h:23
Definition SimShapeFilterWrapper.h:51
~SimShapeFilterWrapperUnion()
Destructor.
Definition SimShapeFilterWrapper.h:65
SimShapeFilterWrapperUnion(const SimShapeFilter *inFilter, const Body *inBody1)
Constructor.
Definition SimShapeFilterWrapper.h:54
SimShapeFilterWrapper & GetSimShapeFilterWrapper()
Accessor.
Definition SimShapeFilterWrapper.h:71