Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
BroadPhaseLayer.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
18{
19public:
20 using Type = uint8;
21
22 JPH_INLINE BroadPhaseLayer() = default;
23 JPH_INLINE explicit constexpr BroadPhaseLayer(Type inValue) : mValue(inValue) { }
24 JPH_INLINE constexpr BroadPhaseLayer(const BroadPhaseLayer &) = default;
25 JPH_INLINE BroadPhaseLayer & operator = (const BroadPhaseLayer &) = default;
26
27 JPH_INLINE constexpr bool operator == (const BroadPhaseLayer &inRHS) const
28 {
29 return mValue == inRHS.mValue;
30 }
31
32 JPH_INLINE constexpr bool operator != (const BroadPhaseLayer &inRHS) const
33 {
34 return mValue != inRHS.mValue;
35 }
36
37 JPH_INLINE constexpr bool operator < (const BroadPhaseLayer &inRHS) const
38 {
39 return mValue < inRHS.mValue;
40 }
41
42 JPH_INLINE explicit constexpr operator Type() const
43 {
44 return mValue;
45 }
46
47 JPH_INLINE Type GetValue() const
48 {
49 return mValue;
50 }
51
52private:
53 Type mValue;
54};
55
57static constexpr BroadPhaseLayer cBroadPhaseLayerInvalid(0xff);
58
61{
62public:
64 virtual ~BroadPhaseLayerInterface() = default;
65
67 virtual uint GetNumBroadPhaseLayers() const = 0;
68
71
72#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED)
74 virtual const char * GetBroadPhaseLayerName(BroadPhaseLayer inLayer) const = 0;
75#endif // JPH_EXTERNAL_PROFILE || JPH_PROFILE_ENABLED
76};
77
80{
81public:
83 virtual ~ObjectVsBroadPhaseLayerFilter() = default;
84
86 virtual bool ShouldCollide([[maybe_unused]] ObjectLayer inLayer1, [[maybe_unused]] BroadPhaseLayer inLayer2) const
87 {
88 return true;
89 }
90};
91
94{
95public:
97 virtual ~BroadPhaseLayerFilter() = default;
98
100 virtual bool ShouldCollide([[maybe_unused]] BroadPhaseLayer inLayer) const
101 {
102 return true;
103 }
104};
105
108{
109public:
111 DefaultBroadPhaseLayerFilter(const ObjectVsBroadPhaseLayerFilter &inObjectVsBroadPhaseLayerFilter, ObjectLayer inLayer) :
112 mObjectVsBroadPhaseLayerFilter(inObjectVsBroadPhaseLayerFilter),
113 mLayer(inLayer)
114 {
115 }
116
117 // See BroadPhaseLayerFilter::ShouldCollide
118 virtual bool ShouldCollide(BroadPhaseLayer inLayer) const override
119 {
120 return mObjectVsBroadPhaseLayerFilter.ShouldCollide(mLayer, inLayer);
121 }
122
123private:
124 const ObjectVsBroadPhaseLayerFilter &mObjectVsBroadPhaseLayerFilter;
125 ObjectLayer mLayer;
126};
127
130{
131public:
134 mLayer(inLayer)
135 {
136 }
137
138 // See BroadPhaseLayerFilter::ShouldCollide
139 virtual bool ShouldCollide(BroadPhaseLayer inLayer) const override
140 {
141 return mLayer == inLayer;
142 }
143
144private:
145 BroadPhaseLayer mLayer;
146};
147
std::uint8_t uint8
Definition: Core.h:440
unsigned int uint
Definition: Core.h:439
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
uint16 ObjectLayer
Definition: ObjectLayer.h:16
Filter class for broadphase layers.
Definition: BroadPhaseLayer.h:94
virtual ~BroadPhaseLayerFilter()=default
Destructor.
virtual bool ShouldCollide(BroadPhaseLayer inLayer) const
Function to filter out broadphase layers when doing collision query test (return true to allow testin...
Definition: BroadPhaseLayer.h:100
Definition: BroadPhaseLayer.h:18
JPH_INLINE constexpr bool operator<(const BroadPhaseLayer &inRHS) const
Definition: BroadPhaseLayer.h:37
JPH_INLINE BroadPhaseLayer()=default
JPH_INLINE constexpr BroadPhaseLayer(Type inValue)
Definition: BroadPhaseLayer.h:23
JPH_INLINE Type GetValue() const
Definition: BroadPhaseLayer.h:47
uint8 Type
Definition: BroadPhaseLayer.h:20
JPH_INLINE BroadPhaseLayer & operator=(const BroadPhaseLayer &)=default
JPH_INLINE constexpr bool operator!=(const BroadPhaseLayer &inRHS) const
Definition: BroadPhaseLayer.h:32
JPH_INLINE constexpr BroadPhaseLayer(const BroadPhaseLayer &)=default
JPH_INLINE constexpr bool operator==(const BroadPhaseLayer &inRHS) const
Definition: BroadPhaseLayer.h:27
Interface that the application should implement to allow mapping object layers to broadphase layers.
Definition: BroadPhaseLayer.h:61
virtual uint GetNumBroadPhaseLayers() const =0
Return the number of broadphase layers there are.
virtual BroadPhaseLayer GetBroadPhaseLayer(ObjectLayer inLayer) const =0
Convert an object layer to the corresponding broadphase layer.
virtual ~BroadPhaseLayerInterface()=default
Destructor.
virtual const char * GetBroadPhaseLayerName(BroadPhaseLayer inLayer) const =0
Get the user readable name of a broadphase layer (debugging purposes)
Default filter class that uses the pair filter in combination with a specified layer to filter layers...
Definition: BroadPhaseLayer.h:108
DefaultBroadPhaseLayerFilter(const ObjectVsBroadPhaseLayerFilter &inObjectVsBroadPhaseLayerFilter, ObjectLayer inLayer)
Constructor.
Definition: BroadPhaseLayer.h:111
virtual bool ShouldCollide(BroadPhaseLayer inLayer) const override
Function to filter out broadphase layers when doing collision query test (return true to allow testin...
Definition: BroadPhaseLayer.h:118
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition: NonCopyable.h:11
Class to test if an object can collide with a broadphase layer. Used while finding collision pairs.
Definition: BroadPhaseLayer.h:80
virtual bool ShouldCollide(ObjectLayer inLayer1, BroadPhaseLayer inLayer2) const
Returns true if an object layer should collide with a broadphase layer.
Definition: BroadPhaseLayer.h:86
virtual ~ObjectVsBroadPhaseLayerFilter()=default
Destructor.
Allows objects from a specific broad phase layer only.
Definition: BroadPhaseLayer.h:130
SpecifiedBroadPhaseLayerFilter(BroadPhaseLayer inLayer)
Constructor.
Definition: BroadPhaseLayer.h:133
virtual bool ShouldCollide(BroadPhaseLayer inLayer) const override
Function to filter out broadphase layers when doing collision query test (return true to allow testin...
Definition: BroadPhaseLayer.h:139