Toast Engine
Loading...
Searching...
No Matches
body.hpp
Go to the documentation of this file.
1
7
8#pragma once
9
10#include "layers.hpp"
11
12#include <compare>
13#include <cstdint>
14#include <glm/glm.hpp>
15#include <glm/gtc/quaternion.hpp>
16#include <limits>
17
18namespace physics {
19
20struct BodyID {
21 uint32_t slot = std::numeric_limits<uint32_t>::max();
22 uint32_t generation = 0;
23 auto operator<=>(const BodyID&) const = default;
24};
25
26enum class BodyType : uint8_t {
27 static_body,
28 dynamic_body,
29 kinematic_body
30};
31
33 BodyType type = BodyType::dynamic_body;
34 bool allow_sleep = true;
35 glm::vec3 position = {};
36 glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
37 glm::vec3 linear_velocity = {};
38 glm::vec3 angular_velocity = {};
39 float mass = 1.0f;
40 float gravity_scale = 1.0f;
41 glm::bvec3 lock_position = glm::bvec3(false);
42 glm::bvec3 lock_rotation = glm::bvec3(false);
43 float linear_damping = 0.0f;
44 float angular_damping = 0.0f;
45 float drag_scale = 1.0f;
46 LayerFilter layers;
47};
48
49struct BodyState {
50 BodyType type = BodyType::dynamic_body;
51 bool awake = true;
52 glm::vec3 position = {};
53 glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
54 glm::vec3 previous_position = {};
55 glm::quat previous_rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
56 glm::vec3 linear_velocity = {};
57 glm::vec3 angular_velocity = {};
58};
59
60struct Body {
61 BodyType type = BodyType::dynamic_body;
62 bool enabled = true;
63 bool awake = true;
64 bool allow_sleep = true;
65 bool sleep_locked = false;
66 float sleep_timer = 0.0f;
67 float asleep_seconds = 0.0f;
68 glm::vec3 sleep_anchor_center = {};
69 glm::quat sleep_anchor_rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
70 glm::vec3 position = {};
71 glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
72 glm::vec3 previous_position = {};
73 glm::quat previous_rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
74 glm::vec3 linear_velocity = {};
75 glm::vec3 angular_velocity = {};
76 float inverse_mass = 1.0f;
77 float gravity_scale = 1.0f;
78 glm::mat3 inverse_inertia_local = {0.0f};
79 glm::mat3 inverse_inertia_world = {0.0f};
80 glm::vec3 local_center_of_mass = {};
81 float extent_radius = 0.0f;
82 glm::bvec3 lock_position = glm::bvec3(false);
83 glm::bvec3 lock_rotation = glm::bvec3(false);
84 float linear_damping = 0.0f;
85 float angular_damping = 0.0f;
86 float drag_scale = 1.0f;
87 LayerFilter layers;
88 float drag_coefficient = 0.0f;
89 float drag_area_base = 0.0f;
90 glm::vec3 drag_area_axis = {};
91
92 [[nodiscard]]
93 auto worldCenterOfMass() const -> glm::vec3 {
94 return position + rotation * local_center_of_mass;
95 }
96};
97
98struct BodySlot {
99 Body body;
100 uint32_t generation = 1;
101 bool occupied = false;
102};
103
104}
Collision layers.
Definition body.hpp:32
Definition body.hpp:20
Definition body.hpp:98
Definition body.hpp:49
Definition body.hpp:60
glm::bvec3 lock_position
Distance to the center of mass.
Definition body.hpp:82
Definition layers.hpp:36