Toast Engine
Loading...
Searching...
No Matches
rigidbody.hpp
1
8
9#pragma once
10#include "../body.hpp"
11#include "../collision.hpp"
13#include "../shape.hpp"
14
16#include <vector>
17
18namespace physics {
19
20class Simulator;
21
22class [[ToastNode, Hidden, Interface, Icon("PhysicsBody"), Color("Green")]] TOAST_API Rigidbody : public toast::Node3D {
23 friend class Simulator;
24
25public:
26 signals::Signal<toast::Box<toast::Node>> contact_begin;
27 signals::Signal<toast::Box<toast::Node>> contact_end;
28
29 [[Reflect, Layers("excluded"), Name("Layers")]]
30 uint32_t included = 1; // Default
31
32 [[Reflect, LayersExcluded]]
33 uint32_t excluded = 0;
34
35 [[Reflect]]
36 void setLayers(int included_layers, int excluded_layers);
37
38 [[Reflect]]
39 void includeLayer(int layer, bool value = true);
40
41 [[Reflect]]
42 void excludeLayer(int layer, bool value = true);
43
44protected:
45 explicit Rigidbody(BodyType type) : m_body_type(type) { }
46
47 virtual void configureBodyDescriptor(BodyDescriptor& descriptor) const { }
48
49 [[nodiscard]]
50 auto bodyID() const noexcept -> BodyID {
51 return m_body;
52 }
53
54 [[Reflect]]
56
57 [[Reflect, Name("Lock X"), Group("Position Locks")]]
58 bool lock_pos_x = false;
59 [[Reflect, Name("Lock Y"), Group("Position Locks")]]
60 bool lock_pos_y = false;
61 [[Reflect, Name("Lock Z"), Group("Position Locks")]]
62 bool lock_pos_z = false;
63 [[Reflect, Name("Lock X"), Group("Rotation Locks")]]
64 bool lock_rot_x = false;
65 [[Reflect, Name("Lock Y"), Group("Rotation Locks")]]
66 bool lock_rot_y = false;
67 [[Reflect, Name("Lock Z"), Group("Rotation Locks")]]
68 bool lock_rot_z = false;
69
70private:
71 struct ActiveContact {
72 BodyID other_body;
73 toast::Box<toast::Node> other_node;
74 uint32_t shape_pair_count = 0;
75 };
76
77 void updateInspectorMessages() override;
78 void begin();
79 void end();
80 void onEnable();
81 void onDisable();
82 void handleContactBegin(const BroadPhasePair& pair);
83 void handleContactEnd(const BroadPhasePair& pair);
84
85 [[nodiscard]]
86 auto descriptor() const -> BodyDescriptor;
87
88 void assignBody(BodyID body) noexcept { m_body = body; }
89
90 void applyPhysicsTransform(const glm::vec3& position, const glm::quat& rotation);
91
92 void onEditorTransformChanged() override;
93
94 BodyType m_body_type;
95 BodyID m_body;
96 std::vector<ActiveContact> m_active_contacts;
97 bool m_registration_requested = false;
98};
99
100}
Body identifiers, creation data, and copied runtime state.
Type-safe smart pointer for assets.
Definition core_types.hpp:149
Definition simulator.hpp:57
Intrusive reference-counted handle to a Node.
Definition box.hpp:35
Definition node_3d.hpp:25
auto type() const noexcept -> NodeType
Definition node.hpp:192
Canonical collision-pair records shared by broad and narrow phases.
Node with 3D spatial transforms.
TODO: Brief description of the file's purpose.
Shape identifiers, geometry, and runtime records.
Definition body.hpp:32
Definition body.hpp:20
Definition collision.hpp:24