@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,638 @@
|
|
|
1
|
+
#include "character.hpp"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <array>
|
|
5
|
+
#include <cmath>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
|
|
8
|
+
namespace rundot::kinetix::physics {
|
|
9
|
+
|
|
10
|
+
#if defined(__GNUC__) || defined(__clang__)
|
|
11
|
+
__attribute__((weak)) std::int32_t shapeCastSoA(const double*, std::uint32_t, const double*, std::uint32_t) { return 0; }
|
|
12
|
+
__attribute__((weak)) std::int32_t overlapSoA(const double*, std::uint32_t, const double*, std::uint32_t) { return 0; }
|
|
13
|
+
__attribute__((weak)) std::uint32_t queryResultCount() { return 0; }
|
|
14
|
+
__attribute__((weak)) const double* queryResultData() { return nullptr; }
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
namespace {
|
|
18
|
+
|
|
19
|
+
inline double solverSqrt(double value) {
|
|
20
|
+
if (value <= 0.0) return 0.0;
|
|
21
|
+
return std::sqrt(value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
} // namespace
|
|
25
|
+
|
|
26
|
+
CharacterVec3 addVec3(const CharacterVec3& a, const CharacterVec3& b) {
|
|
27
|
+
return {a.x + b.x, a.y + b.y, a.z + b.z};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
CharacterVec3 subVec3(const CharacterVec3& a, const CharacterVec3& b) {
|
|
31
|
+
return {a.x - b.x, a.y - b.y, a.z - b.z};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
CharacterVec3 scaleVec3(const CharacterVec3& v, double s) {
|
|
35
|
+
return {v.x * s, v.y * s, v.z * s};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
double dotVec3(const CharacterVec3& a, const CharacterVec3& b) {
|
|
39
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
CharacterVec3 crossVec3(const CharacterVec3& a, const CharacterVec3& b) {
|
|
43
|
+
return {
|
|
44
|
+
a.y * b.z - a.z * b.y,
|
|
45
|
+
a.z * b.x - a.x * b.z,
|
|
46
|
+
a.x * b.y - a.y * b.x,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
double lengthSquaredVec3(const CharacterVec3& v) {
|
|
51
|
+
return dotVec3(v, v);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
double lengthVec3(const CharacterVec3& v) {
|
|
55
|
+
return solverSqrt(lengthSquaredVec3(v));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
CharacterVec3 normalizeVec3(const CharacterVec3& v) {
|
|
59
|
+
const double lenSq = lengthSquaredVec3(v);
|
|
60
|
+
if (lenSq <= 1e-24) return {0.0, 0.0, 0.0};
|
|
61
|
+
const double invLen = 1.0 / solverSqrt(lenSq);
|
|
62
|
+
return {v.x * invLen, v.y * invLen, v.z * invLen};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
bool depenetrateCharacter(
|
|
66
|
+
CharacterVec3& currentPos,
|
|
67
|
+
const CharacterConfig& config,
|
|
68
|
+
const CharacterQueryCallbacks& queries) {
|
|
69
|
+
if (queries.overlap == nullptr) return false;
|
|
70
|
+
|
|
71
|
+
bool wasDepenetrated = false;
|
|
72
|
+
for (std::uint32_t iter = 0; iter < 4; ++iter) {
|
|
73
|
+
CharacterHit hit;
|
|
74
|
+
if (!queries.overlap(
|
|
75
|
+
queries.userData,
|
|
76
|
+
config.shape,
|
|
77
|
+
currentPos,
|
|
78
|
+
config.collisionMask,
|
|
79
|
+
config.excludedBodyIndex,
|
|
80
|
+
hit)) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
wasDepenetrated = true;
|
|
85
|
+
CharacterVec3 pushDir = hit.normal;
|
|
86
|
+
if (lengthSquaredVec3(pushDir) < 1e-6) {
|
|
87
|
+
pushDir = config.up;
|
|
88
|
+
} else {
|
|
89
|
+
pushDir = normalizeVec3(pushDir);
|
|
90
|
+
}
|
|
91
|
+
const double pushDist = config.skinWidth > 0.0 ? config.skinWidth : 0.01;
|
|
92
|
+
currentPos = addVec3(currentPos, scaleVec3(pushDir, pushDist));
|
|
93
|
+
}
|
|
94
|
+
return wasDepenetrated;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
bool checkGroundSupport(
|
|
98
|
+
CharacterState& state,
|
|
99
|
+
const CharacterConfig& config,
|
|
100
|
+
const CharacterQueryCallbacks& queries) {
|
|
101
|
+
if (queries.shapeCast == nullptr) return false;
|
|
102
|
+
|
|
103
|
+
const CharacterVec3 downDir = scaleVec3(config.up, -1.0);
|
|
104
|
+
const double probeDist = config.groundProbeDistance + config.skinWidth * 2.0;
|
|
105
|
+
|
|
106
|
+
CharacterHit hit;
|
|
107
|
+
if (!queries.shapeCast(
|
|
108
|
+
queries.userData,
|
|
109
|
+
config.shape,
|
|
110
|
+
state.position,
|
|
111
|
+
downDir,
|
|
112
|
+
probeDist,
|
|
113
|
+
config.collisionMask,
|
|
114
|
+
config.excludedBodyIndex,
|
|
115
|
+
hit)) {
|
|
116
|
+
state.grounded = false;
|
|
117
|
+
state.groundDistance = probeDist;
|
|
118
|
+
state.groundBodyIndex = -1;
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
CharacterVec3 surfNormal = hit.normal;
|
|
123
|
+
if (dotVec3(surfNormal, downDir) > 0.0) {
|
|
124
|
+
surfNormal = scaleVec3(surfNormal, -1.0);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const double cosSlope = dotVec3(surfNormal, config.up);
|
|
128
|
+
state.groundNormal = surfNormal;
|
|
129
|
+
state.groundDistance = hit.distance;
|
|
130
|
+
state.groundBodyIndex = hit.bodyIndex;
|
|
131
|
+
|
|
132
|
+
if (cosSlope >= std::cos(config.maxSlopeAngle)) {
|
|
133
|
+
state.grounded = true;
|
|
134
|
+
return true;
|
|
135
|
+
} else {
|
|
136
|
+
// Steep slope is not walkable ground
|
|
137
|
+
state.grounded = false;
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
bool sweepAndSlide(
|
|
143
|
+
CharacterVec3& currentPos,
|
|
144
|
+
CharacterVec3& move,
|
|
145
|
+
CharacterState& state,
|
|
146
|
+
const CharacterConfig& config,
|
|
147
|
+
const CharacterQueryCallbacks& queries,
|
|
148
|
+
bool isHorizontal) {
|
|
149
|
+
if (queries.shapeCast == nullptr) return false;
|
|
150
|
+
|
|
151
|
+
std::array<CharacterVec3, 4> hitPlanes{};
|
|
152
|
+
std::size_t hitPlaneCount = 0;
|
|
153
|
+
|
|
154
|
+
for (std::uint32_t iter = 0; iter < config.maxSlideIterations; ++iter) {
|
|
155
|
+
const double dist = lengthVec3(move);
|
|
156
|
+
if (dist < config.minStepDistance) break;
|
|
157
|
+
const CharacterVec3 dir = scaleVec3(move, 1.0 / dist);
|
|
158
|
+
|
|
159
|
+
CharacterHit hit;
|
|
160
|
+
const double castDist = dist + config.skinWidth;
|
|
161
|
+
if (!queries.shapeCast(
|
|
162
|
+
queries.userData,
|
|
163
|
+
config.shape,
|
|
164
|
+
currentPos,
|
|
165
|
+
dir,
|
|
166
|
+
castDist,
|
|
167
|
+
config.collisionMask,
|
|
168
|
+
config.excludedBodyIndex,
|
|
169
|
+
hit)) {
|
|
170
|
+
currentPos = addVec3(currentPos, move);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Determine outward obstacle surface normal (pointing toward character)
|
|
175
|
+
CharacterVec3 surfNormal = hit.normal;
|
|
176
|
+
if (dotVec3(surfNormal, dir) > 0.0) {
|
|
177
|
+
surfNormal = scaleVec3(surfNormal, -1.0);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const double advance = std::max(0.0, hit.distance - config.skinWidth);
|
|
181
|
+
if (advance > 0.0) {
|
|
182
|
+
currentPos = addVec3(currentPos, scaleVec3(dir, advance));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Classify hit surface
|
|
186
|
+
const double upDot = dotVec3(surfNormal, config.up);
|
|
187
|
+
if (upDot < -0.1) {
|
|
188
|
+
// Ceiling hit
|
|
189
|
+
state.hitCeiling = true;
|
|
190
|
+
if (state.velocity.y > 0.0) state.velocity.y = 0.0;
|
|
191
|
+
} else if (upDot >= std::cos(config.maxSlopeAngle)) {
|
|
192
|
+
// Ground hit
|
|
193
|
+
state.grounded = true;
|
|
194
|
+
state.groundNormal = surfNormal;
|
|
195
|
+
state.groundBodyIndex = hit.bodyIndex;
|
|
196
|
+
state.groundDistance = 0.0;
|
|
197
|
+
if (state.velocity.y < 0.0) state.velocity.y = 0.0;
|
|
198
|
+
} else {
|
|
199
|
+
// Wall hit
|
|
200
|
+
state.hitWall = true;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
state.slideCount++;
|
|
204
|
+
|
|
205
|
+
const double remainingDist = dist - hit.distance;
|
|
206
|
+
if (remainingDist <= 1e-6) break;
|
|
207
|
+
|
|
208
|
+
// Project remaining travel vector onto collision plane
|
|
209
|
+
CharacterVec3 remainingVec = scaleVec3(dir, remainingDist);
|
|
210
|
+
CharacterVec3 slideMove = subVec3(remainingVec, scaleVec3(surfNormal, dotVec3(remainingVec, surfNormal)));
|
|
211
|
+
|
|
212
|
+
if (hitPlaneCount < hitPlanes.size()) {
|
|
213
|
+
hitPlanes[hitPlaneCount++] = surfNormal;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Handle corner crease / multi-plane collision
|
|
217
|
+
if (hitPlaneCount >= 2) {
|
|
218
|
+
for (std::size_t i = 0; i < hitPlaneCount - 1; ++i) {
|
|
219
|
+
if (dotVec3(slideMove, hitPlanes[i]) < 0.0) {
|
|
220
|
+
CharacterVec3 crease = crossVec3(surfNormal, hitPlanes[i]);
|
|
221
|
+
const double creaseLen = lengthVec3(crease);
|
|
222
|
+
if (creaseLen > 1e-6) {
|
|
223
|
+
crease = scaleVec3(crease, 1.0 / creaseLen);
|
|
224
|
+
slideMove = scaleVec3(crease, dotVec3(slideMove, crease));
|
|
225
|
+
} else {
|
|
226
|
+
slideMove = {0.0, 0.0, 0.0};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (isHorizontal) {
|
|
233
|
+
slideMove.y = 0.0;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
move = slideMove;
|
|
237
|
+
}
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
bool tryStepUp(
|
|
242
|
+
CharacterVec3& currentPos,
|
|
243
|
+
const CharacterVec3& horizMove,
|
|
244
|
+
CharacterState& state,
|
|
245
|
+
const CharacterConfig& config,
|
|
246
|
+
const CharacterQueryCallbacks& queries) {
|
|
247
|
+
if (config.stepHeight <= 0.0 || queries.shapeCast == nullptr) return false;
|
|
248
|
+
const double horizLen = lengthVec3(horizMove);
|
|
249
|
+
if (horizLen < config.minStepDistance) return false;
|
|
250
|
+
const CharacterVec3 horizDir = scaleVec3(horizMove, 1.0 / horizLen);
|
|
251
|
+
|
|
252
|
+
// 1. Elevate upward
|
|
253
|
+
CharacterHit upHit;
|
|
254
|
+
double actualStepHeight = config.stepHeight;
|
|
255
|
+
if (queries.shapeCast(
|
|
256
|
+
queries.userData,
|
|
257
|
+
config.shape,
|
|
258
|
+
currentPos,
|
|
259
|
+
config.up,
|
|
260
|
+
config.stepHeight + config.skinWidth,
|
|
261
|
+
config.collisionMask,
|
|
262
|
+
config.excludedBodyIndex,
|
|
263
|
+
upHit)) {
|
|
264
|
+
actualStepHeight = std::max(0.0, upHit.distance - config.skinWidth);
|
|
265
|
+
}
|
|
266
|
+
if (actualStepHeight < 0.05) return false;
|
|
267
|
+
|
|
268
|
+
const CharacterVec3 elevatedPos = addVec3(currentPos, scaleVec3(config.up, actualStepHeight));
|
|
269
|
+
|
|
270
|
+
// 2. Forward sweep at elevated position
|
|
271
|
+
CharacterHit fwdHit;
|
|
272
|
+
double forwardDist = horizLen;
|
|
273
|
+
if (queries.shapeCast(
|
|
274
|
+
queries.userData,
|
|
275
|
+
config.shape,
|
|
276
|
+
elevatedPos,
|
|
277
|
+
horizDir,
|
|
278
|
+
horizLen + config.skinWidth,
|
|
279
|
+
config.collisionMask,
|
|
280
|
+
config.excludedBodyIndex,
|
|
281
|
+
fwdHit)) {
|
|
282
|
+
forwardDist = std::max(0.0, fwdHit.distance - config.skinWidth);
|
|
283
|
+
}
|
|
284
|
+
if (forwardDist < config.minStepDistance) return false;
|
|
285
|
+
|
|
286
|
+
const CharacterVec3 forwardPos = addVec3(elevatedPos, scaleVec3(horizDir, forwardDist));
|
|
287
|
+
|
|
288
|
+
// 3. Downward cast to find step landing surface
|
|
289
|
+
CharacterHit downHit;
|
|
290
|
+
const double downCastDist = actualStepHeight + config.stepHeight + config.skinWidth * 2.0;
|
|
291
|
+
const CharacterVec3 downDir = scaleVec3(config.up, -1.0);
|
|
292
|
+
if (!queries.shapeCast(
|
|
293
|
+
queries.userData,
|
|
294
|
+
config.shape,
|
|
295
|
+
forwardPos,
|
|
296
|
+
downDir,
|
|
297
|
+
downCastDist,
|
|
298
|
+
config.collisionMask,
|
|
299
|
+
config.excludedBodyIndex,
|
|
300
|
+
downHit)) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
CharacterVec3 landNormal = downHit.normal;
|
|
305
|
+
if (dotVec3(landNormal, downDir) > 0.0) landNormal = scaleVec3(landNormal, -1.0);
|
|
306
|
+
const double cosSlope = dotVec3(landNormal, config.up);
|
|
307
|
+
if (cosSlope < std::cos(config.maxSlopeAngle)) return false;
|
|
308
|
+
|
|
309
|
+
const double landingAdvance = std::max(0.0, downHit.distance - config.skinWidth);
|
|
310
|
+
const CharacterVec3 landingPos = addVec3(forwardPos, scaleVec3(downDir, landingAdvance));
|
|
311
|
+
|
|
312
|
+
const double verticalDiff = dotVec3(subVec3(landingPos, currentPos), config.up);
|
|
313
|
+
if (verticalDiff <= 0.005 || verticalDiff > config.stepHeight + 1e-4) return false;
|
|
314
|
+
|
|
315
|
+
currentPos = landingPos;
|
|
316
|
+
state.steppedUp = true;
|
|
317
|
+
state.grounded = true;
|
|
318
|
+
state.groundNormal = landNormal;
|
|
319
|
+
state.groundBodyIndex = downHit.bodyIndex;
|
|
320
|
+
state.groundDistance = 0.0;
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
CharacterStatus stepCharacterController(
|
|
325
|
+
CharacterState& state,
|
|
326
|
+
const CharacterInput& input,
|
|
327
|
+
const CharacterConfig& config,
|
|
328
|
+
const CharacterQueryCallbacks& queries) {
|
|
329
|
+
if (input.dt <= 0.0) return CharacterStatus::InvalidInput;
|
|
330
|
+
|
|
331
|
+
// Reset per-step flags
|
|
332
|
+
state.hitWall = false;
|
|
333
|
+
state.hitCeiling = false;
|
|
334
|
+
state.steppedUp = false;
|
|
335
|
+
state.depenetrated = false;
|
|
336
|
+
state.slideCount = 0;
|
|
337
|
+
|
|
338
|
+
// 1. Initial depenetration
|
|
339
|
+
if (depenetrateCharacter(state.position, config, queries)) {
|
|
340
|
+
state.depenetrated = true;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// 2. Jump handling
|
|
344
|
+
if (input.jump && state.grounded) {
|
|
345
|
+
state.velocity.y = input.jumpSpeed;
|
|
346
|
+
state.grounded = false;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// 3. Air acceleration under gravity
|
|
350
|
+
if (!state.grounded) {
|
|
351
|
+
state.velocity.x += config.gravity.x * input.dt;
|
|
352
|
+
state.velocity.y += config.gravity.y * input.dt;
|
|
353
|
+
state.velocity.z += config.gravity.z * input.dt;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// 4. Movement decomposition
|
|
357
|
+
CharacterVec3 horizMove = {input.movement.x, 0.0, input.movement.z};
|
|
358
|
+
CharacterVec3 vertMove = {0.0, input.movement.y + state.velocity.y * input.dt, 0.0};
|
|
359
|
+
|
|
360
|
+
// 5. Slope motion projection when grounded
|
|
361
|
+
if (state.grounded) {
|
|
362
|
+
const double cosSlope = dotVec3(state.groundNormal, config.up);
|
|
363
|
+
if (cosSlope >= std::cos(config.maxSlopeAngle)) {
|
|
364
|
+
// Walkable slope: project horizontal movement onto slope tangent plane
|
|
365
|
+
const double slopeDot = dotVec3(horizMove, state.groundNormal);
|
|
366
|
+
horizMove = subVec3(horizMove, scaleVec3(state.groundNormal, slopeDot));
|
|
367
|
+
} else {
|
|
368
|
+
// Steep slope: cannot climb, slide downhill under gravity
|
|
369
|
+
const CharacterVec3 downhill = normalizeVec3(subVec3(scaleVec3(config.up, cosSlope), state.groundNormal));
|
|
370
|
+
const double downhillSpeed = lengthVec3(config.gravity) * input.dt;
|
|
371
|
+
horizMove = addVec3(horizMove, scaleVec3(downhill, downhillSpeed));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const bool wasGroundedBeforeMove = state.grounded;
|
|
376
|
+
|
|
377
|
+
// 6. Horizontal sweep-and-slide
|
|
378
|
+
if (lengthSquaredVec3(horizMove) > config.minStepDistance * config.minStepDistance) {
|
|
379
|
+
const CharacterVec3 prevPos = state.position;
|
|
380
|
+
CharacterVec3 remainingMove = horizMove;
|
|
381
|
+
sweepAndSlide(state.position, remainingMove, state, config, queries, true);
|
|
382
|
+
|
|
383
|
+
// Try stair step-up if blocked by obstacle
|
|
384
|
+
if (state.hitWall && wasGroundedBeforeMove) {
|
|
385
|
+
CharacterVec3 stepPos = prevPos;
|
|
386
|
+
if (tryStepUp(stepPos, horizMove, state, config, queries)) {
|
|
387
|
+
state.position = stepPos;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// 7. Vertical sweep-and-slide
|
|
393
|
+
if (lengthSquaredVec3(vertMove) > 1e-12) {
|
|
394
|
+
sweepAndSlide(state.position, vertMove, state, config, queries, false);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// 8. Ground support check & snap to ground
|
|
398
|
+
if (state.velocity.y <= 0.01) {
|
|
399
|
+
checkGroundSupport(state, config, queries);
|
|
400
|
+
|
|
401
|
+
if (wasGroundedBeforeMove && state.grounded && config.snapToGround && state.groundDistance > config.skinWidth) {
|
|
402
|
+
const double snapDist = state.groundDistance - config.skinWidth;
|
|
403
|
+
if (snapDist <= config.stepHeight + config.groundProbeDistance) {
|
|
404
|
+
state.position = subVec3(state.position, scaleVec3(config.up, snapDist));
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (state.grounded && state.velocity.y < 0.0) {
|
|
409
|
+
state.velocity.y = 0.0;
|
|
410
|
+
}
|
|
411
|
+
} else {
|
|
412
|
+
state.grounded = false;
|
|
413
|
+
state.groundBodyIndex = -1;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return CharacterStatus::Success;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
struct BodyQueryContext {
|
|
420
|
+
const double* bodyData = nullptr;
|
|
421
|
+
std::uint32_t bodyCount = 0;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
static bool bodyShapeCast(
|
|
425
|
+
void* userData,
|
|
426
|
+
const CharacterShape& shape,
|
|
427
|
+
const CharacterVec3& start,
|
|
428
|
+
const CharacterVec3& direction,
|
|
429
|
+
double maxDistance,
|
|
430
|
+
std::uint32_t layerMask,
|
|
431
|
+
std::int32_t excludedBodyIndex,
|
|
432
|
+
CharacterHit& hit) {
|
|
433
|
+
auto* ctx = static_cast<BodyQueryContext*>(userData);
|
|
434
|
+
if (ctx == nullptr || ctx->bodyData == nullptr || ctx->bodyCount == 0) return false;
|
|
435
|
+
|
|
436
|
+
std::array<double, 21> queryData{};
|
|
437
|
+
queryData[0] = static_cast<double>(shape.shape);
|
|
438
|
+
if (shape.shape == ShapeKind::Box) {
|
|
439
|
+
queryData[1] = shape.halfExtents.x;
|
|
440
|
+
queryData[2] = shape.halfExtents.y;
|
|
441
|
+
queryData[3] = shape.halfExtents.z;
|
|
442
|
+
} else if (shape.shape == ShapeKind::Capsule) {
|
|
443
|
+
queryData[1] = shape.radius;
|
|
444
|
+
queryData[2] = shape.halfHeight;
|
|
445
|
+
queryData[3] = 0.0;
|
|
446
|
+
} else if (shape.shape == ShapeKind::Sphere) {
|
|
447
|
+
queryData[1] = shape.radius;
|
|
448
|
+
queryData[2] = 0.0;
|
|
449
|
+
queryData[3] = 0.0;
|
|
450
|
+
}
|
|
451
|
+
queryData[4] = 0.0;
|
|
452
|
+
queryData[5] = 0.0;
|
|
453
|
+
queryData[6] = 0.0;
|
|
454
|
+
queryData[7] = start.x;
|
|
455
|
+
queryData[8] = start.y;
|
|
456
|
+
queryData[9] = start.z;
|
|
457
|
+
queryData[10] = 0.0;
|
|
458
|
+
queryData[11] = 0.0;
|
|
459
|
+
queryData[12] = 0.0;
|
|
460
|
+
queryData[13] = 1.0;
|
|
461
|
+
queryData[14] = direction.x;
|
|
462
|
+
queryData[15] = direction.y;
|
|
463
|
+
queryData[16] = direction.z;
|
|
464
|
+
queryData[17] = maxDistance;
|
|
465
|
+
queryData[18] = 0.0;
|
|
466
|
+
queryData[19] = static_cast<double>(layerMask);
|
|
467
|
+
queryData[20] = static_cast<double>(excludedBodyIndex);
|
|
468
|
+
|
|
469
|
+
const std::int32_t status = shapeCastSoA(ctx->bodyData, ctx->bodyCount, queryData.data(), 21);
|
|
470
|
+
if (status != 0) return false;
|
|
471
|
+
const std::uint32_t count = queryResultCount();
|
|
472
|
+
if (count == 0) return false;
|
|
473
|
+
|
|
474
|
+
const double* res = queryResultData();
|
|
475
|
+
hit.hit = true;
|
|
476
|
+
hit.bodyIndex = static_cast<std::int32_t>(res[0]);
|
|
477
|
+
hit.distance = res[1];
|
|
478
|
+
hit.point = {res[2], res[3], res[4]};
|
|
479
|
+
hit.normal = {res[5], res[6], res[7]};
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
static bool bodyOverlap(
|
|
484
|
+
void* userData,
|
|
485
|
+
const CharacterShape& shape,
|
|
486
|
+
const CharacterVec3& pos,
|
|
487
|
+
std::uint32_t layerMask,
|
|
488
|
+
std::int32_t excludedBodyIndex,
|
|
489
|
+
CharacterHit& hit) {
|
|
490
|
+
auto* ctx = static_cast<BodyQueryContext*>(userData);
|
|
491
|
+
if (ctx == nullptr || ctx->bodyData == nullptr || ctx->bodyCount == 0) return false;
|
|
492
|
+
|
|
493
|
+
std::array<double, 21> queryData{};
|
|
494
|
+
queryData[0] = static_cast<double>(shape.shape);
|
|
495
|
+
if (shape.shape == ShapeKind::Box) {
|
|
496
|
+
queryData[1] = shape.halfExtents.x;
|
|
497
|
+
queryData[2] = shape.halfExtents.y;
|
|
498
|
+
queryData[3] = shape.halfExtents.z;
|
|
499
|
+
} else if (shape.shape == ShapeKind::Capsule) {
|
|
500
|
+
queryData[1] = shape.radius;
|
|
501
|
+
queryData[2] = shape.halfHeight;
|
|
502
|
+
queryData[3] = 0.0;
|
|
503
|
+
} else if (shape.shape == ShapeKind::Sphere) {
|
|
504
|
+
queryData[1] = shape.radius;
|
|
505
|
+
queryData[2] = 0.0;
|
|
506
|
+
queryData[3] = 0.0;
|
|
507
|
+
}
|
|
508
|
+
queryData[4] = 0.0;
|
|
509
|
+
queryData[5] = 0.0;
|
|
510
|
+
queryData[6] = 0.0;
|
|
511
|
+
queryData[7] = pos.x;
|
|
512
|
+
queryData[8] = pos.y;
|
|
513
|
+
queryData[9] = pos.z;
|
|
514
|
+
queryData[10] = 0.0;
|
|
515
|
+
queryData[11] = 0.0;
|
|
516
|
+
queryData[12] = 0.0;
|
|
517
|
+
queryData[13] = 1.0;
|
|
518
|
+
queryData[14] = 1.0;
|
|
519
|
+
queryData[15] = 0.0;
|
|
520
|
+
queryData[16] = 0.0;
|
|
521
|
+
queryData[17] = 1.0;
|
|
522
|
+
queryData[18] = 0.0;
|
|
523
|
+
queryData[19] = static_cast<double>(layerMask);
|
|
524
|
+
queryData[20] = static_cast<double>(excludedBodyIndex);
|
|
525
|
+
|
|
526
|
+
const std::int32_t status = overlapSoA(ctx->bodyData, ctx->bodyCount, queryData.data(), 21);
|
|
527
|
+
if (status != 0) return false;
|
|
528
|
+
const std::uint32_t count = queryResultCount();
|
|
529
|
+
if (count == 0) return false;
|
|
530
|
+
|
|
531
|
+
const double* res = queryResultData();
|
|
532
|
+
hit.hit = true;
|
|
533
|
+
hit.bodyIndex = static_cast<std::int32_t>(res[0]);
|
|
534
|
+
hit.distance = res[1];
|
|
535
|
+
hit.point = {res[2], res[3], res[4]};
|
|
536
|
+
hit.normal = {res[5], res[6], res[7]};
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
CharacterStatus stepCharacterWithBodies(
|
|
541
|
+
CharacterState& state,
|
|
542
|
+
const CharacterInput& input,
|
|
543
|
+
const CharacterConfig& config,
|
|
544
|
+
const double* bodyData,
|
|
545
|
+
std::uint32_t bodyCount) {
|
|
546
|
+
BodyQueryContext ctx{bodyData, bodyCount};
|
|
547
|
+
CharacterQueryCallbacks queries{&ctx, bodyShapeCast, bodyOverlap};
|
|
548
|
+
return stepCharacterController(state, input, config, queries);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
} // namespace rundot::kinetix::physics
|
|
552
|
+
|
|
553
|
+
extern "C" {
|
|
554
|
+
|
|
555
|
+
std::uint32_t rundot_kinetix_physics_character_abi_version() {
|
|
556
|
+
return rundot::kinetix::physics::kCharacterAbiVersion;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
std::uint32_t rundot_kinetix_physics_character_input_stride() {
|
|
560
|
+
return rundot::kinetix::physics::kCharacterInputStride;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
std::uint32_t rundot_kinetix_physics_character_config_stride() {
|
|
564
|
+
return rundot::kinetix::physics::kCharacterConfigStride;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
std::uint32_t rundot_kinetix_physics_character_state_stride() {
|
|
568
|
+
return rundot::kinetix::physics::kCharacterStateStride;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
std::int32_t rundot_kinetix_physics_character_step(
|
|
572
|
+
const double* bodyData,
|
|
573
|
+
std::uint32_t bodyCount,
|
|
574
|
+
const double* inputData,
|
|
575
|
+
const double* configData,
|
|
576
|
+
double* stateData) {
|
|
577
|
+
if (inputData == nullptr || configData == nullptr || stateData == nullptr) {
|
|
578
|
+
return static_cast<std::int32_t>(rundot::kinetix::physics::CharacterStatus::InvalidInput);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
using namespace rundot::kinetix::physics;
|
|
582
|
+
|
|
583
|
+
CharacterInput input;
|
|
584
|
+
input.movement = {inputData[0], inputData[1], inputData[2]};
|
|
585
|
+
input.dt = inputData[3];
|
|
586
|
+
input.jump = inputData[4] != 0.0;
|
|
587
|
+
input.jumpSpeed = inputData[5];
|
|
588
|
+
|
|
589
|
+
CharacterConfig config;
|
|
590
|
+
config.up = {configData[0], configData[1], configData[2]};
|
|
591
|
+
config.maxSlopeAngle = configData[3];
|
|
592
|
+
config.stepHeight = configData[4];
|
|
593
|
+
config.skinWidth = configData[5];
|
|
594
|
+
config.minStepDistance = configData[6];
|
|
595
|
+
config.groundProbeDistance = configData[7];
|
|
596
|
+
config.gravity = {configData[8], configData[9], configData[10]};
|
|
597
|
+
config.maxSlideIterations = static_cast<std::uint32_t>(configData[11]);
|
|
598
|
+
config.snapToGround = configData[12] != 0.0;
|
|
599
|
+
config.shape.shape = static_cast<ShapeKind>(static_cast<std::uint32_t>(configData[13]));
|
|
600
|
+
config.shape.radius = configData[14];
|
|
601
|
+
config.shape.halfHeight = configData[15];
|
|
602
|
+
config.shape.halfExtents = {configData[14], configData[15], configData[14]};
|
|
603
|
+
config.collisionMask = static_cast<std::uint32_t>(configData[16]);
|
|
604
|
+
config.excludedBodyIndex = static_cast<std::int32_t>(configData[17]);
|
|
605
|
+
|
|
606
|
+
CharacterState state;
|
|
607
|
+
state.position = {stateData[0], stateData[1], stateData[2]};
|
|
608
|
+
state.velocity = {stateData[3], stateData[4], stateData[5]};
|
|
609
|
+
state.grounded = stateData[6] != 0.0;
|
|
610
|
+
state.groundNormal = {stateData[7], stateData[8], stateData[9]};
|
|
611
|
+
state.groundDistance = stateData[10];
|
|
612
|
+
state.groundBodyIndex = static_cast<std::int32_t>(stateData[11]);
|
|
613
|
+
|
|
614
|
+
const CharacterStatus status = stepCharacterWithBodies(state, input, config, bodyData, bodyCount);
|
|
615
|
+
if (status != CharacterStatus::Success) return static_cast<std::int32_t>(status);
|
|
616
|
+
|
|
617
|
+
stateData[0] = state.position.x;
|
|
618
|
+
stateData[1] = state.position.y;
|
|
619
|
+
stateData[2] = state.position.z;
|
|
620
|
+
stateData[3] = state.velocity.x;
|
|
621
|
+
stateData[4] = state.velocity.y;
|
|
622
|
+
stateData[5] = state.velocity.z;
|
|
623
|
+
stateData[6] = state.grounded ? 1.0 : 0.0;
|
|
624
|
+
stateData[7] = state.groundNormal.x;
|
|
625
|
+
stateData[8] = state.groundNormal.y;
|
|
626
|
+
stateData[9] = state.groundNormal.z;
|
|
627
|
+
stateData[10] = state.groundDistance;
|
|
628
|
+
stateData[11] = static_cast<double>(state.groundBodyIndex);
|
|
629
|
+
stateData[12] = state.hitWall ? 1.0 : 0.0;
|
|
630
|
+
stateData[13] = state.hitCeiling ? 1.0 : 0.0;
|
|
631
|
+
stateData[14] = state.steppedUp ? 1.0 : 0.0;
|
|
632
|
+
stateData[15] = state.depenetrated ? 1.0 : 0.0;
|
|
633
|
+
stateData[16] = static_cast<double>(state.slideCount);
|
|
634
|
+
|
|
635
|
+
return 0;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
} // extern "C"
|