TheAtlasEngine
 
Loading...
Searching...
No Matches
jolt_broad_phase.hpp
1#pragma once
2
3#include <drivers/jolt-cpp/jolt-imports.hpp>
4
5namespace atlas::physics {
6
17 // This should eventually have a pipeline for the user to create masks.
18 enum class ObjectLayer : std::uint8_t {
19 NonMoving = 0,
20 Moving = 1,
21 NumLayers
22 };
23
24 enum class BroadPhaseLayers : std::uint8_t {
25 NonMoving = 0,
26 Moving = 1,
27 NumLayers
28 };
29
39 : public JPH::BroadPhaseLayerInterface {
40 public:
42
49 [[nodiscard]] uint32_t GetNumBroadPhaseLayers() const override {
50 return (uint32_t)(BroadPhaseLayers::NumLayers);
51 }
52
63 [[nodiscard]] JPH::BroadPhaseLayer GetBroadPhaseLayer(
64 JPH::ObjectLayer p_in_layer) const override {
65 JPH_ASSERT(p_in_layer < (JPH::ObjectLayer)ObjectLayer::NumLayers);
66 return m_object_to_broadphase[p_in_layer];
67 }
68
69#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED)
78 [[nodiscard]] const char* GetBroadPhaseLayerName(
79 JPH::BroadPhaseLayer p_in_layer) const override {
80 switch (p_in_layer.GetValue()) {
81 case (JPH::BroadPhaseLayer::Type)(BroadPhaseLayers::NonMoving):
82 return "NonMoving";
83 case (JPH::BroadPhaseLayer::Type)(BroadPhaseLayers::Moving):
84 return "Moving";
85 default:
86 JPH_ASSERT(false);
87 return "Unknown";
88 }
89 }
90#endif
91
92 private:
93 // The list of organizational layers
94 std::vector<JPH::BroadPhaseLayer> m_object_to_broadphase{
95 JPH::BroadPhaseLayer((uint8_t)(BroadPhaseLayers::NonMoving)),
96 JPH::BroadPhaseLayer((uint8_t)(BroadPhaseLayers::Moving))
97
98 };
99 };
100
118 : public JPH::ObjectVsBroadPhaseLayerFilter {
119 public:
120 [[nodiscard]] bool ShouldCollide(
121 JPH::ObjectLayer p_in_layer1,
122 JPH::BroadPhaseLayer p_in_layer2) const override {
123 switch (p_in_layer1) {
124 case (int)(ObjectLayer::NonMoving):
125 return p_in_layer2 ==
126 JPH::BroadPhaseLayer((JPH::BroadPhaseLayer::Type)(
127 BroadPhaseLayers::Moving));
128 case (int)ObjectLayer::Moving:
129 return true;
130 default:
131 JPH_ASSERT(false);
132 return false;
133 }
134 }
135 };
136
144 class object_layer_pair_filter final : public JPH::ObjectLayerPairFilter {
145 public:
146 [[nodiscard]] bool ShouldCollide(
147 JPH::ObjectLayer p_in_object1,
148 JPH::ObjectLayer p_in_object2) const override {
149 switch (p_in_object1) {
150 case (int)(ObjectLayer::NonMoving):
151 return p_in_object2 == (int)(ObjectLayer::Moving);
152 case (int)(ObjectLayer::Moving):
153 return true;
154 default:
155 JPH_ASSERT(false);
156 return false;
157 }
158 }
159 };
160
161}
This class is made to control the broadphase layer. Filters can be added to it to create a better and...
Definition jolt_broad_phase.hpp:39
JPH::BroadPhaseLayer GetBroadPhaseLayer(JPH::ObjectLayer p_in_layer) const override
Gives the caller access to the broadphase object. Allowing for some manipulation on how those interac...
Definition jolt_broad_phase.hpp:63
uint32_t GetNumBroadPhaseLayers() const override
Get the Number of layers that exsist in the current context. Static for now.
Definition jolt_broad_phase.hpp:49
This goes into more detailed ways of filtering, where the object collisions may be defined be what th...
Definition jolt_broad_phase.hpp:144
This is used to tell Jolt what can or cannot collide. As of right now the list is static therfore the...
Definition jolt_broad_phase.hpp:118
Types are still be filled out. When this is completed to_jph() can be removed.
Definition jolt_broad_phase.hpp:5
ObjectLayer
This contains a few important comparisons having to do with setting up the oct-trees correctly as wel...
Definition jolt_broad_phase.hpp:18