PixelBullet
0.0.1
A C++ game engine
Loading...
Searching...
No Matches
engine
include
pixelbullet
physics
physics_types.h
1
#pragma once
2
3
#include <glm/glm.hpp>
4
#include <glm/gtc/quaternion.hpp>
5
6
#include <cstdint>
7
8
namespace
pixelbullet
9
{
10
enum class
ColliderShapeType
11
{
12
Box,
13
Sphere,
14
Capsule,
15
};
16
17
enum class
RigidBodyMotionType
18
{
19
Static,
20
Kinematic,
21
Dynamic,
22
};
23
24
struct
PhysicsBodyHandle
25
{
26
uint64_t value = 0;
27
28
[[nodiscard]]
explicit
operator
bool()
const
noexcept
29
{
30
return
value != 0;
31
}
32
33
[[nodiscard]]
bool
operator==(
const
PhysicsBodyHandle
&)
const
noexcept
=
default
;
34
};
35
36
struct
PhysicsBodyPose
37
{
38
glm::vec3 position = glm::vec3(0.0f);
39
glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
40
41
[[nodiscard]]
bool
operator==(
const
PhysicsBodyPose
&)
const
noexcept
=
default
;
42
};
43
44
struct
PhysicsColliderDescription
45
{
46
ColliderShapeType shape = ColliderShapeType::Box;
47
glm::vec3 box_half_extents = glm::vec3(0.5f);
48
float
sphere_radius = 0.5f;
49
float
capsule_radius = 0.5f;
50
// Half-height of the cylindrical capsule section, excluding the hemispherical caps.
51
float
capsule_half_height = 0.5f;
52
glm::vec3 center = glm::vec3(0.0f);
53
float
friction = 0.5f;
54
float
restitution = 0.0f;
55
bool
is_trigger =
false
;
56
57
[[nodiscard]]
bool
operator==(
const
PhysicsColliderDescription
&)
const
noexcept
=
default
;
58
};
59
60
enum class
PhysicsTriggerEventType
61
{
62
Enter,
63
Exit,
64
};
65
66
struct
PhysicsTriggerEvent
67
{
68
PhysicsBodyHandle
trigger_body{};
69
PhysicsBodyHandle
other_body{};
70
PhysicsTriggerEventType type = PhysicsTriggerEventType::Enter;
71
72
[[nodiscard]]
bool
operator==(
const
PhysicsTriggerEvent
&)
const
noexcept
=
default
;
73
};
74
75
struct
PhysicsBodyCreateInfo
76
{
77
PhysicsBodyPose
pose;
78
PhysicsColliderDescription
collider;
79
bool
has_rigid_body =
false
;
80
RigidBodyMotionType motion_type = RigidBodyMotionType::Static;
81
float
mass = 1.0f;
82
float
linear_damping = 0.05f;
83
float
angular_damping = 0.05f;
84
float
gravity_scale = 1.0f;
85
86
[[nodiscard]]
bool
operator==(
const
PhysicsBodyCreateInfo
&)
const
noexcept
=
default
;
87
};
88
89
struct
PhysicsSweepHit
90
{
91
PhysicsBodyHandle
body{};
92
glm::vec3 position = glm::vec3(0.0f);
93
glm::vec3 normal = glm::vec3(0.0f, 1.0f, 0.0f);
94
float
fraction = 0.0f;
95
float
penetration_depth = 0.0f;
96
97
[[nodiscard]]
bool
operator==(
const
PhysicsSweepHit
&)
const
noexcept
=
default
;
98
};
99
100
struct
PhysicsRayHit
101
{
102
PhysicsBodyHandle
body{};
103
glm::vec3 position = glm::vec3(0.0f);
104
glm::vec3 normal = glm::vec3(0.0f, 1.0f, 0.0f);
105
float
fraction = 0.0f;
106
107
[[nodiscard]]
bool
operator==(
const
PhysicsRayHit
&)
const
noexcept
=
default
;
108
};
109
}
// namespace pixelbullet
pixelbullet::PhysicsBodyCreateInfo
Definition
physics_types.h:76
pixelbullet::PhysicsBodyHandle
Definition
physics_types.h:25
pixelbullet::PhysicsBodyPose
Definition
physics_types.h:37
pixelbullet::PhysicsColliderDescription
Definition
physics_types.h:45
pixelbullet::PhysicsRayHit
Definition
physics_types.h:101
pixelbullet::PhysicsSweepHit
Definition
physics_types.h:90
pixelbullet::PhysicsTriggerEvent
Definition
physics_types.h:67
Generated by
1.16.1