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
15class BodyFilter : public NonCopyable
16{
17public:
19 virtual ~BodyFilter() = default;
20
22 virtual bool ShouldCollide(const BodyID &inBodyID) const
23 {
24 return true;
25 }
26
28 virtual bool ShouldCollideLocked(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 find(mBodyIDs.begin(), mBodyIDs.end(), inBodyID) == mBodyIDs.end();
80 }
81
82private:
83 Array<BodyID> mBodyIDs;
84};
85
86#ifdef JPH_DEBUG_RENDERER
89{
90public:
92 virtual ~BodyDrawFilter() = default;
93
95 virtual bool ShouldDraw(const Body& inBody) const
96 {
97 return true;
98 }
99};
100#endif // JPH_DEBUG_RENDERER
101
unsigned int uint
Definition: Core.h:309
#define JPH_NAMESPACE_END
Definition: Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
Class function to filter out bodies for debug rendering, returns true if body should be rendered.
Definition: BodyFilter.h:89
virtual bool ShouldDraw(const Body &inBody) const
Filter function. Returns true if inBody should be rendered.
Definition: BodyFilter.h:95
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:33
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
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