@series-inc/rundot-syncplay 6.0.0-rc.2 → 6.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -0
- package/core/deterministic-math.d.ts +75 -1
- package/core/native/instance_ledger.hpp +1095 -0
- package/core/native/legacy_checkpoint_ids.hpp +107 -0
- package/core/native/physics/abi.cpp +39 -211
- package/core/native/physics/abi.hpp +2 -6
- package/core/native/physics/articulation.cpp +1434 -0
- package/core/native/physics/articulation.hpp +279 -0
- package/core/native/physics/buoyancy.cpp +1588 -0
- package/core/native/physics/buoyancy.hpp +254 -0
- package/core/native/physics/capsule_triangle.cpp +168 -0
- package/core/native/physics/capsule_triangle.hpp +40 -0
- package/core/native/physics/capsule_triangle_native.inc +291 -0
- package/core/native/physics/certified_sum.hpp +218 -0
- package/core/native/physics/character.cpp +638 -0
- package/core/native/physics/character.hpp +169 -0
- package/core/native/physics/checkpoint_schema.hpp +379 -0
- package/core/native/physics/cloth.cpp +1401 -0
- package/core/native/physics/cloth.hpp +357 -0
- package/core/native/physics/constraint_rows.cpp +363 -2
- package/core/native/physics/constraint_rows.hpp +72 -1
- package/core/native/physics/deformable_query.cpp +1630 -0
- package/core/native/physics/deformable_query.hpp +578 -0
- package/core/native/physics/distance.cpp +1166 -0
- package/core/native/physics/distance.hpp +151 -0
- package/core/native/physics/exact/exact-applied.cpp +101 -0
- package/core/native/physics/exact/exact-applied.hpp +112 -0
- package/core/native/physics/exact/exact-dyadic.cpp +691 -0
- package/core/native/physics/exact/exact-dyadic.hpp +58 -0
- package/core/native/physics/exact/exact-operation.hpp +51 -0
- package/core/native/physics/exact/word-core.hpp +262 -0
- package/core/native/physics/extended_abi.cpp +1242 -0
- package/core/native/physics/extended_abi.hpp +355 -0
- package/core/native/physics/extended_abi_characters.cpp +261 -0
- package/core/native/physics/extended_abi_characters.hpp +434 -0
- package/core/native/physics/extended_abi_core_features.cpp +713 -0
- package/core/native/physics/extended_abi_core_features.hpp +226 -0
- package/core/native/physics/extended_abi_deformables.cpp +448 -0
- package/core/native/physics/extended_abi_deformables.hpp +867 -0
- package/core/native/physics/extended_abi_vehicles.cpp +411 -0
- package/core/native/physics/extended_abi_vehicles.hpp +222 -0
- package/core/native/physics/fracture.cpp +1981 -0
- package/core/native/physics/fracture.hpp +460 -0
- package/core/native/physics/gear.cpp +563 -0
- package/core/native/physics/gear.hpp +158 -0
- package/core/native/physics/geometry_memory.hpp +476 -0
- package/core/native/physics/geometry_store.cpp +547 -0
- package/core/native/physics/geometry_store.hpp +134 -0
- package/core/native/physics/lag_compensation.cpp +1626 -0
- package/core/native/physics/lag_compensation.hpp +405 -0
- package/core/native/physics/mass_properties.cpp +449 -0
- package/core/native/physics/mass_properties.hpp +23 -0
- package/core/native/physics/material_pose.hpp +988 -0
- package/core/native/physics/particles.cpp +1065 -0
- package/core/native/physics/particles.hpp +261 -0
- package/core/native/physics/path_joint.cpp +781 -0
- package/core/native/physics/path_joint.hpp +154 -0
- package/core/native/physics/physics.cpp +13043 -1065
- package/core/native/physics/physics.hpp +184 -8
- package/core/native/physics/planar_deformable.cpp +2433 -0
- package/core/native/physics/planar_deformable.hpp +889 -0
- package/core/native/physics/platformer_2d.cpp +1353 -0
- package/core/native/physics/platformer_2d.hpp +340 -0
- package/core/native/physics/powered_ragdoll.cpp +1100 -0
- package/core/native/physics/powered_ragdoll.hpp +279 -0
- package/core/native/physics/powertrain.cpp +586 -0
- package/core/native/physics/powertrain.hpp +180 -0
- package/core/native/physics/pulley.cpp +311 -0
- package/core/native/physics/pulley.hpp +121 -0
- package/core/native/physics/ragdoll.cpp +586 -0
- package/core/native/physics/ragdoll.hpp +221 -0
- package/core/native/physics/rope.cpp +692 -0
- package/core/native/physics/rope.hpp +215 -0
- package/core/native/physics/rounded_convex.cpp +1229 -0
- package/core/native/physics/rounded_convex.hpp +287 -0
- package/core/native/physics/sdf_geometry.cpp +1821 -0
- package/core/native/physics/sdf_geometry.hpp +474 -0
- package/core/native/physics/soft_body.cpp +1449 -0
- package/core/native/physics/soft_body.hpp +328 -0
- package/core/native/physics/soft_collision.cpp +1862 -0
- package/core/native/physics/soft_collision.hpp +561 -0
- package/core/native/physics/surface_velocity.cpp +366 -0
- package/core/native/physics/surface_velocity.hpp +243 -0
- package/core/native/physics/topology.cpp +357 -39
- package/core/native/physics/topology.hpp +97 -6
- package/core/native/physics/tracks.cpp +1179 -0
- package/core/native/physics/tracks.hpp +404 -0
- package/core/native/physics/vehicle.cpp +629 -0
- package/core/native/physics/vehicle.hpp +191 -0
- package/core/native/physics/voxel_cooking.cpp +1929 -0
- package/core/native/physics/voxel_cooking.hpp +395 -0
- package/core/native/physics/world.cpp +5290 -854
- package/core/native/physics/world.hpp +796 -24
- package/core/native/physics/world_abi.cpp +3840 -306
- package/core/native/physics/world_abi.hpp +530 -10
- package/core/native/physics/world_digest_visitor.hpp +277 -0
- package/core/native/physics/world_strong_digest.hpp +557 -0
- package/core/native/physics2d/ccd.cpp +1302 -0
- package/core/native/physics2d/ccd.hpp +141 -0
- package/core/native/physics2d/checkpoint_memory.hpp +349 -0
- package/core/native/physics2d/clock_primitives.hpp +138 -0
- package/core/native/physics2d/commands.cpp +174 -28
- package/core/native/physics2d/commands.hpp +3 -1
- package/core/native/physics2d/compound.cpp +581 -0
- package/core/native/physics2d/compound.hpp +248 -0
- package/core/native/physics2d/contour.cpp +325 -0
- package/core/native/physics2d/contour.hpp +143 -0
- package/core/native/physics2d/frame_scope.hpp +124 -0
- package/core/native/physics2d/joint_phases.hpp +93 -0
- package/core/native/physics2d/joints.cpp +587 -150
- package/core/native/physics2d/joints.hpp +5 -0
- package/core/native/physics2d/memory_private.hpp +125 -0
- package/core/native/physics2d/owned_abi.cpp +1354 -879
- package/core/native/physics2d/owned_abi.hpp +190 -52
- package/core/native/physics2d/phase_test_hooks.hpp +17 -0
- package/core/native/physics2d/physics2d.cpp +2073 -120
- package/core/native/physics2d/physics2d.hpp +154 -2
- package/core/native/physics2d/queries.cpp +1055 -79
- package/core/native/physics2d/queries.hpp +71 -5
- package/core/native/physics2d/world.cpp +1313 -353
- package/core/native/physics2d/world.hpp +124 -13
- package/core/native/sha256/sha256_compress_unsigned.hpp +68 -0
- package/core/native/sha256/sha256_fips_constants.hpp +24 -0
- package/core/native/sha256/sha256_length.hpp +56 -0
- package/core/native/sha256/sha256_memo.hpp +48 -0
- package/core/native/sha256/sha256_sink.hpp +234 -0
- package/core/physics2d-owned.d.ts +466 -126
- package/core/runtime.d.ts +192 -19
- package/core/scripts/build-native.mjs +34 -0
- package/core/scripts/build-wasm-physics.mjs +272 -23
- package/core/scripts/extended-physics-profile.mjs +634 -0
- package/core/scripts/generate-physics2d-vectors.mjs +59 -0
- package/core/src/kinetix-deterministic-math.d.ts +2 -0
- package/core/src/kinetix-deterministic-math.mjs +513 -27
- package/core/src/kinetix-owned-runtime-adapter.mjs +788 -0
- package/core/src/kinetix-runtime-adapter-utils.mjs +54 -6
- package/core/src/kinetix-runtime-contract.mjs +55 -9
- package/core/src/kinetix-runtime-identity.mjs +12 -1
- package/core/src/kinetix-session-config.mjs +7 -2
- package/core/src/kinetix-state-report.mjs +36 -0
- package/core/src/physics/abi-constants.mjs +5 -4
- package/core/src/physics/articulation.d.mts +194 -0
- package/core/src/physics/articulation.mjs +1141 -0
- package/core/src/physics/buoyancy.d.mts +143 -0
- package/core/src/physics/buoyancy.mjs +268 -0
- package/core/src/physics/cloth.d.mts +314 -0
- package/core/src/physics/cloth.mjs +1156 -0
- package/core/src/physics/deformable-query.d.mts +217 -0
- package/core/src/physics/deformable-query.mjs +1412 -0
- package/core/src/physics/distance.d.mts +160 -0
- package/core/src/physics/distance.mjs +175 -0
- package/core/src/physics/extended-wasm-instance.d.mts +5 -0
- package/core/src/physics/extended-wasm-instance.mjs +48 -0
- package/core/src/physics/feature-api.d.mts +74 -0
- package/core/src/physics/feature-api.mjs +98 -0
- package/core/src/physics/fracture.d.mts +133 -0
- package/core/src/physics/fracture.mjs +1324 -0
- package/core/src/physics/gear.d.mts +585 -0
- package/core/src/physics/gear.mjs +955 -0
- package/core/src/physics/lag-compensation.d.mts +101 -0
- package/core/src/physics/lag-compensation.mjs +1100 -0
- package/core/src/physics/mass-properties.d.mts +114 -0
- package/core/src/physics/mass-properties.mjs +137 -468
- package/core/src/physics/particles.d.mts +177 -0
- package/core/src/physics/particles.mjs +758 -0
- package/core/src/physics/path-joint.d.mts +171 -0
- package/core/src/physics/path-joint.mjs +1231 -0
- package/core/src/physics/physics-extended-wasm-module.generated.mjs +13 -0
- package/core/src/physics/physics-profile-wasm-module.generated.mjs +48 -0
- package/core/src/physics/physics-wasm-module.generated.mjs +34 -5
- package/core/src/physics/powered-ragdoll.d.mts +188 -0
- package/core/src/physics/powered-ragdoll.mjs +1043 -0
- package/core/src/physics/powertrain.d.mts +260 -0
- package/core/src/physics/powertrain.mjs +621 -0
- package/core/src/physics/pulley.d.mts +98 -0
- package/core/src/physics/pulley.mjs +686 -0
- package/core/src/physics/ragdoll.d.mts +289 -0
- package/core/src/physics/ragdoll.mjs +1323 -0
- package/core/src/physics/rope.d.mts +241 -0
- package/core/src/physics/rope.mjs +319 -0
- package/core/src/physics/rounded-convex.d.mts +328 -0
- package/core/src/physics/rounded-convex.mjs +1404 -0
- package/core/src/physics/sdf-geometry.d.mts +117 -0
- package/core/src/physics/sdf-geometry.mjs +1204 -0
- package/core/src/physics/soft-body.d.mts +144 -0
- package/core/src/physics/soft-body.mjs +1285 -0
- package/core/src/physics/soft-collision.d.mts +651 -0
- package/core/src/physics/soft-collision.mjs +1883 -0
- package/core/src/physics/surface-velocity.d.mts +156 -0
- package/core/src/physics/surface-velocity.mjs +722 -0
- package/core/src/physics/tracks.d.mts +411 -0
- package/core/src/physics/tracks.mjs +1074 -0
- package/core/src/physics/vehicle.d.mts +3 -0
- package/core/src/physics/vehicle.mjs +172 -0
- package/core/src/physics/voxel-cooking.d.mts +219 -0
- package/core/src/physics/voxel-cooking.mjs +1499 -0
- package/core/src/physics/voxel-swept-quad.mjs +110 -0
- package/core/src/physics/wasm-instance.mjs +160 -23
- package/core/src/physics/world.d.mts +62 -0
- package/core/src/physics/world.mjs +1947 -152
- package/core/src/physics2d/body-state.mjs +218 -15
- package/core/src/physics2d/collision.d.mts +52 -0
- package/core/src/physics2d/collision.mjs +234 -0
- package/core/src/physics2d/compound.mjs +454 -0
- package/core/src/physics2d/contour-state.mjs +771 -0
- package/core/src/physics2d/feature-api.d.mts +211 -0
- package/core/src/physics2d/feature-api.mjs +3 -0
- package/core/src/physics2d/fluid-state.mjs +145 -0
- package/core/src/physics2d/joint-state.mjs +1 -1
- package/core/src/physics2d/owned-queries.mjs +3 -1
- package/core/src/physics2d/owned-transport.mjs +268 -122
- package/core/src/physics2d/owned-world.mjs +353 -230
- package/core/src/physics2d/particle-fluid.d.mts +152 -0
- package/core/src/physics2d/particle-fluid.mjs +233 -0
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +27 -10
- package/core/src/physics2d/query-codec.mjs +61 -13
- package/core/src/physics2d/submerged-geometry.d.mts +51 -0
- package/core/src/physics2d/submerged-geometry.mjs +186 -0
- package/core/src/runtime.mjs +23 -0
- package/core/src/shared/bytes.d.mts +2 -0
- package/core/src/shared/bytes.mjs +33 -0
- package/core/src/shared/sha256.d.mts +3 -0
- package/core/src/shared/sha256.mjs +72 -22
- package/core/units.d.ts +50 -0
- package/core/world.d.ts +253 -5
- package/dist/authority-room.d.ts +9 -0
- package/dist/authority-room.js +45 -16
- package/dist/browser.d.ts +6 -5
- package/dist/browser.js +4 -3
- package/dist/cadence.d.ts +7 -0
- package/dist/cadence.js +19 -0
- package/dist/canonical.d.ts +1 -0
- package/dist/canonical.js +3 -0
- package/dist/checksum-policy.d.ts +10 -0
- package/dist/checksum-policy.js +14 -0
- package/dist/collider-cooking-hull.d.ts +18 -0
- package/dist/collider-cooking-hull.js +248 -0
- package/dist/collider-cooking.d.ts +140 -0
- package/dist/collider-cooking.js +794 -0
- package/dist/compat/v5.d.ts +121 -0
- package/dist/compat/v5.js +479 -0
- package/dist/creator.d.ts +7 -6
- package/dist/creator.js +4 -3
- package/dist/game-byte-section.d.ts +36 -0
- package/dist/game-byte-section.js +350 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.js +9 -4
- package/dist/instant-replay.d.ts +27 -2
- package/dist/instant-replay.js +91 -16
- package/dist/lag-compensation3d.js +11 -10
- package/dist/match-log.d.ts +21 -4
- package/dist/match-log.js +92 -9
- package/dist/math.d.ts +2 -0
- package/dist/math.js +1 -0
- package/dist/modules/character-3d.d.ts +16 -1
- package/dist/modules/character-3d.js +42 -5
- package/dist/modules/combat.js +6 -5
- package/dist/movement3d-revision1.d.ts +2 -0
- package/dist/movement3d-revision1.js +973 -0
- package/dist/movement3d.d.ts +53 -3
- package/dist/movement3d.js +917 -247
- package/dist/networked-client.d.ts +15 -0
- package/dist/networked-client.js +378 -105
- package/dist/node.d.ts +3 -2
- package/dist/node.js +2 -1
- package/dist/physics/2d.d.ts +38 -4
- package/dist/physics/2d.js +57 -36
- package/dist/physics/3d.d.ts +755 -111
- package/dist/physics/3d.js +2355 -158
- package/dist/physics/edit-result-graph.d.ts +36 -0
- package/dist/physics/edit-result-graph.js +141 -0
- package/dist/physics/game-codec3d.d.ts +41 -0
- package/dist/physics/game-codec3d.js +544 -0
- package/dist/physics/installed-checkpoint3d.d.ts +13 -0
- package/dist/physics/installed-checkpoint3d.js +120 -0
- package/dist/physics/installed-runtime3d.d.ts +51 -0
- package/dist/physics/installed-runtime3d.js +372 -0
- package/dist/physics/installed-state-commitment3d.d.ts +2 -0
- package/dist/physics/installed-state-commitment3d.js +24 -0
- package/dist/physics/units.d.ts +38 -0
- package/dist/physics/units.js +56 -0
- package/dist/physics/vehicle-state3d.d.ts +93 -0
- package/dist/physics/vehicle-state3d.js +1191 -0
- package/dist/physics/voxel-body-state.d.ts +61 -0
- package/dist/physics/voxel-body-state.js +410 -0
- package/dist/r3f-render-adapter.d.ts +59 -1
- package/dist/r3f-render-adapter.js +137 -2
- package/dist/replay.d.ts +13 -0
- package/dist/replay.js +95 -70
- package/dist/run-room-transport.js +5 -1
- package/dist/runner.d.ts +17 -2
- package/dist/runner.js +472 -84
- package/dist/runtime-cleanup.d.ts +54 -0
- package/dist/runtime-cleanup.js +266 -0
- package/dist/runtime-lease.d.ts +11 -1
- package/dist/runtime-lease.js +23 -10
- package/dist/runtime-room-metadata.d.ts +2 -8
- package/dist/runtime-room-metadata.js +11 -14
- package/dist/runtime-session.d.ts +8 -0
- package/dist/runtime-session.js +222 -58
- package/dist/schema-codegen.js +3 -0
- package/dist/schema-dsl-binary.d.ts +10 -4
- package/dist/schema-dsl-binary.js +375 -76
- package/dist/scratch-pool.d.ts +32 -0
- package/dist/scratch-pool.js +60 -0
- package/dist/sdk-session.d.ts +1 -0
- package/dist/sdk-session.js +4 -0
- package/dist/secret-config.js +2 -60
- package/dist/secret-crypto.js +70 -36
- package/dist/session-snapshot.d.ts +15 -4
- package/dist/session-snapshot.js +35 -33
- package/dist/session-wire.js +14 -22
- package/dist/sparse-set.d.ts +1 -0
- package/dist/sparse-set.js +22 -0
- package/dist/spatial/spatial-grid-3d.d.ts +41 -0
- package/dist/spatial/spatial-grid-3d.js +115 -0
- package/dist/synctest.d.ts +9 -0
- package/dist/synctest.js +106 -17
- package/dist/testing-network.d.ts +2 -0
- package/dist/testing-network.js +122 -18
- package/dist/testing.d.ts +27 -6
- package/dist/testing.js +297 -56
- package/dist/tools/index.d.ts +3 -2
- package/dist/tools/index.js +3 -2
- package/dist/tools/module-certification.d.ts +6 -0
- package/dist/tools/module-certification.js +26 -2
- package/package.json +18 -5
- package/core/scripts/run-box3d-benchmark.mjs +0 -350
- package/core/src/physics/index.mjs +0 -3169
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <array>
|
|
4
|
+
#include <cmath>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <span>
|
|
7
|
+
|
|
8
|
+
namespace rundot::kinetix::physics::powertrain {
|
|
9
|
+
|
|
10
|
+
constexpr std::uint32_t kPowertrainAbiVersion = 1;
|
|
11
|
+
constexpr std::uint32_t kMaxForwardGears = 8;
|
|
12
|
+
constexpr std::uint32_t kMaxEngineCurvePoints = 16;
|
|
13
|
+
constexpr std::uint32_t kMaxWheels = 8;
|
|
14
|
+
|
|
15
|
+
enum class DriveType : std::uint32_t {
|
|
16
|
+
FWD = 0,
|
|
17
|
+
RWD = 1,
|
|
18
|
+
AWD = 2,
|
|
19
|
+
Custom = 3,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
enum class DifferentialType : std::uint32_t {
|
|
23
|
+
Open = 0,
|
|
24
|
+
Locked = 1,
|
|
25
|
+
LimitedSlip = 2,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
struct EngineCurvePoint {
|
|
29
|
+
double rpm = 0.0;
|
|
30
|
+
double torque = 0.0;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
struct EngineConfig {
|
|
34
|
+
double idleRpm = 800.0;
|
|
35
|
+
double maxRpm = 6500.0;
|
|
36
|
+
double revLimiterRpm = 7000.0;
|
|
37
|
+
double revLimiterRecoveryRpm = 6600.0;
|
|
38
|
+
double idleTorque = 120.0;
|
|
39
|
+
double peakTorque = 300.0;
|
|
40
|
+
double peakTorqueRpm = 4000.0;
|
|
41
|
+
double redlineTorque = 180.0;
|
|
42
|
+
double inertia = 0.2; // kg * m^2
|
|
43
|
+
double frictionCoefficient = 0.02; // Nm / (rad/s)
|
|
44
|
+
std::uint32_t curvePointCount = 0;
|
|
45
|
+
std::array<EngineCurvePoint, kMaxEngineCurvePoints> curvePoints{};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
struct TransmissionConfig {
|
|
49
|
+
std::uint32_t forwardGearCount = 5;
|
|
50
|
+
std::array<double, kMaxForwardGears> forwardRatios{3.8, 2.3, 1.5, 1.0, 0.75, 0.0, 0.0, 0.0};
|
|
51
|
+
double reverseRatio = -3.5;
|
|
52
|
+
double finalDriveRatio = 3.8;
|
|
53
|
+
double efficiency = 0.95;
|
|
54
|
+
double shiftDelay = 0.15; // seconds
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
struct DifferentialConfig {
|
|
58
|
+
DriveType driveType = DriveType::RWD;
|
|
59
|
+
DifferentialType frontDiff = DifferentialType::Open;
|
|
60
|
+
DifferentialType rearDiff = DifferentialType::Open;
|
|
61
|
+
DifferentialType centerDiff = DifferentialType::Open;
|
|
62
|
+
double frontRearSplit = 0.5; // AWD front bias [0.0 = 100% rear, 1.0 = 100% front]
|
|
63
|
+
double lsdBiasRatio = 2.5;
|
|
64
|
+
double lsdPreload = 10.0;
|
|
65
|
+
double lockStiffness = 50.0;
|
|
66
|
+
std::uint32_t wheelCount = 4;
|
|
67
|
+
std::array<double, kMaxWheels> customDriveDistribution{};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
struct BrakeConfig {
|
|
71
|
+
double maxServiceBrakeTorque = 2000.0; // Nm total
|
|
72
|
+
double frontBrakeBias = 0.6; // 60% front, 40% rear
|
|
73
|
+
double maxHandbrakeTorque = 1200.0; // Nm total on rear wheels
|
|
74
|
+
std::array<bool, kMaxWheels> handbrakeWheels{false, false, true, true, false, false, false, false};
|
|
75
|
+
std::array<double, kMaxWheels> customBrakeDistribution{};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
struct PowertrainConfig {
|
|
79
|
+
EngineConfig engine{};
|
|
80
|
+
TransmissionConfig transmission{};
|
|
81
|
+
DifferentialConfig differential{};
|
|
82
|
+
BrakeConfig brakes{};
|
|
83
|
+
std::uint32_t wheelCount = 4;
|
|
84
|
+
std::array<double, kMaxWheels> wheelRadii{0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35};
|
|
85
|
+
std::array<double, kMaxWheels> wheelInertias{0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
struct DriverInput {
|
|
89
|
+
double throttle = 0.0; // [0.0, 1.0]
|
|
90
|
+
double brake = 0.0; // [0.0, 1.0]
|
|
91
|
+
double handbrake = 0.0; // [0.0, 1.0]
|
|
92
|
+
double clutch = 1.0; // [0.0, 1.0] (1.0 = fully engaged)
|
|
93
|
+
std::int32_t targetGear = 1; // -1 = Reverse, 0 = Neutral, 1..N = Forward
|
|
94
|
+
bool autoShift = false;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
struct WheelDynamicState {
|
|
98
|
+
double angularVelocity = 0.0; // rad/s (positive = forward)
|
|
99
|
+
bool grounded = true;
|
|
100
|
+
double normalForce = 2500.0; // N
|
|
101
|
+
double friction = 0.8;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
struct EngineState {
|
|
105
|
+
double rpm = 800.0;
|
|
106
|
+
double angularVelocity = 0.0; // rad/s
|
|
107
|
+
double throttle = 0.0;
|
|
108
|
+
double grossTorque = 0.0; // Nm
|
|
109
|
+
double netTorque = 0.0; // Nm
|
|
110
|
+
bool revLimiterActive = false;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
struct TransmissionState {
|
|
114
|
+
std::int32_t currentGear = 1;
|
|
115
|
+
std::int32_t targetGear = 1;
|
|
116
|
+
double shiftTimer = 0.0;
|
|
117
|
+
bool isShifting = false;
|
|
118
|
+
double effectiveRatio = 0.0;
|
|
119
|
+
double clutchEngagement = 1.0;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
struct WheelOutput {
|
|
123
|
+
double driveTorque = 0.0; // Nm
|
|
124
|
+
double brakeTorque = 0.0; // Nm
|
|
125
|
+
double netTorque = 0.0; // Nm
|
|
126
|
+
double updatedAngularVel = 0.0; // rad/s
|
|
127
|
+
double longitudinalForce = 0.0; // N
|
|
128
|
+
bool isLocked = false;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
struct PowertrainState {
|
|
132
|
+
EngineState engine{};
|
|
133
|
+
TransmissionState transmission{};
|
|
134
|
+
double totalDriveForce = 0.0; // N
|
|
135
|
+
double totalBrakeTorque = 0.0; // Nm
|
|
136
|
+
double totalOutputTorque = 0.0; // Nm
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
struct PowertrainOutput {
|
|
140
|
+
PowertrainState state{};
|
|
141
|
+
std::uint32_t wheelCount = 4;
|
|
142
|
+
std::array<WheelOutput, kMaxWheels> wheels{};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Deterministic math helpers
|
|
146
|
+
double quantizeValue(double value);
|
|
147
|
+
double sampleEngineCurve(const EngineConfig& config, double rpm);
|
|
148
|
+
double getGearRatio(const TransmissionConfig& config, std::int32_t gear);
|
|
149
|
+
|
|
150
|
+
// Step function
|
|
151
|
+
PowertrainOutput stepPowertrain(
|
|
152
|
+
const PowertrainConfig& config,
|
|
153
|
+
const PowertrainState& currentState,
|
|
154
|
+
const DriverInput& input,
|
|
155
|
+
std::span<const WheelDynamicState> wheelStates,
|
|
156
|
+
double dt = 1.0 / 60.0);
|
|
157
|
+
|
|
158
|
+
} // namespace rundot::kinetix::physics::powertrain
|
|
159
|
+
|
|
160
|
+
extern "C" {
|
|
161
|
+
|
|
162
|
+
std::uint32_t rundot_kinetix_powertrain_abi_version();
|
|
163
|
+
std::uint32_t rundot_kinetix_powertrain_max_wheels();
|
|
164
|
+
std::uint32_t rundot_kinetix_powertrain_max_gears();
|
|
165
|
+
|
|
166
|
+
std::int32_t rundot_kinetix_powertrain_sample_engine_curve(
|
|
167
|
+
const double* engineConfigData,
|
|
168
|
+
double rpm,
|
|
169
|
+
double* outTorque);
|
|
170
|
+
|
|
171
|
+
std::int32_t rundot_kinetix_powertrain_step(
|
|
172
|
+
const double* configData,
|
|
173
|
+
const double* stateData,
|
|
174
|
+
const double* inputData,
|
|
175
|
+
const double* wheelStatesData,
|
|
176
|
+
std::uint32_t wheelCount,
|
|
177
|
+
double dt,
|
|
178
|
+
double* outputData);
|
|
179
|
+
|
|
180
|
+
} // extern "C"
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#include "pulley.hpp"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cmath>
|
|
5
|
+
#include <limits>
|
|
6
|
+
|
|
7
|
+
namespace rundot::kinetix::physics {
|
|
8
|
+
|
|
9
|
+
namespace {
|
|
10
|
+
|
|
11
|
+
inline PulleyVec3 cross(const PulleyVec3& a, const PulleyVec3& b) {
|
|
12
|
+
return {
|
|
13
|
+
a.y * b.z - a.z * b.y,
|
|
14
|
+
a.z * b.x - a.x * b.z,
|
|
15
|
+
a.x * b.y - a.y * b.x,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
inline double dot(const PulleyVec3& a, const PulleyVec3& b) {
|
|
20
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
inline PulleyVec3 rotateByQuat(double qx, double qy, double qz, double qw, const PulleyVec3& v) {
|
|
24
|
+
const double normSq = qx * qx + qy * qy + qz * qz + qw * qw;
|
|
25
|
+
if (normSq <= 1e-24) return v;
|
|
26
|
+
const double invNorm = 1.0 / std::sqrt(normSq);
|
|
27
|
+
const double x = qx * invNorm;
|
|
28
|
+
const double y = qy * invNorm;
|
|
29
|
+
const double z = qz * invNorm;
|
|
30
|
+
const double w = qw * invNorm;
|
|
31
|
+
|
|
32
|
+
const double uvX = y * v.z - z * v.y;
|
|
33
|
+
const double uvY = z * v.x - x * v.z;
|
|
34
|
+
const double uvZ = x * v.y - y * v.x;
|
|
35
|
+
|
|
36
|
+
const double uuvX = y * uvZ - z * uvY;
|
|
37
|
+
const double uuvY = z * uvX - x * uvZ;
|
|
38
|
+
const double uuvZ = x * uvY - y * uvX;
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
v.x + 2.0 * (w * uvX + uuvX),
|
|
42
|
+
v.y + 2.0 * (w * uvY + uuvY),
|
|
43
|
+
v.z + 2.0 * (w * uvZ + uuvZ),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
} // namespace
|
|
48
|
+
|
|
49
|
+
bool computePulleyGeometry3D(
|
|
50
|
+
const PulleyConstraint3D& constraint,
|
|
51
|
+
const Body& bodyA,
|
|
52
|
+
const Body& bodyB,
|
|
53
|
+
PulleyGeometry3D& output) {
|
|
54
|
+
output = PulleyGeometry3D{};
|
|
55
|
+
if (!(constraint.ratio > 0.0) || !std::isfinite(constraint.ratio)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const PulleyVec3 rA = rotateByQuat(bodyA.orientationX, bodyA.orientationY,
|
|
60
|
+
bodyA.orientationZ, bodyA.orientationW,
|
|
61
|
+
constraint.anchorA);
|
|
62
|
+
const PulleyVec3 worldA = {bodyA.x + rA.x, bodyA.y + rA.y, bodyA.z + rA.z};
|
|
63
|
+
|
|
64
|
+
const PulleyVec3 rB = rotateByQuat(bodyB.orientationX, bodyB.orientationY,
|
|
65
|
+
bodyB.orientationZ, bodyB.orientationW,
|
|
66
|
+
constraint.anchorB);
|
|
67
|
+
const PulleyVec3 worldB = {bodyB.x + rB.x, bodyB.y + rB.y, bodyB.z + rB.z};
|
|
68
|
+
|
|
69
|
+
const PulleyVec3 legA = {worldA.x - constraint.groundA.x,
|
|
70
|
+
worldA.y - constraint.groundA.y,
|
|
71
|
+
worldA.z - constraint.groundA.z};
|
|
72
|
+
const PulleyVec3 legB = {worldB.x - constraint.groundB.x,
|
|
73
|
+
worldB.y - constraint.groundB.y,
|
|
74
|
+
worldB.z - constraint.groundB.z};
|
|
75
|
+
|
|
76
|
+
const double lengthASq = dot(legA, legA);
|
|
77
|
+
const double lengthBSq = dot(legB, legB);
|
|
78
|
+
const double lengthA = std::sqrt(lengthASq);
|
|
79
|
+
const double lengthB = std::sqrt(lengthBSq);
|
|
80
|
+
|
|
81
|
+
if (lengthA <= 1e-12 || lengthB <= 1e-12 ||
|
|
82
|
+
!std::isfinite(lengthA) || !std::isfinite(lengthB)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const PulleyVec3 unitA = {legA.x / lengthA, legA.y / lengthA, legA.z / lengthA};
|
|
87
|
+
const PulleyVec3 unitB = {legB.x / lengthB, legB.y / lengthB, legB.z / lengthB};
|
|
88
|
+
|
|
89
|
+
const PulleyVec3 angA = cross(rA, unitA);
|
|
90
|
+
const PulleyVec3 angB = cross(rB, unitB);
|
|
91
|
+
|
|
92
|
+
const double coordinate = lengthA + constraint.ratio * lengthB;
|
|
93
|
+
const double targetLength = constraint.totalLength > 0.0 ? constraint.totalLength : coordinate;
|
|
94
|
+
const double error = coordinate - targetLength;
|
|
95
|
+
|
|
96
|
+
const PulleyVec3 velA = {bodyA.vx, bodyA.vy, bodyA.vz};
|
|
97
|
+
const PulleyVec3 angVelA = {bodyA.angularVelX, bodyA.angularVelY, bodyA.angularVelZ};
|
|
98
|
+
const PulleyVec3 velB = {bodyB.vx, bodyB.vy, bodyB.vz};
|
|
99
|
+
const PulleyVec3 angVelB = {bodyB.angularVelX, bodyB.angularVelY, bodyB.angularVelZ};
|
|
100
|
+
|
|
101
|
+
const double speedA = dot(unitA, velA) + dot(angA, angVelA);
|
|
102
|
+
const double speedB = dot(unitB, velB) + dot(angB, angVelB);
|
|
103
|
+
const double speed = speedA + constraint.ratio * speedB;
|
|
104
|
+
|
|
105
|
+
if (!std::isfinite(coordinate) || !std::isfinite(speed)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
output.worldAnchorA = worldA;
|
|
110
|
+
output.worldAnchorB = worldB;
|
|
111
|
+
output.legA = legA;
|
|
112
|
+
output.legB = legB;
|
|
113
|
+
output.lengthA = lengthA;
|
|
114
|
+
output.lengthB = lengthB;
|
|
115
|
+
output.coordinate = coordinate;
|
|
116
|
+
output.error = error;
|
|
117
|
+
output.speed = speed;
|
|
118
|
+
output.unitA = unitA;
|
|
119
|
+
output.unitB = unitB;
|
|
120
|
+
output.angularFactorA = angA;
|
|
121
|
+
output.angularFactorB = angB;
|
|
122
|
+
output.valid = true;
|
|
123
|
+
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
std::uint32_t buildPulleyConstraintRows(
|
|
128
|
+
const PulleyConstraint3D& constraint,
|
|
129
|
+
const Body& bodyA,
|
|
130
|
+
const Body& bodyB,
|
|
131
|
+
double dt,
|
|
132
|
+
std::span<ConstraintRow6> outputRows,
|
|
133
|
+
PulleyState3D* outState) {
|
|
134
|
+
if (outputRows.empty() || dt <= 0.0 || !(constraint.ratio > 0.0)) return 0;
|
|
135
|
+
|
|
136
|
+
PulleyGeometry3D geom{};
|
|
137
|
+
if (!computePulleyGeometry3D(constraint, bodyA, bodyB, geom)) return 0;
|
|
138
|
+
|
|
139
|
+
ConstraintRow6& row = outputRows[0];
|
|
140
|
+
row = ConstraintRow6{};
|
|
141
|
+
row.scalar = ConstraintScalar::unconstrained();
|
|
142
|
+
row.bodyA = constraint.bodyA;
|
|
143
|
+
row.bodyB = constraint.bodyB;
|
|
144
|
+
|
|
145
|
+
row.jacobianA = {
|
|
146
|
+
geom.unitA.x, geom.unitA.y, geom.unitA.z,
|
|
147
|
+
geom.angularFactorA.x, geom.angularFactorA.y, geom.angularFactorA.z,
|
|
148
|
+
};
|
|
149
|
+
row.jacobianB = {
|
|
150
|
+
constraint.ratio * geom.unitB.x,
|
|
151
|
+
constraint.ratio * geom.unitB.y,
|
|
152
|
+
constraint.ratio * geom.unitB.z,
|
|
153
|
+
constraint.ratio * geom.angularFactorB.x,
|
|
154
|
+
constraint.ratio * geom.angularFactorB.y,
|
|
155
|
+
constraint.ratio * geom.angularFactorB.z,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const bool isFixed = constraint.mode == PulleyMode3D::FixedLength;
|
|
159
|
+
const bool isSlack = !isFixed && (geom.error < 0.0);
|
|
160
|
+
|
|
161
|
+
if (isFixed) {
|
|
162
|
+
if (constraint.frequencyHz > 0.0) {
|
|
163
|
+
row.scalar = constraintSoftness(geom.error, dt, constraint.frequencyHz,
|
|
164
|
+
constraint.dampingRatio, constraint.maxForce);
|
|
165
|
+
} else {
|
|
166
|
+
row.scalar.bias = 0.2 * geom.error / dt;
|
|
167
|
+
if (constraint.maxForce > 0.0) {
|
|
168
|
+
row.scalar.lower = -constraint.maxForce * dt;
|
|
169
|
+
row.scalar.upper = constraint.maxForce * dt;
|
|
170
|
+
} else {
|
|
171
|
+
row.scalar.lower = -std::numeric_limits<double>::infinity();
|
|
172
|
+
row.scalar.upper = std::numeric_limits<double>::infinity();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (constraint.initialImpulse != 0.0) {
|
|
176
|
+
row.scalar.accumulatedImpulse = constraint.initialImpulse;
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
// MaxLength / Unilateral mode
|
|
180
|
+
if (constraint.frequencyHz > 0.0) {
|
|
181
|
+
row.scalar = constraintSoftness(geom.error, dt, constraint.frequencyHz,
|
|
182
|
+
constraint.dampingRatio, constraint.maxForce);
|
|
183
|
+
row.scalar.upper = 0.0;
|
|
184
|
+
if (isSlack) {
|
|
185
|
+
row.scalar.bias = geom.error / dt;
|
|
186
|
+
row.scalar.accumulatedImpulse = 0.0;
|
|
187
|
+
} else if (constraint.initialImpulse < 0.0) {
|
|
188
|
+
row.scalar.accumulatedImpulse = constraint.initialImpulse;
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
row.scalar.bias = (isSlack ? 1.0 : 0.2) * geom.error / dt;
|
|
192
|
+
row.scalar.lower = constraint.maxForce > 0.0 ? -constraint.maxForce * dt : -std::numeric_limits<double>::infinity();
|
|
193
|
+
row.scalar.upper = 0.0;
|
|
194
|
+
if (isSlack) {
|
|
195
|
+
row.scalar.accumulatedImpulse = 0.0;
|
|
196
|
+
} else if (constraint.initialImpulse < 0.0) {
|
|
197
|
+
row.scalar.accumulatedImpulse = constraint.initialImpulse;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (outState != nullptr) {
|
|
203
|
+
outState->lengthA = geom.lengthA;
|
|
204
|
+
outState->lengthB = geom.lengthB;
|
|
205
|
+
outState->coordinate = geom.coordinate;
|
|
206
|
+
outState->targetLength = constraint.totalLength > 0.0 ? constraint.totalLength : geom.coordinate;
|
|
207
|
+
outState->error = geom.error;
|
|
208
|
+
outState->speed = geom.speed;
|
|
209
|
+
outState->accumulatedImpulse = row.scalar.accumulatedImpulse;
|
|
210
|
+
outState->impulseMagnitude = std::abs(row.scalar.accumulatedImpulse);
|
|
211
|
+
outState->tensionForce = outState->impulseMagnitude / dt;
|
|
212
|
+
outState->tensionForceB = outState->tensionForce * constraint.ratio;
|
|
213
|
+
outState->reactionForceA = {
|
|
214
|
+
-geom.unitA.x * outState->tensionForce,
|
|
215
|
+
-geom.unitA.y * outState->tensionForce,
|
|
216
|
+
-geom.unitA.z * outState->tensionForce,
|
|
217
|
+
};
|
|
218
|
+
outState->reactionForceB = {
|
|
219
|
+
-geom.unitB.x * outState->tensionForceB,
|
|
220
|
+
-geom.unitB.y * outState->tensionForceB,
|
|
221
|
+
-geom.unitB.z * outState->tensionForceB,
|
|
222
|
+
};
|
|
223
|
+
outState->limitState = isFixed ? PulleyLimitState3D::Equal
|
|
224
|
+
: (isSlack ? PulleyLimitState3D::Inactive : PulleyLimitState3D::AtUpper);
|
|
225
|
+
outState->broken = false;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return 1;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
std::uint32_t solvePulleyConstraint(
|
|
232
|
+
const PulleyConstraint3D& constraint,
|
|
233
|
+
std::span<Body> bodies,
|
|
234
|
+
std::span<const ConstraintBodyMobility> mobility,
|
|
235
|
+
double dt,
|
|
236
|
+
std::uint32_t iterations,
|
|
237
|
+
PulleyState3D* outState) {
|
|
238
|
+
if (constraint.bodyA >= bodies.size() || constraint.bodyB >= bodies.size()) return 0;
|
|
239
|
+
if (constraint.bodyA >= mobility.size() || constraint.bodyB >= mobility.size()) return 0;
|
|
240
|
+
if (constraint.bodyA == constraint.bodyB || dt <= 0.0 || iterations == 0) return 0;
|
|
241
|
+
|
|
242
|
+
std::array<ConstraintRow6, 1> rows{};
|
|
243
|
+
PulleyState3D state{};
|
|
244
|
+
if (buildPulleyConstraintRows(constraint, bodies[constraint.bodyA], bodies[constraint.bodyB],
|
|
245
|
+
dt, rows, &state) == 0) {
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!prepareConstraintRow(rows[0], mobility)) {
|
|
250
|
+
return 0;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Apply warm-start impulse if non-zero
|
|
254
|
+
if (rows[0].scalar.accumulatedImpulse != 0.0) {
|
|
255
|
+
applyConstraintRowImpulse(rows[0], bodies, mobility, rows[0].scalar.accumulatedImpulse);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Iterative Gauss-Seidel solver loop
|
|
259
|
+
for (std::uint32_t iter = 0; iter < iterations; ++iter) {
|
|
260
|
+
solveConstraintRow(rows[0], bodies, mobility);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Final telemetry extraction
|
|
264
|
+
const double impulse = rows[0].scalar.accumulatedImpulse;
|
|
265
|
+
const double impulseMag = std::abs(impulse);
|
|
266
|
+
const double tensionA = impulseMag / dt;
|
|
267
|
+
const double tensionB = tensionA * constraint.ratio;
|
|
268
|
+
|
|
269
|
+
state.accumulatedImpulse = impulse;
|
|
270
|
+
state.impulseMagnitude = impulseMag;
|
|
271
|
+
state.tensionForce = tensionA;
|
|
272
|
+
state.tensionForceB = tensionB;
|
|
273
|
+
|
|
274
|
+
PulleyGeometry3D geom{};
|
|
275
|
+
if (computePulleyGeometry3D(constraint, bodies[constraint.bodyA], bodies[constraint.bodyB], geom)) {
|
|
276
|
+
state.reactionForceA = {
|
|
277
|
+
-geom.unitA.x * tensionA,
|
|
278
|
+
-geom.unitA.y * tensionA,
|
|
279
|
+
-geom.unitA.z * tensionA,
|
|
280
|
+
};
|
|
281
|
+
state.reactionForceB = {
|
|
282
|
+
-geom.unitB.x * tensionB,
|
|
283
|
+
-geom.unitB.y * tensionB,
|
|
284
|
+
-geom.unitB.z * tensionB,
|
|
285
|
+
};
|
|
286
|
+
state.speed = geom.speed;
|
|
287
|
+
state.coordinate = geom.coordinate;
|
|
288
|
+
state.lengthA = geom.lengthA;
|
|
289
|
+
state.lengthB = geom.lengthB;
|
|
290
|
+
state.error = geom.error;
|
|
291
|
+
if (constraint.mode == PulleyMode3D::MaxLength) {
|
|
292
|
+
state.limitState = (impulse < 0.0 || geom.error >= 0.0)
|
|
293
|
+
? PulleyLimitState3D::AtUpper
|
|
294
|
+
: PulleyLimitState3D::Inactive;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (constraint.breakForce > 0.0 && tensionA > constraint.breakForce) {
|
|
299
|
+
state.broken = true;
|
|
300
|
+
state.limitState = PulleyLimitState3D::Inactive;
|
|
301
|
+
state.accumulatedImpulse = 0.0;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (outState != nullptr) {
|
|
305
|
+
*outState = state;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return 1;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
} // namespace rundot::kinetix::physics
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <array>
|
|
4
|
+
#include <cmath>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <span>
|
|
7
|
+
|
|
8
|
+
#include "constraint_rows.hpp"
|
|
9
|
+
#include "physics.hpp"
|
|
10
|
+
|
|
11
|
+
namespace rundot::kinetix::physics {
|
|
12
|
+
|
|
13
|
+
constexpr std::uint32_t kPulleyAbiVersion = 1;
|
|
14
|
+
constexpr std::uint32_t kPulleyJointTypeCode = 12;
|
|
15
|
+
|
|
16
|
+
enum class PulleyMode3D : std::uint8_t {
|
|
17
|
+
MaxLength = 0, // Unilateral: rope pulls when taut, slack (no force) when shorter
|
|
18
|
+
FixedLength = 1, // Bilateral: maintains exact total length (pulls and pushes)
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
enum class PulleyLimitState3D : std::uint8_t {
|
|
22
|
+
Inactive = 0, // Slack (length < totalLength in MaxLength mode)
|
|
23
|
+
AtUpper = 1, // Taut / at limit (length >= totalLength in MaxLength mode)
|
|
24
|
+
Equal = 2, // FixedLength mode
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
struct PulleyVec3 {
|
|
28
|
+
double x = 0.0;
|
|
29
|
+
double y = 0.0;
|
|
30
|
+
double z = 0.0;
|
|
31
|
+
|
|
32
|
+
constexpr bool operator==(const PulleyVec3& other) const = default;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
struct PulleyConstraint3D {
|
|
36
|
+
std::uint32_t bodyA = 0;
|
|
37
|
+
std::uint32_t bodyB = 0;
|
|
38
|
+
PulleyVec3 groundA{}; // World position of pulley fixed suspension / ground anchor A
|
|
39
|
+
PulleyVec3 groundB{}; // World position of pulley fixed suspension / ground anchor B
|
|
40
|
+
PulleyVec3 anchorA{}; // Local anchor position on body A (relative to body A center)
|
|
41
|
+
PulleyVec3 anchorB{}; // Local anchor position on body B (relative to body B center)
|
|
42
|
+
double ratio = 1.0; // Pulley transmission ratio (segment B scaling factor, must be > 0)
|
|
43
|
+
double totalLength = 0.0; // Target total length: lengthA + ratio * lengthB (must be > 0)
|
|
44
|
+
PulleyMode3D mode = PulleyMode3D::MaxLength; // Unilateral slack policy by default
|
|
45
|
+
double maxForce = 0.0; // Maximum tension force limit (0.0 = unlimited)
|
|
46
|
+
double breakForce = 0.0; // Breaking tension force threshold (0.0 = unbreakable)
|
|
47
|
+
double frequencyHz = 0.0; // Soft constraint spring frequency (0.0 = rigid Baumgarte)
|
|
48
|
+
double dampingRatio = 1.0; // Soft constraint damping ratio
|
|
49
|
+
double initialImpulse = 0.0;// Warm-start impulse from previous step (must be <= 0 in MaxLength)
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
struct PulleyGeometry3D {
|
|
53
|
+
PulleyVec3 worldAnchorA{};
|
|
54
|
+
PulleyVec3 worldAnchorB{};
|
|
55
|
+
PulleyVec3 legA{};
|
|
56
|
+
PulleyVec3 legB{};
|
|
57
|
+
double lengthA = 0.0;
|
|
58
|
+
double lengthB = 0.0;
|
|
59
|
+
double coordinate = 0.0; // lengthA + ratio * lengthB
|
|
60
|
+
double error = 0.0; // coordinate - totalLength
|
|
61
|
+
double speed = 0.0; // d(coordinate)/dt
|
|
62
|
+
PulleyVec3 unitA{}; // Unit vector from groundA to anchorA
|
|
63
|
+
PulleyVec3 unitB{}; // Unit vector from groundB to anchorB
|
|
64
|
+
PulleyVec3 angularFactorA{};// rA x unitA
|
|
65
|
+
PulleyVec3 angularFactorB{};// rB x unitB
|
|
66
|
+
bool valid = false;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
struct PulleyState3D {
|
|
70
|
+
double lengthA = 0.0;
|
|
71
|
+
double lengthB = 0.0;
|
|
72
|
+
double coordinate = 0.0; // lengthA + ratio * lengthB
|
|
73
|
+
double targetLength = 0.0;
|
|
74
|
+
double error = 0.0; // coordinate - targetLength
|
|
75
|
+
double speed = 0.0; // d(coordinate)/dt
|
|
76
|
+
double accumulatedImpulse = 0.0; // Raw accumulated impulse lambda (<= 0 in MaxLength)
|
|
77
|
+
double impulseMagnitude = 0.0; // Tension impulse magnitude |lambda|
|
|
78
|
+
double tensionForce = 0.0; // Tension force on segment A (impulseMagnitude / dt)
|
|
79
|
+
double tensionForceB = 0.0; // Tension force on segment B (tensionForce * ratio)
|
|
80
|
+
PulleyVec3 reactionForceA{}; // Force vector on body A (pulls toward groundA)
|
|
81
|
+
PulleyVec3 reactionForceB{}; // Force vector on body B (pulls toward groundB)
|
|
82
|
+
PulleyLimitState3D limitState = PulleyLimitState3D::Inactive;
|
|
83
|
+
bool broken = false;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Compute world geometry, segment lengths, coordinate, and unit vectors for a pulley.
|
|
88
|
+
* Returns true if geometry is non-degenerate (both lengths > 1e-12 and finite).
|
|
89
|
+
*/
|
|
90
|
+
bool computePulleyGeometry3D(
|
|
91
|
+
const PulleyConstraint3D& constraint,
|
|
92
|
+
const Body& bodyA,
|
|
93
|
+
const Body& bodyB,
|
|
94
|
+
PulleyGeometry3D& output);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Build 3D pulley constraint row on constraint_rows.hpp.
|
|
98
|
+
* Conserves lengthA + ratio * lengthB with unilateral behavior (pulls but never pushes).
|
|
99
|
+
* Returns 1 on success, 0 on degeneracy or invalid parameters.
|
|
100
|
+
*/
|
|
101
|
+
std::uint32_t buildPulleyConstraintRows(
|
|
102
|
+
const PulleyConstraint3D& constraint,
|
|
103
|
+
const Body& bodyA,
|
|
104
|
+
const Body& bodyB,
|
|
105
|
+
double dt,
|
|
106
|
+
std::span<ConstraintRow6> outputRows,
|
|
107
|
+
PulleyState3D* outState = nullptr);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Solves the pulley constraint iteratively using constraint_rows mobility.
|
|
111
|
+
* Returns 1 on success, 0 on failure.
|
|
112
|
+
*/
|
|
113
|
+
std::uint32_t solvePulleyConstraint(
|
|
114
|
+
const PulleyConstraint3D& constraint,
|
|
115
|
+
std::span<Body> bodies,
|
|
116
|
+
std::span<const ConstraintBodyMobility> mobility,
|
|
117
|
+
double dt,
|
|
118
|
+
std::uint32_t iterations,
|
|
119
|
+
PulleyState3D* outState = nullptr);
|
|
120
|
+
|
|
121
|
+
} // namespace rundot::kinetix::physics
|