Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
BodyFilter.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
9
11
12class Body;
13
16{
17public:
19 virtual ~BodyFilter() = default;
20
22 virtual bool ShouldCollide([[maybe_unused]] const BodyID &inBodyID) const
23 {
24 return true;
25 }
26
28 virtual bool ShouldCollideLocked([[maybe_unused]] const Body &inBody) const
29 {
30 return true;
31 }
32};
33
36{
37public:
39 explicit IgnoreSingleBodyFilter(const BodyID &inBodyID) :
40 mBodyID(inBodyID)
41 {
42 }
43
45 virtual bool ShouldCollide(const BodyID &inBodyID) const override
46 {
47 return mBodyID != inBodyID;
48 }
49
50private:
51 BodyID mBodyID;
52};
53
56{
57public:
59 void Clear()
60 {
61 mBodyIDs.clear();
62 }
63
65 void Reserve(uint inSize)
66 {
67 mBodyIDs.reserve(inSize);
68 }
69
71 void IgnoreBody(const BodyID &inBodyID)
72 {
73 mBodyIDs.push_back(inBodyID);
74 }
75
77 virtual bool ShouldCollide(const BodyID &inBodyID) const override
78 {
79 return std::find(mBodyIDs.begin(), mBodyIDs.end(), inBodyID) == mBodyIDs.end();
80 }
81
82private:
83 Array<BodyID> mBodyIDs;
84};
85
88{
89public:
91 explicit IgnoreSingleBodyFilterChained(const BodyID inBodyID, const BodyFilter &inFilter) :
92 mBodyID(inBodyID),
93 mFilter(inFilter)
94 {
95 }
96
98 virtual bool ShouldCollide(const BodyID &inBodyID) const override
99 {
100 return inBodyID != mBodyID && mFilter.ShouldCollide(inBodyID);
101 }
102
104 virtual bool ShouldCollideLocked(const Body &inBody) const override
105 {
106 return mFilter.ShouldCollideLocked(inBody);
107 }
108
109private:
110 BodyID mBodyID;
111 const BodyFilter & mFilter;
112};
113
114#ifdef JPH_DEBUG_RENDERER
117{
118public:
120 virtual ~BodyDrawFilter() = default;
121
123 virtual bool ShouldDraw([[maybe_unused]] const Body& inBody) const
124 {
125 return true;
126 }
127};
128#endif // JPH_DEBUG_RENDERER
129
#define JPH_EXPORT
Definition Core.h:271
unsigned int uint
Definition Core.h:481
#define JPH_NAMESPACE_END
Definition Core.h:414
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
Definition Array.h:36
Class function to filter out bodies for debug rendering, returns true if body should be rendered.
Definition BodyFilter.h:117
virtual bool ShouldDraw(const Body &inBody) const
Filter function. Returns true if inBody should be rendered.
Definition BodyFilter.h:123
virtual ~BodyDrawFilter()=default
Destructor.
Class function to filter out bodies, returns true if test should collide with body.
Definition BodyFilter.h:16
virtual bool ShouldCollideLocked(const Body &inBody) const
Filter function. Returns true if we should collide with inBody (this is called after the body is lock...
Definition BodyFilter.h:28
virtual ~BodyFilter()=default
Destructor.
virtual bool ShouldCollide(const BodyID &inBodyID) const
Filter function. Returns true if we should collide with inBodyID.
Definition BodyFilter.h:22
Definition Body.h:35
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition BodyID.h:13
A simple body filter implementation that ignores multiple, specified bodies.
Definition BodyFilter.h:56
virtual bool ShouldCollide(const BodyID &inBodyID) const override
Filter function. Returns true if we should collide with inBodyID.
Definition BodyFilter.h:77
void Reserve(uint inSize)
Reserve space for inSize body ID's.
Definition BodyFilter.h:65
void IgnoreBody(const BodyID &inBodyID)
Add a body to be ignored.
Definition BodyFilter.h:71
void Clear()
Remove all bodies from the filter.
Definition BodyFilter.h:59
Ignores a single body and chains the filter to another filter.
Definition BodyFilter.h:88
IgnoreSingleBodyFilterChained(const BodyID inBodyID, const BodyFilter &inFilter)
Constructor.
Definition BodyFilter.h:91
virtual bool ShouldCollide(const BodyID &inBodyID) const override
Filter function. Returns true if we should collide with inBodyID.
Definition BodyFilter.h:98
virtual bool ShouldCollideLocked(const Body &inBody) const override
Filter function. Returns true if we should collide with inBody (this is called after the body is lock...
Definition BodyFilter.h:104
A simple body filter implementation that ignores a single, specified body.
Definition BodyFilter.h:36
virtual bool ShouldCollide(const BodyID &inBodyID) const override
Filter function. Returns true if we should collide with inBodyID.
Definition BodyFilter.h:45
IgnoreSingleBodyFilter(const BodyID &inBodyID)
Constructor, pass the body you want to ignore.
Definition BodyFilter.h:39
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11