Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
ConstraintInternal.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 ConstraintInternal.hpp
14 * @brief Internal constraint component for Jolt Physics data storage
15 *
16 * This component is automatically created/destroyed via entt hooks when
17 * constraint components are added/removed. Users should never directly
18 * interact with this component.
19 *
20 * @author @EngineSquared
21 * @version 0.1.1
22 * @date 2025-12-04
23 **************************************************************************/
24
25#pragma once
26
27// clang-format off
28#include <Jolt/Jolt.h>
29// clang-format on
30
31#include <Jolt/Physics/Constraints/Constraint.h>
32
33namespace Physics::Component {
34
38enum class ConstraintType : uint8_t {
42};
43
54 JPH::Constraint *constraint = nullptr;
55
58
60 bool broken = false;
61
63 float breakForce = 0.0f;
64 float breakTorque = 0.0f;
65
69 ConstraintInternal() = default;
70
76 ConstraintInternal(JPH::Constraint *c, ConstraintType t) : constraint(c), type(t) {}
77
85 ConstraintInternal(JPH::Constraint *c, ConstraintType t, float force, float torque)
86 : constraint(c), type(t), breakForce(force), breakTorque(torque)
87 {
88 }
89
94 [[nodiscard]] bool IsValid() const { return constraint != nullptr; }
95
100 [[nodiscard]] bool IsBreakable() const { return breakForce > 0.0f || breakTorque > 0.0f; }
101};
102
103} // namespace Physics::Component
Definition BoxCollider.hpp:27
ConstraintType
Enumeration of supported constraint types.
Definition ConstraintInternal.hpp:38
@ Distance
Distance constraint (5 DOF) - rope/spring with min/max distance.
Definition ConstraintInternal.hpp:40
@ Point
Point constraint (3 DOF) - ball-and-socket joint.
Definition ConstraintInternal.hpp:41
@ Fixed
Fixed constraint (0 DOF) - welds two bodies together.
Definition ConstraintInternal.hpp:39
JPH::Constraint * constraint
Pointer to the Jolt constraint object.
Definition ConstraintInternal.hpp:54
bool broken
Whether this constraint has been broken (exceeded force/torque thresholds).
Definition ConstraintInternal.hpp:60
ConstraintInternal(JPH::Constraint *c, ConstraintType t, float force, float torque)
Construct with constraint pointer, type, and breaking thresholds.
Definition ConstraintInternal.hpp:85
ConstraintInternal(JPH::Constraint *c, ConstraintType t)
Construct with constraint pointer and type.
Definition ConstraintInternal.hpp:76
float breakForce
Settings used to create this constraint (for force monitoring).
Definition ConstraintInternal.hpp:63
bool IsValid() const
Check if this component has a valid constraint.
Definition ConstraintInternal.hpp:94
bool IsBreakable() const
Check if this constraint is breakable.
Definition ConstraintInternal.hpp:100
ConstraintInternal()=default
Default constructor (invalid constraint).
float breakTorque
Definition ConstraintInternal.hpp:64
ConstraintType type
Type of the constraint for runtime identification.
Definition ConstraintInternal.hpp:57