Debian Codegraph @

thirdparty/jolt_physics/Jolt/Physics/Collision/ObjectLayer.h

raw symbols SCIP
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
7 #include <Jolt/Core/NonCopyable.h>
8
9 JPH_NAMESPACE_BEGIN
10
11 /// Layer that objects can be in, determines which other objects it can collide with
12 #ifndef JPH_OBJECT_LAYER_BITS
13 #define JPH_OBJECT_LAYER_BITS 16
14 #endif // JPH_OBJECT_LAYER_BITS
15 #if JPH_OBJECT_LAYER_BITS == 16
16 using ObjectLayer = uint16;
17 #elif JPH_OBJECT_LAYER_BITS == 32
18 using ObjectLayer = uint32;
19 #else
20 #error "JPH_OBJECT_LAYER_BITS must be 16 or 32"
21 #endif
22
23 /// Constant value used to indicate an invalid object layer
24 static constexpr ObjectLayer cObjectLayerInvalid = ObjectLayer(~ObjectLayer(0U));
25
26 /// Filter class for object layers
27 class JPH_EXPORT ObjectLayerFilter : public NonCopyable
28 {
29 public:
30 /// Destructor
31 virtual ~ObjectLayerFilter() = default;
32
33 /// Function to filter out object layers when doing collision query test (return true to allow testing against objects with this layer)
34 virtual bool ShouldCollide([[maybe_unused]] ObjectLayer inLayer) const
35 {
36 return true;
37 }
38
39 #ifdef JPH_TRACK_BROADPHASE_STATS
40 /// Get a string that describes this filter for stat tracking purposes
41 virtual String GetDescription() const
42 {
43 return "No Description";
44 }
45 #endif // JPH_TRACK_BROADPHASE_STATS
46 };
47
48 /// Filter class to test if two objects can collide based on their object layer. Used while finding collision pairs.
49 class JPH_EXPORT ObjectLayerPairFilter : public NonCopyable
50 {
51 public:
52 /// Destructor
53 virtual ~ObjectLayerPairFilter() = default;
54
55 /// Returns true if two layers can collide
56 virtual bool ShouldCollide([[maybe_unused]] ObjectLayer inLayer1, [[maybe_unused]] ObjectLayer inLayer2) const
57 {
58 return true;
59 }
60 };
61
62 /// Default filter class that uses the pair filter in combination with a specified layer to filter layers
63 class JPH_EXPORT DefaultObjectLayerFilter : public ObjectLayerFilter
64 {
65 public:
66 /// Constructor
67 DefaultObjectLayerFilter(const ObjectLayerPairFilter &inObjectLayerPairFilter, ObjectLayer inLayer) :
68 mObjectLayerPairFilter(inObjectLayerPairFilter),
69 mLayer(inLayer)
70 {
71 }
72
73 /// Copy constructor
74 DefaultObjectLayerFilter(const DefaultObjectLayerFilter &inRHS) :
75 mObjectLayerPairFilter(inRHS.mObjectLayerPairFilter),
76 mLayer(inRHS.mLayer)
77 {
78 }
79
80 // See ObjectLayerFilter::ShouldCollide
81 virtual bool ShouldCollide(ObjectLayer inLayer) const override
82 {
83 return mObjectLayerPairFilter.ShouldCollide(mLayer, inLayer);
84 }
85
86 private:
87 const ObjectLayerPairFilter & mObjectLayerPairFilter;
88 ObjectLayer mLayer;
89 };
90
91 /// Allows objects from a specific layer only
92 class JPH_EXPORT SpecifiedObjectLayerFilter : public ObjectLayerFilter
93 {
94 public:
95 /// Constructor
96 explicit SpecifiedObjectLayerFilter(ObjectLayer inLayer) :
97 mLayer(inLayer)
98 {
99 }
100
101 // See ObjectLayerFilter::ShouldCollide
102 virtual bool ShouldCollide(ObjectLayer inLayer) const override
103 {
104 return mLayer == inLayer;
105 }
106
107 private:
108 ObjectLayer mLayer;
109 };
110
111 JPH_NAMESPACE_END