PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
physics_types.h
1#pragma once
2
3#include "pixelbullet/serialization/glm_node.h"
4#include "pixelbullet/serialization/node.h"
5
6#include <glm/gtc/quaternion.hpp>
7
8#include <cstdint>
9
10namespace pixelbullet
11{
12enum class ColliderShapeType
13{
14 Box,
15 Sphere,
16 Capsule,
17};
18
19enum class RigidBodyMotionType
20{
21 Static,
22 Kinematic,
23 Dynamic,
24};
25
27{
28 uint64_t value = 0;
29
30 [[nodiscard]] explicit operator bool() const noexcept
31 {
32 return value != 0;
33 }
34
35 [[nodiscard]] bool operator==(const PhysicsBodyHandle&) const noexcept = default;
36};
37
39{
40 glm::vec3 position = glm::vec3(0.0f);
41 glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
42
43 [[nodiscard]] bool operator==(const PhysicsBodyPose&) const noexcept = default;
44};
45
47{
48 ColliderShapeType shape = ColliderShapeType::Box;
49 glm::vec3 box_half_extents = glm::vec3(0.5f);
50 float sphere_radius = 0.5f;
51 float capsule_radius = 0.5f;
52 float capsule_half_height = 0.5f;
53 glm::vec3 center = glm::vec3(0.0f);
54 float friction = 0.5f;
55 float restitution = 0.0f;
56 bool is_trigger = false;
57
58 [[nodiscard]] bool operator==(const PhysicsColliderDescription&) const noexcept = default;
59};
60
61enum class PhysicsTriggerEventType
62{
63 Enter,
64 Exit,
65};
66
68{
69 PhysicsBodyHandle trigger_body{};
70 PhysicsBodyHandle other_body{};
71 PhysicsTriggerEventType type = PhysicsTriggerEventType::Enter;
72
73 [[nodiscard]] bool operator==(const PhysicsTriggerEvent&) const noexcept = default;
74};
75
77{
78 PhysicsBodyPose pose;
80 bool has_rigid_body = false;
81 RigidBodyMotionType motion_type = RigidBodyMotionType::Static;
82 float mass = 1.0f;
83 float linear_damping = 0.05f;
84 float angular_damping = 0.05f;
85 float gravity_scale = 1.0f;
86
87 [[nodiscard]] bool operator==(const PhysicsBodyCreateInfo&) const noexcept = default;
88};
89
91{
92 PhysicsBodyHandle body{};
93 glm::vec3 position = glm::vec3(0.0f);
94 glm::vec3 normal = glm::vec3(0.0f, 1.0f, 0.0f);
95 float fraction = 0.0f;
96 float penetration_depth = 0.0f;
97
98 [[nodiscard]] bool operator==(const PhysicsSweepHit&) const noexcept = default;
99};
100
102{
103 PhysicsBodyHandle body{};
104 glm::vec3 position = glm::vec3(0.0f);
105 float fraction = 0.0f;
106
107 [[nodiscard]] bool operator==(const PhysicsRayHit&) const noexcept = default;
108};
109
110inline Node& operator<<(Node& node, const ColliderShapeType& value)
111{
112 switch (value)
113 {
114 case ColliderShapeType::Box:
115 node << "Box";
116 break;
117 case ColliderShapeType::Sphere:
118 node << "Sphere";
119 break;
120 case ColliderShapeType::Capsule:
121 node << "Capsule";
122 break;
123 }
124 return node;
125}
126
127inline const Node& operator>>(const Node& node, ColliderShapeType& value)
128{
129 std::string serialized;
130 node >> serialized;
131 if (serialized == "Sphere")
132 {
133 value = ColliderShapeType::Sphere;
134 }
135 else if (serialized == "Capsule")
136 {
137 value = ColliderShapeType::Capsule;
138 }
139 else
140 {
141 value = ColliderShapeType::Box;
142 }
143 return node;
144}
145
146inline Node& operator<<(Node& node, const RigidBodyMotionType& value)
147{
148 switch (value)
149 {
150 case RigidBodyMotionType::Static:
151 node << "Static";
152 break;
153 case RigidBodyMotionType::Kinematic:
154 node << "Kinematic";
155 break;
156 case RigidBodyMotionType::Dynamic:
157 node << "Dynamic";
158 break;
159 }
160 return node;
161}
162
163inline const Node& operator>>(const Node& node, RigidBodyMotionType& value)
164{
165 std::string serialized;
166 node >> serialized;
167 if (serialized == "Kinematic")
168 {
169 value = RigidBodyMotionType::Kinematic;
170 }
171 else if (serialized == "Dynamic")
172 {
173 value = RigidBodyMotionType::Dynamic;
174 }
175 else
176 {
177 value = RigidBodyMotionType::Static;
178 }
179 return node;
180}
181} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:45
Definition physics_types.h:77
Definition physics_types.h:27
Definition physics_types.h:39
Definition physics_types.h:47
Definition physics_types.h:102
Definition physics_types.h:91
Definition physics_types.h:68