Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
RigidBody.hpp
Go to the documentation of this file.
1/**************************************************************************
2 * EngineSquared v0.1.1
3 *
4 * EngineSquared is a software package, part of the Engine² organization.
5 *
6 * This file is part of the EngineSquared project that is under MIT License.
7 * Copyright © 2025-present by @EngineSquared, All rights reserved.
8 *
9 * EngineSquared is a free software: you can redistribute it and/or modify
10 * it under the terms of the MIT License. See the project's LICENSE file for
11 * the full license text and details.
12 *
13 * @file RigidBody.hpp
14 * @brief Public RigidBody component for Jolt Physics simulation
15 *
16 * This component encapsulates all Jolt Physics settings and provides
17 * a clean API for users. Internal Jolt data is managed via RigidBodyInternal.
18 *
19 * @author @EngineSquared
20 * @version 0.1.1
21 * @date 2025-10-28
22 **************************************************************************/
23
24#pragma once
25
26#include "utils/Layers.hpp"
27#include <Jolt/Physics/Body/MotionType.h>
28#include <Jolt/Physics/EActivation.h>
29#include <cstdint>
30
31namespace Physics::Component {
32
36using MotionType = JPH::EMotionType;
37
41using Activation = JPH::EActivation;
42
64struct RigidBody {
65 //========================================================================
66 // Motion Properties
67 //========================================================================
68
70 MotionType motionType = MotionType::Dynamic;
71
73 Activation activation = Activation::Activate;
74
75 //========================================================================
76 // Mass Properties
77 //========================================================================
78
80 float mass = 1.0f;
81
83 bool allowSleeping = true;
84
85 //========================================================================
86 // Material Properties
87 //========================================================================
88
90 float friction = 0.5f;
91
93 float restitution = 0.0f;
94
96 float linearDamping = 0.05f;
97
99 float angularDamping = 0.05f;
100
101 //========================================================================
102 // Gravity
103 //========================================================================
104
106 float gravityFactor = 1.0f;
107
108 //========================================================================
109 // Layer (for collision filtering)
110 //========================================================================
111
114 uint16_t objectLayer = 0;
115
116 //========================================================================
117 // Helper Methods
118 //========================================================================
119
124 {
125 RigidBody rb;
126 rb.motionType = MotionType::Static;
127 rb.activation = Activation::DontActivate;
129 rb.mass = 0.0f;
130 return rb;
131 }
132
137 {
138 RigidBody rb;
139 rb.motionType = MotionType::Kinematic;
140 rb.activation = Activation::Activate;
142 rb.mass = 0.0f;
143 return rb;
144 }
145
150 static RigidBody CreateDynamic(float bodyMass = 1.0f)
151 {
152 RigidBody rb;
153 rb.motionType = MotionType::Dynamic;
154 rb.activation = Activation::Activate;
156 rb.mass = bodyMass;
157 return rb;
158 }
159};
160
161} // namespace Physics::Component
Definition BoxCollider.hpp:27
JPH::EActivation Activation
Activation mode for bodies when added to the physics world.
Definition RigidBody.hpp:41
JPH::EMotionType MotionType
Motion type for rigid bodies.
Definition RigidBody.hpp:36
static constexpr JPH::ObjectLayer MOVING
Definition Layers.hpp:12
static constexpr JPH::ObjectLayer NON_MOVING
Definition Layers.hpp:11
Definition RigidBody.hpp:64
MotionType motionType
Motion type (Static, Kinematic, or Dynamic).
Definition RigidBody.hpp:70
static RigidBody CreateKinematic()
Create a kinematic rigid body.
Definition RigidBody.hpp:136
Activation activation
Activation mode when added to world.
Definition RigidBody.hpp:73
float linearDamping
Linear damping (resistance to linear motion).
Definition RigidBody.hpp:96
float gravityFactor
Gravity factor (1.0 = normal gravity, 0.0 = no gravity).
Definition RigidBody.hpp:106
float restitution
Restitution/bounciness [0, 1].
Definition RigidBody.hpp:93
uint16_t objectLayer
Definition RigidBody.hpp:114
static RigidBody CreateDynamic(float bodyMass=1.0f)
Create a dynamic rigid body.
Definition RigidBody.hpp:150
float friction
Friction coefficient [0, 1].
Definition RigidBody.hpp:90
float mass
Mass in kg (only for Dynamic bodies).
Definition RigidBody.hpp:80
float angularDamping
Angular damping (resistance to rotation).
Definition RigidBody.hpp:99
bool allowSleeping
Allow body to go to sleep when inactive.
Definition RigidBody.hpp:83
static RigidBody CreateStatic()
Create a static rigid body.
Definition RigidBody.hpp:123