Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
broad_phase.hpp
Go to the documentation of this file.
1
5
6
#pragma once
7
8
#include "
aabb_tree.hpp
"
9
#include "
collision.hpp
"
10
#include "
collision_world.hpp
"
11
12
#include <optional>
13
#include <utility>
14
#include <vector>
15
16
namespace
physics {
17
18
struct
ShapeBoundsUpdate
{
19
ShapeID
shape;
20
AABB
bounds;
21
bool
active =
false
;
22
};
23
24
struct
BroadPhaseStats
{
25
size_t
input_shapes = 0;
26
size_t
active_shapes = 0;
27
size_t
bounds_jobs = 0;
28
size_t
inserted_leaves = 0;
29
size_t
reinserted_leaves = 0;
30
size_t
removed_leaves = 0;
31
size_t
skipped_refits = 0;
32
size_t
skipped_self_queries = 0;
33
size_t
queries = 0;
34
size_t
query_hits = 0;
35
size_t
pair_records = 0;
36
size_t
candidate_pairs = 0;
37
size_t
duplicate_pairs = 0;
38
size_t
rejected_invalid_shapes = 0;
39
size_t
rejected_disabled_shapes = 0;
40
size_t
rejected_same_body = 0;
41
size_t
rejected_invalid_bodies = 0;
42
size_t
rejected_immovable_bodies = 0;
43
size_t
rejected_layers = 0;
44
size_t
tree_nodes = 0;
45
};
46
47
[[nodiscard]]
48
auto
worldShapeBounds(
const
Body
& body,
const
Shape
& shape) ->
AABB
;
49
50
class
BroadPhase
{
51
public
:
52
[[nodiscard]]
53
auto
calculateBounds(
CollisionWorldView
world,
size_t
begin,
size_t
end)
const
-> std::vector<ShapeBoundsUpdate>;
54
55
[[nodiscard]]
56
auto
findPairs(
CollisionWorldView
world) -> std::vector<BroadPhasePair>;
57
58
[[nodiscard]]
59
auto
queryBounds(
const
AABB
& bounds)
const
-> std::vector<ShapeID>;
60
61
template
<
typename
Visit>
62
void
raycast(glm::vec3 origin, glm::vec3 inv_dir,
float
max_distance, Visit&& visit)
const
{
63
m_tree.raycast(origin, inv_dir, max_distance, std::forward<Visit>(visit));
64
}
65
66
[[nodiscard]]
67
auto
debugNodes()
const
-> std::vector<AABBTreeDebugNode>;
68
[[nodiscard]]
69
auto
stats()
const
->
const
BroadPhaseStats
&;
70
71
private
:
72
struct
ShapeLeaf {
73
TreeNodeID node = null_node;
74
uint32_t generation = 0;
75
};
76
78
[[nodiscard]]
79
auto
testPair(
CollisionWorldView
world,
ShapeID
shape_a,
ShapeID
shape_b,
BroadPhaseStats
& stats)
80
-> std::optional<BroadPhasePair>;
81
82
AABBTree
m_tree;
83
std::vector<ShapeLeaf> m_shape_leaves;
84
BroadPhaseStats
m_stats;
85
};
86
87
}
aabb_tree.hpp
TODO: Brief description of the file's purpose.
physics::AABBTree
Definition
aabb_tree.hpp:52
physics::BroadPhase
Definition
broad_phase.hpp:50
collision.hpp
Canonical collision-pair records shared by broad and narrow phases.
collision_world.hpp
Read-only access to physics data used by collision detection.
physics::AABB
Definition
aabb.hpp:16
physics::Body
Definition
body.hpp:60
physics::BroadPhaseStats
Definition
broad_phase.hpp:24
physics::CollisionWorldView
Definition
collision_world.hpp:16
physics::ShapeBoundsUpdate
Definition
broad_phase.hpp:18
physics::ShapeID
Definition
shape.hpp:29
physics::Shape
Definition
shape.hpp:161
engine
src
toast
physics
broad_phase.hpp
Generated by
1.17.0