Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
FixedConstraint.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 FixedConstraint.hpp
14 * @brief Fixed constraint component (0 DOF) - welds two bodies together
15 *
16 * A fixed constraint removes all degrees of freedom between two bodies,
17 * effectively welding them into a single rigid structure. This is useful
18 * for compound objects, breakable structures, and rigid attachments.
19 *
20 * @author @EngineSquared
21 * @version 0.1.1
22 * @date 2025-12-04
23 **************************************************************************/
24
25#pragma once
26
28#include <Engine.hpp>
29#include <glm/glm.hpp>
30
31namespace Physics::Component {
32
72 //========================================================================
73 // Constraint Bodies
74 //========================================================================
75
83
90
91 //========================================================================
92 // Attachment Points
93 //========================================================================
94
101 glm::vec3 localPointA = glm::vec3(0.0f);
102
109 glm::vec3 localPointB = glm::vec3(0.0f);
110
111 //========================================================================
112 // Settings
113 //========================================================================
114
119
120 //========================================================================
121 // Runtime State
122 //========================================================================
123
131 bool broken = false;
132
133 //========================================================================
134 // Factory Methods
135 //========================================================================
136
147 [[nodiscard]] static FixedConstraint
148 Create(Engine::EntityId a, Engine::EntityId b, const glm::vec3 &pointA = glm::vec3(0.0f),
149 const glm::vec3 &pointB = glm::vec3(0.0f),
150 const ConstraintSettings &constraintSettings = ConstraintSettings::Rigid())
151 {
152 FixedConstraint constraint;
153 constraint.bodyA = a;
154 constraint.bodyB = b;
155 constraint.localPointA = pointA;
156 constraint.localPointB = pointB;
157 constraint.settings = constraintSettings;
158 constraint.broken = false;
159 return constraint;
160 }
161
172 [[nodiscard]] static FixedConstraint
173 CreateToWorld(Engine::EntityId body, const glm::vec3 &worldPoint,
174 const ConstraintSettings &constraintSettings = ConstraintSettings::Rigid())
175 {
176 FixedConstraint constraint;
177 constraint.bodyA = body;
178 constraint.bodyB = Engine::EntityId::Null(); // P Invalid entity = world
179 constraint.localPointA = glm::vec3(0.0f);
180 constraint.localPointB = worldPoint; // Used as world position
181 constraint.settings = constraintSettings;
182 constraint.broken = false;
183 return constraint;
184 }
185
190 [[nodiscard]] bool IsWorldConstraint() const { return bodyB.IsNull(); }
191};
192
193} // namespace Physics::Component
Definition BoxCollider.hpp:27
Represents a unique identifier for an entity in the Engine's entity-component system....
Definition EntityId.hpp:14
static constexpr EntityId Null()
Returns a null EntityId. A null EntityId is an EntityId that does not correspond to any valid entity ...
Definition EntityId.hpp:40
Definition ConstraintSettings.hpp:52
static ConstraintSettings Rigid()
Create settings for a perfectly rigid constraint.
Definition ConstraintSettings.hpp:136
Definition FixedConstraint.hpp:71
ConstraintSettings settings
Constraint settings (stiffness, damping, breaking thresholds).
Definition FixedConstraint.hpp:118
bool IsWorldConstraint() const
Check if this is a world constraint (body to world, not body to body).
Definition FixedConstraint.hpp:190
bool broken
Whether this constraint has been broken.
Definition FixedConstraint.hpp:131
Engine::EntityId bodyB
Second body entity (the entity to connect to).
Definition FixedConstraint.hpp:89
glm::vec3 localPointA
Attachment point on bodyA in local body space.
Definition FixedConstraint.hpp:101
glm::vec3 localPointB
Attachment point on bodyB in local body space.
Definition FixedConstraint.hpp:109
static FixedConstraint CreateToWorld(Engine::EntityId body, const glm::vec3 &worldPoint, const ConstraintSettings &constraintSettings=ConstraintSettings::Rigid())
Create a fixed constraint from one body to the world.
Definition FixedConstraint.hpp:173
static FixedConstraint Create(Engine::EntityId a, Engine::EntityId b, const glm::vec3 &pointA=glm::vec3(0.0f), const glm::vec3 &pointB=glm::vec3(0.0f), const ConstraintSettings &constraintSettings=ConstraintSettings::Rigid())
Create a fixed constraint between two bodies.
Definition FixedConstraint.hpp:148
Engine::EntityId bodyA
First body entity (the entity this component is attached to).
Definition FixedConstraint.hpp:82