Toast Engine
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
16namespace physics {
17
19 ShapeID shape;
20 AABB bounds;
21 bool active = false;
22};
23
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]]
48auto worldShapeBounds(const Body& body, const Shape& shape) -> AABB;
49
51public:
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
71private:
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}
TODO: Brief description of the file's purpose.
Definition aabb_tree.hpp:52
Definition broad_phase.hpp:50
Canonical collision-pair records shared by broad and narrow phases.
Read-only access to physics data used by collision detection.
Definition aabb.hpp:16
Definition body.hpp:60
Definition broad_phase.hpp:24
Definition collision_world.hpp:16
Definition broad_phase.hpp:18
Definition shape.hpp:29
Definition shape.hpp:161