Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ObjectLayer.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
8
10
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
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
24static constexpr ObjectLayer cObjectLayerInvalid = ObjectLayer(~ObjectLayer(0U));
25
28{
29public:
31 virtual ~ObjectLayerFilter() = default;
32
34 virtual bool ShouldCollide([[maybe_unused]] ObjectLayer inLayer) const
35 {
36 return true;
37 }
38
39#ifdef JPH_TRACK_BROADPHASE_STATS
41 virtual String GetDescription() const
42 {
43 return "No Description";
44 }
45#endif // JPH_TRACK_BROADPHASE_STATS
46};
47
50{
51public:
53 virtual ~ObjectLayerPairFilter() = default;
54
56 virtual bool ShouldCollide([[maybe_unused]] ObjectLayer inLayer1, [[maybe_unused]] ObjectLayer inLayer2) const
57 {
58 return true;
59 }
60};
61
64{
65public:
67 DefaultObjectLayerFilter(const ObjectLayerPairFilter &inObjectLayerPairFilter, ObjectLayer inLayer) :
68 mObjectLayerPairFilter(inObjectLayerPairFilter),
69 mLayer(inLayer)
70 {
71 }
72
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
86private:
87 const ObjectLayerPairFilter & mObjectLayerPairFilter;
88 ObjectLayer mLayer;
89};
90
93{
94public:
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
107private:
108 ObjectLayer mLayer;
109};
110
#define JPH_NAMESPACE_END
Definition: Core.h:367
std::uint32_t uint32
Definition: Core.h:442
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
std::uint16_t uint16
Definition: Core.h:441
uint16 ObjectLayer
Definition: ObjectLayer.h:16
std::basic_string< char, std::char_traits< char >, STLAllocator< char > > String
Definition: STLAllocator.h:82
Default filter class that uses the pair filter in combination with a specified layer to filter layers...
Definition: ObjectLayer.h:64
virtual bool ShouldCollide(ObjectLayer inLayer) const override
Function to filter out object layers when doing collision query test (return true to allow testing ag...
Definition: ObjectLayer.h:81
DefaultObjectLayerFilter(const ObjectLayerPairFilter &inObjectLayerPairFilter, ObjectLayer inLayer)
Constructor.
Definition: ObjectLayer.h:67
DefaultObjectLayerFilter(const DefaultObjectLayerFilter &inRHS)
Copy constructor.
Definition: ObjectLayer.h:74
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition: NonCopyable.h:11
Filter class for object layers.
Definition: ObjectLayer.h:28
virtual bool ShouldCollide(ObjectLayer inLayer) const
Function to filter out object layers when doing collision query test (return true to allow testing ag...
Definition: ObjectLayer.h:34
virtual ~ObjectLayerFilter()=default
Destructor.
Filter class to test if two objects can collide based on their object layer. Used while finding colli...
Definition: ObjectLayer.h:50
virtual bool ShouldCollide(ObjectLayer inLayer1, ObjectLayer inLayer2) const
Returns true if two layers can collide.
Definition: ObjectLayer.h:56
virtual ~ObjectLayerPairFilter()=default
Destructor.
Allows objects from a specific layer only.
Definition: ObjectLayer.h:93
virtual bool ShouldCollide(ObjectLayer inLayer) const override
Function to filter out object layers when doing collision query test (return true to allow testing ag...
Definition: ObjectLayer.h:102
SpecifiedObjectLayerFilter(ObjectLayer inLayer)
Constructor.
Definition: ObjectLayer.h:96