Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
ConstraintSettings.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 ConstraintSettings.hpp
14 * @brief Common settings structure for all constraint types
15 *
16 * This file provides the base configuration for physics constraints including
17 * stiffness, damping, and breaking force/torque thresholds.
18 *
19 * @author @EngineSquared
20 * @version 0.1.1
21 * @date 2025-12-04
22 **************************************************************************/
23
24#pragma once
25
26#include <cmath>
27#include <cstdint>
28#include <limits>
29
30namespace Physics::Component {
31
53 //========================================================================
54 // Spring Properties
55 //========================================================================
56
67 float stiffness = 1.0f;
68
79 float damping = 0.0f;
80
81 //========================================================================
82 // Breaking Thresholds
83 //========================================================================
84
96 float breakForce = 0.0f;
97
109 float breakTorque = 0.0f;
110
111 //========================================================================
112 // Collision Settings
113 //========================================================================
114
122 bool enableCollision = false;
123
124 //========================================================================
125 // Factory Methods
126 //========================================================================
127
136 [[nodiscard]] static ConstraintSettings Rigid()
137 {
138 ConstraintSettings settings;
139 settings.stiffness = 1.0f;
140 settings.damping = 0.0f;
141 settings.breakForce = 0.0f;
142 settings.breakTorque = 0.0f;
143 return settings;
144 }
145
156 [[nodiscard]] static ConstraintSettings Breakable(float force, float torque = 0.0f)
157 {
158 ConstraintSettings settings;
159 settings.stiffness = 1.0f;
160 settings.damping = 0.0f;
161 settings.breakForce = force;
162 settings.breakTorque = torque;
163 return settings;
164 }
165
176 [[nodiscard]] static ConstraintSettings Soft(float stiff = 0.5f, float damp = 0.1f)
177 {
178 ConstraintSettings settings;
179 settings.stiffness = stiff;
180 settings.damping = damp;
181 settings.breakForce = 0.0f;
182 settings.breakTorque = 0.0f;
183 return settings;
184 }
185
190 [[nodiscard]] bool IsBreakable() const
191 {
192 const bool forceBreakable = breakForce > 0.0f && std::isfinite(breakForce);
193 const bool torqueBreakable = breakTorque > 0.0f && std::isfinite(breakTorque);
194 return forceBreakable || torqueBreakable;
195 }
196
201 [[nodiscard]] bool IsRigid() const { return stiffness >= 1.0f && damping <= 0.0f; }
202};
203
204} // namespace Physics::Component
Definition BoxCollider.hpp:27
Definition ConstraintSettings.hpp:52
static ConstraintSettings Breakable(float force, float torque=0.0f)
Create settings for a breakable constraint.
Definition ConstraintSettings.hpp:156
float stiffness
Constraint stiffness [0.0, 1.0].
Definition ConstraintSettings.hpp:67
bool enableCollision
Enable collision between constrained bodies.
Definition ConstraintSettings.hpp:122
float breakForce
Maximum force before constraint breaks (Newtons).
Definition ConstraintSettings.hpp:96
float damping
Constraint damping [0.0, 1.0].
Definition ConstraintSettings.hpp:79
static ConstraintSettings Soft(float stiff=0.5f, float damp=0.1f)
Create settings for a soft spring-like constraint.
Definition ConstraintSettings.hpp:176
float breakTorque
Maximum torque before constraint breaks (Newton-meters).
Definition ConstraintSettings.hpp:109
bool IsBreakable() const
Check if this constraint is breakable.
Definition ConstraintSettings.hpp:190
static ConstraintSettings Rigid()
Create settings for a perfectly rigid constraint.
Definition ConstraintSettings.hpp:136
bool IsRigid() const
Check if this constraint is rigid (no spring behavior).
Definition ConstraintSettings.hpp:201