@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include "queries.hpp"
|
|
2
|
+
#include "contour.hpp"
|
|
2
3
|
#include "../deterministic_math.hpp"
|
|
3
4
|
|
|
4
5
|
#include <algorithm>
|
|
@@ -27,6 +28,11 @@ double dot(Vec2 first, Vec2 second) { return first.x * second.x + first.y * seco
|
|
|
27
28
|
double cross(Vec2 first, Vec2 second) { return first.x * second.y - first.y * second.x; }
|
|
28
29
|
double lengthSquared(Vec2 value) { return dot(value, value); }
|
|
29
30
|
double magnitude(Vec2 value) { return std::sqrt(lengthSquared(value)); }
|
|
31
|
+
Vec2 normalizeVec(Vec2 v, Vec2 fallback = {1.0, 0.0}) {
|
|
32
|
+
const double len = magnitude(v);
|
|
33
|
+
if (len <= 1e-12) return fallback;
|
|
34
|
+
return scale(v, 1.0 / len);
|
|
35
|
+
}
|
|
30
36
|
Vec2 interpolate(Vec2 first, Vec2 second, double amount) {
|
|
31
37
|
if (amount == 0.0) return first;
|
|
32
38
|
if (amount == 1.0) return second;
|
|
@@ -34,6 +40,16 @@ Vec2 interpolate(Vec2 first, Vec2 second, double amount) {
|
|
|
34
40
|
}
|
|
35
41
|
double cleanZero(double value) { return value == 0.0 ? 0.0 : value; }
|
|
36
42
|
|
|
43
|
+
Vec2 rotate(Vec2 value, double angle) {
|
|
44
|
+
const double sine = rundot::detmath::det_sin(angle);
|
|
45
|
+
const double cosine = rundot::detmath::det_cos(angle);
|
|
46
|
+
return {cosine * value.x - sine * value.y, sine * value.x + cosine * value.y};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Vec2 inverseRotate(Vec2 value, double angle) {
|
|
50
|
+
return rotate(value, -angle);
|
|
51
|
+
}
|
|
52
|
+
|
|
37
53
|
double valueScale(double first, double second = 0.0, double third = 0.0) {
|
|
38
54
|
return std::max({1.0, absolute(first), absolute(second), absolute(third)});
|
|
39
55
|
}
|
|
@@ -94,13 +110,20 @@ bool excluded(const QueryFilter2D& filter, const std::uint32_t* ids, std::uint32
|
|
|
94
110
|
|
|
95
111
|
bool eligible(const Body& body, const QueryFilter2D& filter, const std::uint32_t* ids) {
|
|
96
112
|
const std::uint32_t bit = 1u << static_cast<std::uint32_t>(body.type);
|
|
97
|
-
|
|
113
|
+
if ((filter.bodyKindMask & bit) == 0 || (body.layer & filter.layerMask) == 0
|
|
114
|
+
|| excluded(filter, ids, body.id)) return false;
|
|
115
|
+
if ((body.filterFlags & kFilterSensor) != 0
|
|
116
|
+
&& (filter.flags & kQueryIncludeSensors) == 0) return false;
|
|
117
|
+
if ((body.filterFlags & kFilterTrigger) != 0
|
|
118
|
+
&& (filter.flags & kQueryIncludeTriggers) == 0) return false;
|
|
119
|
+
return body.filterFlags != 0 || (filter.flags & kQueryHitSolids) != 0;
|
|
98
120
|
}
|
|
99
121
|
|
|
100
122
|
QueryStatus2D validateFilter(
|
|
101
123
|
const QueryFilter2D& filter,
|
|
102
124
|
const std::uint32_t* excludedIds) {
|
|
103
|
-
if ((filter.bodyKindMask & ~7u) != 0 || filter.excludedBodyCount > kMaxBodies
|
|
125
|
+
if ((filter.bodyKindMask & ~7u) != 0 || filter.excludedBodyCount > kMaxBodies
|
|
126
|
+
|| (filter.flags & ~kQueryFilterFlagsMask) != 0) {
|
|
104
127
|
return QueryStatus2D::InvalidFilter;
|
|
105
128
|
}
|
|
106
129
|
for (std::uint32_t index = 1; index < filter.excludedBodyCount; index += 1) {
|
|
@@ -127,6 +150,9 @@ bool validBodyShapeSize(const Body& body) {
|
|
|
127
150
|
&& body.radius >= kQueryMinimumSize
|
|
128
151
|
&& body.radius <= kQueryMaximumLocalCoordinate;
|
|
129
152
|
}
|
|
153
|
+
if (body.shape == ShapeType::Segment || body.shape == ShapeType::Chain) {
|
|
154
|
+
return body.radius >= 0.0 && body.radius <= kQueryMaximumLocalCoordinate;
|
|
155
|
+
}
|
|
130
156
|
return true;
|
|
131
157
|
}
|
|
132
158
|
|
|
@@ -208,6 +234,11 @@ QueryStatus2D validateBodiesAndGeometry(
|
|
|
208
234
|
if (!validPolygonGeometrySlot(geometries[index])) {
|
|
209
235
|
return QueryStatus2D::InvalidGeometry;
|
|
210
236
|
}
|
|
237
|
+
ContourHeader2D ch{};
|
|
238
|
+
std::memcpy(&ch, &geometries[index], sizeof(ch));
|
|
239
|
+
if (ch.tag == kContourHeaderTag) {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
211
242
|
for (std::uint32_t vertex = geometries[index].vertexCount;
|
|
212
243
|
vertex < kMaxPolygonVertices; vertex += 1) {
|
|
213
244
|
if (!positiveZero(geometries[index].vertices[vertex].x)
|
|
@@ -701,7 +732,13 @@ BoundaryResult classifyBoundary(const RoundedHull& hull) {
|
|
|
701
732
|
result.classification = BoundaryResult::Class::Overlap;
|
|
702
733
|
return result;
|
|
703
734
|
}
|
|
704
|
-
result.
|
|
735
|
+
result.classification = BoundaryResult::Class::Touching;
|
|
736
|
+
result.normal = {0.0, 1.0};
|
|
737
|
+
result.activeNormals[0] = result.normal;
|
|
738
|
+
result.activeCorePoints[0] = result.corePoint;
|
|
739
|
+
result.activeTargetCores[0] = result.targetCore;
|
|
740
|
+
result.activeQueryCores[0] = result.queryCore;
|
|
741
|
+
result.activeNormalCount = 1;
|
|
705
742
|
return result;
|
|
706
743
|
}
|
|
707
744
|
result.normal = scale(result.corePoint, -1.0 / coreDistance);
|
|
@@ -1563,7 +1600,168 @@ CastHit2D castRecord(
|
|
|
1563
1600
|
return result;
|
|
1564
1601
|
}
|
|
1565
1602
|
|
|
1603
|
+
bool isChainOrSegment(ShapeType shape) {
|
|
1604
|
+
return shape == ShapeType::Segment || shape == ShapeType::Chain;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
struct QueryEdge2D {
|
|
1608
|
+
Vec2 p1{};
|
|
1609
|
+
Vec2 p2{};
|
|
1610
|
+
Vec2 normal{};
|
|
1611
|
+
double radius = 0.0;
|
|
1612
|
+
std::uint32_t featureId = 0;
|
|
1613
|
+
};
|
|
1614
|
+
|
|
1615
|
+
std::uint32_t getChainOrSegmentEdges(
|
|
1616
|
+
const Body& body,
|
|
1617
|
+
const PolygonGeometry* geometries,
|
|
1618
|
+
std::uint32_t geometryCount,
|
|
1619
|
+
std::array<QueryEdge2D, kMaxPolygonVertices>& edges) {
|
|
1620
|
+
const PolygonGeometry* geom = (geometries != nullptr && body.reserved < geometryCount)
|
|
1621
|
+
? &geometries[body.reserved] : nullptr;
|
|
1622
|
+
const Vec2 origin{body.x, body.y};
|
|
1623
|
+
const double c = std::cos(body.angle);
|
|
1624
|
+
const double s = std::sin(body.angle);
|
|
1625
|
+
auto transform = [&](Vec2 p) -> Vec2 {
|
|
1626
|
+
return {origin.x + c * p.x - s * p.y, origin.y + s * p.x + c * p.y};
|
|
1627
|
+
};
|
|
1628
|
+
|
|
1629
|
+
if (body.shape == ShapeType::Segment) {
|
|
1630
|
+
Vec2 lp1{-body.halfX, 0.0};
|
|
1631
|
+
Vec2 lp2{body.halfX, 0.0};
|
|
1632
|
+
if (geom != nullptr && geom->vertexCount >= 2) {
|
|
1633
|
+
if (geom->vertexCount >= 4) {
|
|
1634
|
+
lp1 = geom->vertices[1];
|
|
1635
|
+
lp2 = geom->vertices[2];
|
|
1636
|
+
} else if (geom->vertexCount == 3) {
|
|
1637
|
+
if ((geom->reserved & 1) != 0) {
|
|
1638
|
+
lp1 = geom->vertices[1];
|
|
1639
|
+
lp2 = geom->vertices[2];
|
|
1640
|
+
} else {
|
|
1641
|
+
lp1 = geom->vertices[0];
|
|
1642
|
+
lp2 = geom->vertices[1];
|
|
1643
|
+
}
|
|
1644
|
+
} else {
|
|
1645
|
+
lp1 = geom->vertices[0];
|
|
1646
|
+
lp2 = geom->vertices[1];
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
Vec2 wp1 = transform(lp1);
|
|
1650
|
+
Vec2 wp2 = transform(lp2);
|
|
1651
|
+
Vec2 e = subtract(wp2, wp1);
|
|
1652
|
+
double len = magnitude(e);
|
|
1653
|
+
if (len <= 1e-12) return 0;
|
|
1654
|
+
Vec2 t = scale(e, 1.0 / len);
|
|
1655
|
+
Vec2 n{t.y, -t.x};
|
|
1656
|
+
edges[0] = {wp1, wp2, n, body.radius, kEdgeFeature | 0u};
|
|
1657
|
+
return 1;
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
if (body.shape == ShapeType::Chain) {
|
|
1661
|
+
if (geom == nullptr || geom->vertexCount < 2 || geom->vertexCount > kMaxPolygonVertices) {
|
|
1662
|
+
return 0;
|
|
1663
|
+
}
|
|
1664
|
+
const bool isLoop = (geom->reserved & 1) != 0;
|
|
1665
|
+
const std::uint32_t n = geom->vertexCount;
|
|
1666
|
+
const std::uint32_t edgeCount = isLoop ? n : (n - 1);
|
|
1667
|
+
std::uint32_t count = 0;
|
|
1668
|
+
for (std::uint32_t i = 0; i < edgeCount; ++i) {
|
|
1669
|
+
Vec2 wp1 = transform(geom->vertices[i]);
|
|
1670
|
+
Vec2 wp2 = transform(geom->vertices[(i + 1) % n]);
|
|
1671
|
+
Vec2 e = subtract(wp2, wp1);
|
|
1672
|
+
double len = magnitude(e);
|
|
1673
|
+
if (len <= 1e-12) continue;
|
|
1674
|
+
Vec2 t = scale(e, 1.0 / len);
|
|
1675
|
+
Vec2 edgeNormal{t.y, -t.x};
|
|
1676
|
+
edges[count++] = {wp1, wp2, edgeNormal, body.radius, kEdgeFeature | i};
|
|
1677
|
+
}
|
|
1678
|
+
return count;
|
|
1679
|
+
}
|
|
1680
|
+
return 0;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
QueryStatus2D validateChainOrSegmentBody(
|
|
1684
|
+
const Body& body,
|
|
1685
|
+
const PolygonGeometry* geometries,
|
|
1686
|
+
std::uint32_t geometryCount) {
|
|
1687
|
+
if (!validBodyShapeSize(body)) return QueryStatus2D::NumericalResolution;
|
|
1688
|
+
if (!finite(body.x) || !finite(body.y) || !finite(body.angle) || !finite(body.radius)) {
|
|
1689
|
+
return QueryStatus2D::InvalidBody;
|
|
1690
|
+
}
|
|
1691
|
+
const PolygonGeometry* geom = (geometries != nullptr && body.reserved < geometryCount)
|
|
1692
|
+
? &geometries[body.reserved] : nullptr;
|
|
1693
|
+
if (body.shape == ShapeType::Segment) {
|
|
1694
|
+
if (geom != nullptr && geom->vertexCount > 0 && !validSegmentGeometry(*geom)) {
|
|
1695
|
+
return QueryStatus2D::InvalidGeometry;
|
|
1696
|
+
}
|
|
1697
|
+
} else if (body.shape == ShapeType::Chain) {
|
|
1698
|
+
if (geom == nullptr || !validChainGeometry(*geom)) {
|
|
1699
|
+
return QueryStatus2D::InvalidGeometry;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
std::array<QueryEdge2D, kMaxPolygonVertices> edges;
|
|
1703
|
+
const std::uint32_t count = getChainOrSegmentEdges(body, geometries, geometryCount, edges);
|
|
1704
|
+
for (std::uint32_t i = 0; i < count; ++i) {
|
|
1705
|
+
PreparedConvex2D edgeTarget{};
|
|
1706
|
+
edgeTarget.coreVertices[0] = edges[i].p1;
|
|
1707
|
+
edgeTarget.coreVertices[1] = edges[i].p2;
|
|
1708
|
+
edgeTarget.coreCount = 2;
|
|
1709
|
+
edgeTarget.radius = edges[i].radius;
|
|
1710
|
+
edgeTarget.sourceShape = ShapeType::Capsule;
|
|
1711
|
+
if (!supportBounds(edgeTarget)) return QueryStatus2D::NumericalResolution;
|
|
1712
|
+
}
|
|
1713
|
+
return QueryStatus2D::Success;
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
bool getContourBodyData(
|
|
1717
|
+
const QueryContext2D* context,
|
|
1718
|
+
const Body& body,
|
|
1719
|
+
const PolygonGeometry* geometries,
|
|
1720
|
+
std::uint32_t geometryCount,
|
|
1721
|
+
ContourHeader2D& outHeader,
|
|
1722
|
+
const ContourEdge2D*& outEdges) {
|
|
1723
|
+
if (body.shape != ShapeType::Contour) return false;
|
|
1724
|
+
if (geometries == nullptr || body.reserved >= geometryCount) return false;
|
|
1725
|
+
const PolygonGeometry& geom = geometries[body.reserved];
|
|
1726
|
+
std::memcpy(&outHeader, &geom, sizeof(outHeader));
|
|
1727
|
+
if (!validateContourHeader(outHeader, kMaxWorldContourEdges)) return false;
|
|
1728
|
+
|
|
1729
|
+
if (context != nullptr && context->contourEdges != nullptr &&
|
|
1730
|
+
outHeader.firstEdge + outHeader.edgeCount <= context->contourEdgeCount) {
|
|
1731
|
+
outEdges = &context->contourEdges[outHeader.firstEdge];
|
|
1732
|
+
return true;
|
|
1733
|
+
}
|
|
1734
|
+
const ContourEdge2D* legacyEdges = legacyContourEdges();
|
|
1735
|
+
const std::uint32_t legacyCount = legacyContourEdgeCount();
|
|
1736
|
+
if (legacyEdges != nullptr && outHeader.firstEdge + outHeader.edgeCount <= legacyCount) {
|
|
1737
|
+
outEdges = &legacyEdges[outHeader.firstEdge];
|
|
1738
|
+
return true;
|
|
1739
|
+
}
|
|
1740
|
+
return false;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
QueryStatus2D validateContourBody(
|
|
1744
|
+
const QueryContext2D* context,
|
|
1745
|
+
const Body& body,
|
|
1746
|
+
const PolygonGeometry* geometries,
|
|
1747
|
+
std::uint32_t geometryCount) {
|
|
1748
|
+
if (!validBodyShapeSize(body)) return QueryStatus2D::NumericalResolution;
|
|
1749
|
+
if (!finite(body.x) || !finite(body.y) || !finite(body.angle) || !finite(body.radius)) {
|
|
1750
|
+
return QueryStatus2D::InvalidBody;
|
|
1751
|
+
}
|
|
1752
|
+
ContourHeader2D header{};
|
|
1753
|
+
const ContourEdge2D* edges = nullptr;
|
|
1754
|
+
if (!getContourBodyData(context, body, geometries, geometryCount, header, edges)) {
|
|
1755
|
+
return QueryStatus2D::InvalidGeometry;
|
|
1756
|
+
}
|
|
1757
|
+
if (!validateContourEdges(header, edges, header.edgeCount)) {
|
|
1758
|
+
return QueryStatus2D::InvalidGeometry;
|
|
1759
|
+
}
|
|
1760
|
+
return QueryStatus2D::Success;
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1566
1763
|
QueryStatus2D validateEligibleBodies(
|
|
1764
|
+
const QueryContext2D* context,
|
|
1567
1765
|
const Body* bodies,
|
|
1568
1766
|
std::uint32_t bodyCount,
|
|
1569
1767
|
const PolygonGeometry* geometries,
|
|
@@ -1572,10 +1770,20 @@ QueryStatus2D validateEligibleBodies(
|
|
|
1572
1770
|
const std::uint32_t* excludedIds) {
|
|
1573
1771
|
for (std::uint32_t index = 0; index < bodyCount; index += 1) {
|
|
1574
1772
|
if (!eligible(bodies[index], filter, excludedIds)) continue;
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1773
|
+
if (bodies[index].shape == ShapeType::Contour) {
|
|
1774
|
+
const QueryStatus2D status = validateContourBody(
|
|
1775
|
+
context, bodies[index], geometries, geometryCount);
|
|
1776
|
+
if (status != QueryStatus2D::Success) return status;
|
|
1777
|
+
} else if (isChainOrSegment(bodies[index].shape)) {
|
|
1778
|
+
const QueryStatus2D status = validateChainOrSegmentBody(
|
|
1779
|
+
bodies[index], geometries, geometryCount);
|
|
1780
|
+
if (status != QueryStatus2D::Success) return status;
|
|
1781
|
+
} else {
|
|
1782
|
+
PreparedConvex2D prepared;
|
|
1783
|
+
const QueryStatus2D status = prepareBodyForQuery(
|
|
1784
|
+
bodies[index], geometries, geometryCount, prepared);
|
|
1785
|
+
if (status != QueryStatus2D::Success) return status;
|
|
1786
|
+
}
|
|
1579
1787
|
}
|
|
1580
1788
|
return QueryStatus2D::Success;
|
|
1581
1789
|
}
|
|
@@ -1619,7 +1827,7 @@ std::int32_t raycastQuery(
|
|
|
1619
1827
|
return static_cast<std::int32_t>(QueryStatus2D::NumericalResolution);
|
|
1620
1828
|
}
|
|
1621
1829
|
status = validateEligibleBodies(
|
|
1622
|
-
bodies, bodyCount, geometries, geometryCount, *filter, excludedIds);
|
|
1830
|
+
context, bodies, bodyCount, geometries, geometryCount, *filter, excludedIds);
|
|
1623
1831
|
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
1624
1832
|
if (request->maxResults == 0) {
|
|
1625
1833
|
*outputCount = 0;
|
|
@@ -1629,22 +1837,152 @@ std::int32_t raycastQuery(
|
|
|
1629
1837
|
std::uint32_t candidateCount = 0;
|
|
1630
1838
|
for (std::uint32_t index = 0; index < bodyCount; index += 1) {
|
|
1631
1839
|
if (!eligible(bodies[index], *filter, excludedIds)) continue;
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1840
|
+
if (bodies[index].shape == ShapeType::Contour) {
|
|
1841
|
+
ContourHeader2D header{};
|
|
1842
|
+
const ContourEdge2D* edges = nullptr;
|
|
1843
|
+
if (!getContourBodyData(context, bodies[index], geometries, geometryCount, header, edges)) {
|
|
1844
|
+
continue;
|
|
1845
|
+
}
|
|
1846
|
+
const Vec2 contourOrigin{bodies[index].x, bodies[index].y};
|
|
1847
|
+
const double contourAngle = bodies[index].angle;
|
|
1848
|
+
const Vec2 rayOriginWorld{request->x, request->y};
|
|
1849
|
+
const Vec2 rayOrigin = (contourOrigin.x == 0.0 && contourOrigin.y == 0.0 && contourAngle == 0.0)
|
|
1850
|
+
? rayOriginWorld
|
|
1851
|
+
: inverseRotate(subtract(rayOriginWorld, contourOrigin), contourAngle);
|
|
1852
|
+
const Vec2 localDir = (contourAngle == 0.0) ? direction : inverseRotate(direction, contourAngle);
|
|
1853
|
+
const Vec2 localTrans = (contourAngle == 0.0) ? translation : inverseRotate(translation, contourAngle);
|
|
1854
|
+
PreparedConvex2D localQuery = query;
|
|
1855
|
+
localQuery.coreVertices[0] = rayOrigin;
|
|
1856
|
+
const Bounds localQueryBounds = sweptBounds(localQuery, localTrans);
|
|
1857
|
+
const std::uint32_t totalEdges = header.reserved > 0 ? header.reserved : header.edgeCount;
|
|
1858
|
+
|
|
1859
|
+
if (header.fill == 1 && windingNumber(rayOrigin, edges, totalEdges) != 0) {
|
|
1860
|
+
SurfaceResult surface{};
|
|
1861
|
+
surface.hit = true;
|
|
1862
|
+
surface.initialOverlap = true;
|
|
1863
|
+
surface.fraction = 0.0;
|
|
1864
|
+
surface.feature = kNoFeature;
|
|
1865
|
+
surface.point = rayOrigin;
|
|
1866
|
+
surface.normal = {0.0, 0.0};
|
|
1867
|
+
if (contourOrigin.x != 0.0 || contourOrigin.y != 0.0 || contourAngle != 0.0) {
|
|
1868
|
+
surface.point = add(contourOrigin, rotate(surface.point, contourAngle));
|
|
1869
|
+
surface.normal = rotate(surface.normal, contourAngle);
|
|
1870
|
+
}
|
|
1871
|
+
context->candidates[candidateCount++] = castRecord(
|
|
1872
|
+
bodies[index].id, surface, request->maxDistance);
|
|
1873
|
+
continue;
|
|
1874
|
+
}
|
|
1875
|
+
SurfaceResult bestSurface;
|
|
1876
|
+
bestSurface.fraction = std::numeric_limits<double>::infinity();
|
|
1877
|
+
for (std::uint32_t e = 0; e < totalEdges; ++e) {
|
|
1878
|
+
const auto& edge = edges[e];
|
|
1879
|
+
if (edge.kind == 2) continue; // ghost
|
|
1880
|
+
if (edge.kind == 0) { // Line
|
|
1881
|
+
const Vec2 edgeVec = subtract(edge.to, edge.from);
|
|
1882
|
+
const double edgeLen = magnitude(edgeVec);
|
|
1883
|
+
if (edgeLen <= 1e-12) continue;
|
|
1884
|
+
const Vec2 t = scale(edgeVec, 1.0 / edgeLen);
|
|
1885
|
+
const Vec2 n{t.y, -t.x};
|
|
1886
|
+
if (dot(localDir, n) >= 0.0) continue;
|
|
1887
|
+
|
|
1888
|
+
PreparedConvex2D target{};
|
|
1889
|
+
target.coreVertices[0] = edge.from;
|
|
1890
|
+
target.coreVertices[1] = edge.to;
|
|
1891
|
+
target.coreCount = 2;
|
|
1892
|
+
target.radius = header.skin;
|
|
1893
|
+
target.sourceShape = ShapeType::Capsule;
|
|
1894
|
+
if (disjoint(sweptBounds(target), localQueryBounds)) continue;
|
|
1895
|
+
RoundedHull hull;
|
|
1896
|
+
BoundaryResult boundary;
|
|
1897
|
+
status = makeHull(target, localQuery, hull, boundary);
|
|
1898
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
1899
|
+
SurfaceResult surface = castRoundedHull(
|
|
1900
|
+
target, localQuery, hull, boundary, localDir, localTrans);
|
|
1901
|
+
if (surface.status != QueryStatus2D::Success) {
|
|
1902
|
+
return static_cast<std::int32_t>(surface.status);
|
|
1903
|
+
}
|
|
1904
|
+
if (surface.hit && surface.fraction < bestSurface.fraction) {
|
|
1905
|
+
surface.feature = edgeFeature(e);
|
|
1906
|
+
surface.normal = n;
|
|
1907
|
+
bestSurface = surface;
|
|
1908
|
+
}
|
|
1909
|
+
} else if (edge.kind == 1) { // Arc
|
|
1910
|
+
double hitT = 0.0;
|
|
1911
|
+
Vec2 hitNormal{};
|
|
1912
|
+
if (rayEdge(rayOrigin, localDir, request->maxDistance, edge, header.skin, &hitT, &hitNormal)) {
|
|
1913
|
+
if (dot(localDir, hitNormal) < 0.0) {
|
|
1914
|
+
const double frac = hitT / request->maxDistance;
|
|
1915
|
+
if (frac < bestSurface.fraction) {
|
|
1916
|
+
bestSurface.hit = true;
|
|
1917
|
+
bestSurface.fraction = frac;
|
|
1918
|
+
bestSurface.point = add(rayOrigin, scale(localDir, hitT));
|
|
1919
|
+
bestSurface.normal = hitNormal;
|
|
1920
|
+
bestSurface.feature = curveFeature(e);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
if (bestSurface.hit) {
|
|
1927
|
+
if (contourOrigin.x != 0.0 || contourOrigin.y != 0.0 || contourAngle != 0.0) {
|
|
1928
|
+
bestSurface.point = add(contourOrigin, rotate(bestSurface.point, contourAngle));
|
|
1929
|
+
bestSurface.normal = rotate(bestSurface.normal, contourAngle);
|
|
1930
|
+
}
|
|
1931
|
+
context->candidates[candidateCount++] = castRecord(
|
|
1932
|
+
bodies[index].id, bestSurface, request->maxDistance);
|
|
1933
|
+
}
|
|
1934
|
+
} else if (isChainOrSegment(bodies[index].shape)) {
|
|
1935
|
+
std::array<QueryEdge2D, kMaxPolygonVertices> edges;
|
|
1936
|
+
const std::uint32_t edgeCount = getChainOrSegmentEdges(
|
|
1937
|
+
bodies[index], geometries, geometryCount, edges);
|
|
1938
|
+
SurfaceResult bestSurface;
|
|
1939
|
+
bestSurface.fraction = std::numeric_limits<double>::infinity();
|
|
1940
|
+
for (std::uint32_t e = 0; e < edgeCount; ++e) {
|
|
1941
|
+
if (dot(direction, edges[e].normal) >= 0.0) continue;
|
|
1942
|
+
PreparedConvex2D target{};
|
|
1943
|
+
target.coreVertices[0] = edges[e].p1;
|
|
1944
|
+
target.coreVertices[1] = edges[e].p2;
|
|
1945
|
+
target.coreCount = 2;
|
|
1946
|
+
target.radius = edges[e].radius;
|
|
1947
|
+
target.sourceShape = ShapeType::Capsule;
|
|
1948
|
+
if (disjoint(sweptBounds(target), queryBounds)) continue;
|
|
1949
|
+
RoundedHull hull;
|
|
1950
|
+
BoundaryResult boundary;
|
|
1951
|
+
status = makeHull(target, query, hull, boundary);
|
|
1952
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
1953
|
+
SurfaceResult surface = castRoundedHull(
|
|
1954
|
+
target, query, hull, boundary, direction, translation);
|
|
1955
|
+
if (surface.status != QueryStatus2D::Success) {
|
|
1956
|
+
return static_cast<std::int32_t>(surface.status);
|
|
1957
|
+
}
|
|
1958
|
+
if (surface.hit && surface.fraction < bestSurface.fraction) {
|
|
1959
|
+
surface.feature = edges[e].featureId;
|
|
1960
|
+
surface.normal = edges[e].normal;
|
|
1961
|
+
bestSurface = surface;
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
if (bestSurface.hit) {
|
|
1965
|
+
context->candidates[candidateCount++] = castRecord(
|
|
1966
|
+
bodies[index].id, bestSurface, request->maxDistance);
|
|
1967
|
+
}
|
|
1968
|
+
} else {
|
|
1969
|
+
PreparedConvex2D target;
|
|
1970
|
+
status = prepareBodyForQuery(bodies[index], geometries, geometryCount, target);
|
|
1971
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
1972
|
+
if (disjoint(sweptBounds(target), queryBounds)) continue;
|
|
1973
|
+
RoundedHull hull;
|
|
1974
|
+
BoundaryResult boundary;
|
|
1975
|
+
status = makeHull(target, query, hull, boundary);
|
|
1976
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
1977
|
+
const SurfaceResult surface = castRoundedHull(
|
|
1978
|
+
target, query, hull, boundary, direction, translation);
|
|
1979
|
+
if (surface.status != QueryStatus2D::Success) {
|
|
1980
|
+
return static_cast<std::int32_t>(surface.status);
|
|
1981
|
+
}
|
|
1982
|
+
if (surface.hit) {
|
|
1983
|
+
context->candidates[candidateCount++] = castRecord(
|
|
1984
|
+
bodies[index].id, surface, request->maxDistance);
|
|
1985
|
+
}
|
|
1648
1986
|
}
|
|
1649
1987
|
}
|
|
1650
1988
|
std::sort(context->candidates, context->candidates + candidateCount, castLess);
|
|
@@ -1683,7 +2021,7 @@ std::int32_t overlapQuery(
|
|
|
1683
2021
|
request->shape, request->x, request->y, request->angle, query);
|
|
1684
2022
|
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
1685
2023
|
status = validateEligibleBodies(
|
|
1686
|
-
bodies, bodyCount, geometries, geometryCount, *filter, excludedIds);
|
|
2024
|
+
context, bodies, bodyCount, geometries, geometryCount, *filter, excludedIds);
|
|
1687
2025
|
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
1688
2026
|
if (request->maxResults == 0) {
|
|
1689
2027
|
*outputCount = 0;
|
|
@@ -1693,18 +2031,123 @@ std::int32_t overlapQuery(
|
|
|
1693
2031
|
std::uint32_t candidateCount = 0;
|
|
1694
2032
|
for (std::uint32_t index = 0; index < bodyCount; index += 1) {
|
|
1695
2033
|
if (!eligible(bodies[index], *filter, excludedIds)) continue;
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
2034
|
+
if (bodies[index].shape == ShapeType::Contour) {
|
|
2035
|
+
ContourHeader2D header{};
|
|
2036
|
+
const ContourEdge2D* edges = nullptr;
|
|
2037
|
+
if (!getContourBodyData(context, bodies[index], geometries, geometryCount, header, edges)) {
|
|
2038
|
+
continue;
|
|
2039
|
+
}
|
|
2040
|
+
const Vec2 contourOrigin{bodies[index].x, bodies[index].y};
|
|
2041
|
+
const double contourAngle = bodies[index].angle;
|
|
2042
|
+
|
|
2043
|
+
PreparedConvex2D localQuery = query;
|
|
2044
|
+
if (contourOrigin.x != 0.0 || contourOrigin.y != 0.0 || contourAngle != 0.0) {
|
|
2045
|
+
for (std::uint32_t v = 0; v < localQuery.coreCount; ++v) {
|
|
2046
|
+
localQuery.coreVertices[v] = inverseRotate(subtract(localQuery.coreVertices[v], contourOrigin), contourAngle);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
const Vec2 queryCenter = (localQuery.coreCount == 1)
|
|
2050
|
+
? localQuery.coreVertices[0]
|
|
2051
|
+
: scale(add(localQuery.coreVertices[0], localQuery.coreVertices[1]), 0.5);
|
|
2052
|
+
const Bounds localQueryBounds = sweptBounds(localQuery);
|
|
2053
|
+
const std::uint32_t totalEdges = header.reserved > 0 ? header.reserved : header.edgeCount;
|
|
2054
|
+
|
|
2055
|
+
bool anyHit = false;
|
|
2056
|
+
if (header.fill == 1 && windingNumber(queryCenter, edges, totalEdges) != 0) {
|
|
2057
|
+
anyHit = true;
|
|
2058
|
+
}
|
|
2059
|
+
if (!anyHit) {
|
|
2060
|
+
for (std::uint32_t e = 0; e < totalEdges; ++e) {
|
|
2061
|
+
const auto& edge = edges[e];
|
|
2062
|
+
if (edge.kind == 2) continue; // ghost
|
|
2063
|
+
if (edge.kind == 0) { // Line
|
|
2064
|
+
PreparedConvex2D target{};
|
|
2065
|
+
target.coreVertices[0] = edge.from;
|
|
2066
|
+
target.coreVertices[1] = edge.to;
|
|
2067
|
+
target.coreCount = 2;
|
|
2068
|
+
target.radius = header.skin;
|
|
2069
|
+
target.sourceShape = ShapeType::Capsule;
|
|
2070
|
+
if (disjoint(sweptBounds(target), localQueryBounds)) continue;
|
|
2071
|
+
RoundedHull hull;
|
|
2072
|
+
BoundaryResult boundary;
|
|
2073
|
+
status = makeHull(target, localQuery, hull, boundary);
|
|
2074
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2075
|
+
if (boundary.classification != BoundaryResult::Class::Separated) {
|
|
2076
|
+
anyHit = true;
|
|
2077
|
+
break;
|
|
2078
|
+
}
|
|
2079
|
+
} else if (edge.kind == 1) { // Arc
|
|
2080
|
+
bool arcHit = false;
|
|
2081
|
+
if (localQuery.coreCount == 1) {
|
|
2082
|
+
const double dist = edgeDistance(queryCenter, localQuery.radius, edge, header.skin);
|
|
2083
|
+
if (dist <= 0.0) arcHit = true;
|
|
2084
|
+
} else if (localQuery.coreCount == 2 && localQuery.radius > 0.0 && localQuery.sourceShape == ShapeType::Capsule) {
|
|
2085
|
+
const double dist = segmentArcDistance(localQuery.coreVertices[0], localQuery.coreVertices[1], edge, header.skin + localQuery.radius);
|
|
2086
|
+
if (dist <= 0.0) arcHit = true;
|
|
2087
|
+
} else {
|
|
2088
|
+
for (std::uint32_t v = 0; v < localQuery.coreCount; ++v) {
|
|
2089
|
+
const Vec2 p1 = localQuery.coreVertices[v];
|
|
2090
|
+
const Vec2 p2 = localQuery.coreVertices[(v + 1) % localQuery.coreCount];
|
|
2091
|
+
const double dist = segmentArcDistance(p1, p2, edge, header.skin + localQuery.radius);
|
|
2092
|
+
if (dist <= 0.0) {
|
|
2093
|
+
arcHit = true;
|
|
2094
|
+
break;
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
if (arcHit) {
|
|
2099
|
+
anyHit = true;
|
|
2100
|
+
break;
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
if (anyHit) {
|
|
2106
|
+
CastHit2D& candidate = context->candidates[candidateCount++];
|
|
2107
|
+
candidate = {};
|
|
2108
|
+
candidate.bodyId = bodies[index].id;
|
|
2109
|
+
}
|
|
2110
|
+
} else if (isChainOrSegment(bodies[index].shape)) {
|
|
2111
|
+
std::array<QueryEdge2D, kMaxPolygonVertices> edges;
|
|
2112
|
+
const std::uint32_t edgeCount = getChainOrSegmentEdges(
|
|
2113
|
+
bodies[index], geometries, geometryCount, edges);
|
|
2114
|
+
bool anyHit = false;
|
|
2115
|
+
for (std::uint32_t e = 0; e < edgeCount; ++e) {
|
|
2116
|
+
PreparedConvex2D target{};
|
|
2117
|
+
target.coreVertices[0] = edges[e].p1;
|
|
2118
|
+
target.coreVertices[1] = edges[e].p2;
|
|
2119
|
+
target.coreCount = 2;
|
|
2120
|
+
target.radius = edges[e].radius;
|
|
2121
|
+
target.sourceShape = ShapeType::Capsule;
|
|
2122
|
+
if (disjoint(sweptBounds(target), queryBounds)) continue;
|
|
2123
|
+
RoundedHull hull;
|
|
2124
|
+
BoundaryResult boundary;
|
|
2125
|
+
status = makeHull(target, query, hull, boundary);
|
|
2126
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2127
|
+
if (boundary.classification != BoundaryResult::Class::Separated) {
|
|
2128
|
+
anyHit = true;
|
|
2129
|
+
break;
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
if (anyHit) {
|
|
2133
|
+
CastHit2D& candidate = context->candidates[candidateCount++];
|
|
2134
|
+
candidate = {};
|
|
2135
|
+
candidate.bodyId = bodies[index].id;
|
|
2136
|
+
}
|
|
2137
|
+
} else {
|
|
2138
|
+
PreparedConvex2D target;
|
|
2139
|
+
status = prepareBodyForQuery(bodies[index], geometries, geometryCount, target);
|
|
2140
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2141
|
+
if (disjoint(sweptBounds(target), queryBounds)) continue;
|
|
2142
|
+
RoundedHull hull;
|
|
2143
|
+
BoundaryResult boundary;
|
|
2144
|
+
status = makeHull(target, query, hull, boundary);
|
|
2145
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2146
|
+
if (boundary.classification != BoundaryResult::Class::Separated) {
|
|
2147
|
+
CastHit2D& candidate = context->candidates[candidateCount++];
|
|
2148
|
+
candidate = {};
|
|
2149
|
+
candidate.bodyId = bodies[index].id;
|
|
2150
|
+
}
|
|
1708
2151
|
}
|
|
1709
2152
|
}
|
|
1710
2153
|
std::sort(context->candidates, context->candidates + candidateCount,
|
|
@@ -1754,7 +2197,7 @@ std::int32_t shapeCastQuery(
|
|
|
1754
2197
|
return static_cast<std::int32_t>(QueryStatus2D::NumericalResolution);
|
|
1755
2198
|
}
|
|
1756
2199
|
status = validateEligibleBodies(
|
|
1757
|
-
bodies, bodyCount, geometries, geometryCount, *filter, excludedIds);
|
|
2200
|
+
context, bodies, bodyCount, geometries, geometryCount, *filter, excludedIds);
|
|
1758
2201
|
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
1759
2202
|
if (request->maxResults == 0) {
|
|
1760
2203
|
*outputCount = 0;
|
|
@@ -1764,22 +2207,239 @@ std::int32_t shapeCastQuery(
|
|
|
1764
2207
|
std::uint32_t candidateCount = 0;
|
|
1765
2208
|
for (std::uint32_t index = 0; index < bodyCount; index += 1) {
|
|
1766
2209
|
if (!eligible(bodies[index], *filter, excludedIds)) continue;
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
2210
|
+
if (bodies[index].shape == ShapeType::Contour) {
|
|
2211
|
+
ContourHeader2D header{};
|
|
2212
|
+
const ContourEdge2D* edges = nullptr;
|
|
2213
|
+
if (!getContourBodyData(context, bodies[index], geometries, geometryCount, header, edges)) {
|
|
2214
|
+
continue;
|
|
2215
|
+
}
|
|
2216
|
+
const Vec2 contourOrigin{bodies[index].x, bodies[index].y};
|
|
2217
|
+
const double contourAngle = bodies[index].angle;
|
|
2218
|
+
|
|
2219
|
+
PreparedConvex2D localQuery = query;
|
|
2220
|
+
Vec2 localDir = direction;
|
|
2221
|
+
Vec2 localTranslation = translation;
|
|
2222
|
+
if (contourOrigin.x != 0.0 || contourOrigin.y != 0.0 || contourAngle != 0.0) {
|
|
2223
|
+
for (std::uint32_t v = 0; v < localQuery.coreCount; ++v) {
|
|
2224
|
+
localQuery.coreVertices[v] = inverseRotate(subtract(localQuery.coreVertices[v], contourOrigin), contourAngle);
|
|
2225
|
+
}
|
|
2226
|
+
localDir = inverseRotate(direction, contourAngle);
|
|
2227
|
+
localTranslation = inverseRotate(translation, contourAngle);
|
|
2228
|
+
}
|
|
2229
|
+
const Vec2 queryStart = (localQuery.coreCount == 1)
|
|
2230
|
+
? localQuery.coreVertices[0]
|
|
2231
|
+
: scale(add(localQuery.coreVertices[0], localQuery.coreVertices[1]), 0.5);
|
|
2232
|
+
const Bounds localQueryBounds = sweptBounds(localQuery, localTranslation);
|
|
2233
|
+
const std::uint32_t totalEdges = header.reserved > 0 ? header.reserved : header.edgeCount;
|
|
2234
|
+
|
|
2235
|
+
if (header.fill == 1 && windingNumber(queryStart, edges, totalEdges) != 0) {
|
|
2236
|
+
SurfaceResult surface{};
|
|
2237
|
+
surface.hit = true;
|
|
2238
|
+
surface.initialOverlap = true;
|
|
2239
|
+
surface.fraction = 0.0;
|
|
2240
|
+
surface.feature = kNoFeature;
|
|
2241
|
+
surface.point = queryStart;
|
|
2242
|
+
surface.normal = {0.0, 0.0};
|
|
2243
|
+
if (contourOrigin.x != 0.0 || contourOrigin.y != 0.0 || contourAngle != 0.0) {
|
|
2244
|
+
surface.point = add(contourOrigin, rotate(surface.point, contourAngle));
|
|
2245
|
+
surface.normal = rotate(surface.normal, contourAngle);
|
|
2246
|
+
}
|
|
2247
|
+
context->candidates[candidateCount++] = castRecord(
|
|
2248
|
+
bodies[index].id, surface, request->maxDistance);
|
|
2249
|
+
continue;
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
SurfaceResult bestSurface;
|
|
2253
|
+
bestSurface.fraction = std::numeric_limits<double>::infinity();
|
|
2254
|
+
for (std::uint32_t e = 0; e < totalEdges; ++e) {
|
|
2255
|
+
const auto& edge = edges[e];
|
|
2256
|
+
if (edge.kind == 2) continue; // ghost
|
|
2257
|
+
if (edge.kind == 0) { // Line
|
|
2258
|
+
const Vec2 edgeVec = subtract(edge.to, edge.from);
|
|
2259
|
+
const double edgeLen = magnitude(edgeVec);
|
|
2260
|
+
if (edgeLen <= 1e-12) continue;
|
|
2261
|
+
const Vec2 t = scale(edgeVec, 1.0 / edgeLen);
|
|
2262
|
+
const Vec2 n{t.y, -t.x};
|
|
2263
|
+
|
|
2264
|
+
PreparedConvex2D target{};
|
|
2265
|
+
target.coreVertices[0] = edge.from;
|
|
2266
|
+
target.coreVertices[1] = edge.to;
|
|
2267
|
+
target.coreCount = 2;
|
|
2268
|
+
target.radius = header.skin;
|
|
2269
|
+
target.sourceShape = ShapeType::Capsule;
|
|
2270
|
+
if (disjoint(sweptBounds(target), localQueryBounds)) continue;
|
|
2271
|
+
RoundedHull hull;
|
|
2272
|
+
BoundaryResult boundary;
|
|
2273
|
+
status = makeHull(target, localQuery, hull, boundary);
|
|
2274
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2275
|
+
SurfaceResult surface = castRoundedHull(
|
|
2276
|
+
target, localQuery, hull, boundary, localDir, localTranslation);
|
|
2277
|
+
if (surface.status != QueryStatus2D::Success) {
|
|
2278
|
+
return static_cast<std::int32_t>(surface.status);
|
|
2279
|
+
}
|
|
2280
|
+
if (surface.hit) {
|
|
2281
|
+
const Vec2 queryCenterAtHit = add(queryStart, scale(localTranslation, surface.fraction));
|
|
2282
|
+
const double freeSideDist = dot(subtract(queryCenterAtHit, edge.from), n);
|
|
2283
|
+
if (freeSideDist < -header.skin - 1e-4) continue;
|
|
2284
|
+
if (dot(localDir, n) >= 0.0) continue;
|
|
2285
|
+
if (surface.fraction < bestSurface.fraction) {
|
|
2286
|
+
surface.feature = edgeFeature(e);
|
|
2287
|
+
surface.normal = n;
|
|
2288
|
+
bestSurface = surface;
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
} else if (edge.kind == 1) { // Arc
|
|
2292
|
+
double t = 0.0;
|
|
2293
|
+
bool converged = false;
|
|
2294
|
+
SurfaceResult arcSurface{};
|
|
2295
|
+
constexpr std::uint32_t kMaxIterations = 32;
|
|
2296
|
+
constexpr double kHitTolerance = 1e-6;
|
|
2297
|
+
|
|
2298
|
+
for (std::uint32_t iter = 0; iter < kMaxIterations; ++iter) {
|
|
2299
|
+
const Vec2 currentCenter = add(queryStart, scale(localDir, t));
|
|
2300
|
+
double dist = 0.0;
|
|
2301
|
+
if (localQuery.coreCount == 1) {
|
|
2302
|
+
dist = edgeDistance(currentCenter, localQuery.radius, edge, header.skin);
|
|
2303
|
+
} else if (localQuery.coreCount == 2 && localQuery.radius > 0.0 && localQuery.sourceShape == ShapeType::Capsule) {
|
|
2304
|
+
const Vec2 v0 = add(localQuery.coreVertices[0], scale(localDir, t));
|
|
2305
|
+
const Vec2 v1 = add(localQuery.coreVertices[1], scale(localDir, t));
|
|
2306
|
+
dist = segmentArcDistance(v0, v1, edge, header.skin + localQuery.radius);
|
|
2307
|
+
} else {
|
|
2308
|
+
double minDist = std::numeric_limits<double>::infinity();
|
|
2309
|
+
for (std::uint32_t v = 0; v < localQuery.coreCount; ++v) {
|
|
2310
|
+
const Vec2 p1 = add(localQuery.coreVertices[v], scale(localDir, t));
|
|
2311
|
+
const Vec2 p2 = add(localQuery.coreVertices[(v + 1) % localQuery.coreCount], scale(localDir, t));
|
|
2312
|
+
const double d = segmentArcDistance(p1, p2, edge, header.skin + localQuery.radius);
|
|
2313
|
+
if (d < minDist) minDist = d;
|
|
2314
|
+
}
|
|
2315
|
+
dist = minDist;
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
if (dist <= kHitTolerance) {
|
|
2319
|
+
if (t == 0.0 && dist <= 0.0) {
|
|
2320
|
+
arcSurface.hit = true;
|
|
2321
|
+
arcSurface.initialOverlap = true;
|
|
2322
|
+
arcSurface.fraction = 0.0;
|
|
2323
|
+
arcSurface.feature = kNoFeature;
|
|
2324
|
+
arcSurface.point = queryStart;
|
|
2325
|
+
arcSurface.normal = {0.0, 0.0};
|
|
2326
|
+
converged = true;
|
|
2327
|
+
break;
|
|
2328
|
+
}
|
|
2329
|
+
Vec2 cp = closestPointOnEdge(currentCenter, edge);
|
|
2330
|
+
if (localQuery.coreCount > 1) {
|
|
2331
|
+
double bestVertD = std::numeric_limits<double>::infinity();
|
|
2332
|
+
for (std::uint32_t v = 0; v < localQuery.coreCount; ++v) {
|
|
2333
|
+
const Vec2 vert = add(localQuery.coreVertices[v], scale(localDir, t));
|
|
2334
|
+
const Vec2 vertCp = closestPointOnEdge(vert, edge);
|
|
2335
|
+
const double d = magnitude(subtract(vert, vertCp));
|
|
2336
|
+
if (d < bestVertD) {
|
|
2337
|
+
bestVertD = d;
|
|
2338
|
+
cp = vertCp;
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
const bool isCcw = isArcCcw(edge);
|
|
2343
|
+
const Vec2 rad = normalizeVec(subtract(cp, edge.center), {1.0, 0.0});
|
|
2344
|
+
const Vec2 normal = isCcw ? rad : scale(rad, -1.0);
|
|
2345
|
+
if (dot(localDir, normal) < 0.0) {
|
|
2346
|
+
arcSurface.hit = true;
|
|
2347
|
+
arcSurface.fraction = t / request->maxDistance;
|
|
2348
|
+
arcSurface.point = cp;
|
|
2349
|
+
arcSurface.normal = normal;
|
|
2350
|
+
arcSurface.feature = curveFeature(e);
|
|
2351
|
+
}
|
|
2352
|
+
converged = true;
|
|
2353
|
+
break;
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
t += dist;
|
|
2357
|
+
if (t > request->maxDistance) {
|
|
2358
|
+
converged = true;
|
|
2359
|
+
break;
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
if (!converged) {
|
|
2364
|
+
return static_cast<std::int32_t>(QueryStatus2D::NumericalResolution);
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
if (arcSurface.hit) {
|
|
2368
|
+
if (arcSurface.initialOverlap) {
|
|
2369
|
+
bestSurface = arcSurface;
|
|
2370
|
+
break;
|
|
2371
|
+
}
|
|
2372
|
+
if (arcSurface.fraction < bestSurface.fraction) {
|
|
2373
|
+
bestSurface = arcSurface;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
if (bestSurface.hit) {
|
|
2379
|
+
if (contourOrigin.x != 0.0 || contourOrigin.y != 0.0 || contourAngle != 0.0) {
|
|
2380
|
+
bestSurface.point = add(contourOrigin, rotate(bestSurface.point, contourAngle));
|
|
2381
|
+
bestSurface.normal = rotate(bestSurface.normal, contourAngle);
|
|
2382
|
+
}
|
|
2383
|
+
context->candidates[candidateCount++] = castRecord(
|
|
2384
|
+
bodies[index].id, bestSurface, request->maxDistance);
|
|
2385
|
+
}
|
|
2386
|
+
} else if (isChainOrSegment(bodies[index].shape)) {
|
|
2387
|
+
std::array<QueryEdge2D, kMaxPolygonVertices> edges;
|
|
2388
|
+
const std::uint32_t edgeCount = getChainOrSegmentEdges(
|
|
2389
|
+
bodies[index], geometries, geometryCount, edges);
|
|
2390
|
+
SurfaceResult bestSurface;
|
|
2391
|
+
bestSurface.fraction = std::numeric_limits<double>::infinity();
|
|
2392
|
+
const Vec2 queryStart{request->x, request->y};
|
|
2393
|
+
for (std::uint32_t e = 0; e < edgeCount; ++e) {
|
|
2394
|
+
PreparedConvex2D target{};
|
|
2395
|
+
target.coreVertices[0] = edges[e].p1;
|
|
2396
|
+
target.coreVertices[1] = edges[e].p2;
|
|
2397
|
+
target.coreCount = 2;
|
|
2398
|
+
target.radius = edges[e].radius;
|
|
2399
|
+
target.sourceShape = ShapeType::Capsule;
|
|
2400
|
+
if (disjoint(sweptBounds(target), queryBounds)) continue;
|
|
2401
|
+
RoundedHull hull;
|
|
2402
|
+
BoundaryResult boundary;
|
|
2403
|
+
status = makeHull(target, query, hull, boundary);
|
|
2404
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2405
|
+
SurfaceResult surface = castRoundedHull(
|
|
2406
|
+
target, query, hull, boundary, direction, translation);
|
|
2407
|
+
if (surface.status != QueryStatus2D::Success) {
|
|
2408
|
+
return static_cast<std::int32_t>(surface.status);
|
|
2409
|
+
}
|
|
2410
|
+
if (surface.hit) {
|
|
2411
|
+
const Vec2 queryCenterAtHit = add(queryStart, scale(translation, surface.fraction));
|
|
2412
|
+
const double freeSideDist = dot(subtract(queryCenterAtHit, edges[e].p1), edges[e].normal);
|
|
2413
|
+
if (freeSideDist < -edges[e].radius - 1e-4) continue;
|
|
2414
|
+
if (surface.fraction < bestSurface.fraction) {
|
|
2415
|
+
surface.feature = edges[e].featureId;
|
|
2416
|
+
surface.normal = edges[e].normal;
|
|
2417
|
+
bestSurface = surface;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
if (bestSurface.hit) {
|
|
2422
|
+
context->candidates[candidateCount++] = castRecord(
|
|
2423
|
+
bodies[index].id, bestSurface, request->maxDistance);
|
|
2424
|
+
}
|
|
2425
|
+
} else {
|
|
2426
|
+
PreparedConvex2D target;
|
|
2427
|
+
status = prepareBodyForQuery(bodies[index], geometries, geometryCount, target);
|
|
2428
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2429
|
+
if (disjoint(sweptBounds(target), queryBounds)) continue;
|
|
2430
|
+
RoundedHull hull;
|
|
2431
|
+
BoundaryResult boundary;
|
|
2432
|
+
status = makeHull(target, query, hull, boundary);
|
|
2433
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2434
|
+
const SurfaceResult surface = castRoundedHull(
|
|
2435
|
+
target, query, hull, boundary, direction, translation);
|
|
2436
|
+
if (surface.status != QueryStatus2D::Success) {
|
|
2437
|
+
return static_cast<std::int32_t>(surface.status);
|
|
2438
|
+
}
|
|
2439
|
+
if (surface.hit) {
|
|
2440
|
+
context->candidates[candidateCount++] = castRecord(
|
|
2441
|
+
bodies[index].id, surface, request->maxDistance);
|
|
2442
|
+
}
|
|
1783
2443
|
}
|
|
1784
2444
|
}
|
|
1785
2445
|
std::sort(context->candidates, context->candidates + candidateCount, castLess);
|
|
@@ -1791,6 +2451,123 @@ std::int32_t shapeCastQuery(
|
|
|
1791
2451
|
return static_cast<std::int32_t>(QueryStatus2D::Success);
|
|
1792
2452
|
}
|
|
1793
2453
|
|
|
2454
|
+
|
|
2455
|
+
std::int32_t overlapContactsQuery(
|
|
2456
|
+
QueryContext2D* context,
|
|
2457
|
+
const Body* bodies,
|
|
2458
|
+
std::uint32_t bodyCount,
|
|
2459
|
+
const PolygonGeometry* geometries,
|
|
2460
|
+
std::uint32_t geometryCount,
|
|
2461
|
+
const OverlapQuery2D* request,
|
|
2462
|
+
const QueryFilter2D* filter,
|
|
2463
|
+
const std::uint32_t* excludedIds,
|
|
2464
|
+
OverlapContactHit2D* outputs,
|
|
2465
|
+
std::uint32_t outputCapacity,
|
|
2466
|
+
std::uint32_t* outputCount) {
|
|
2467
|
+
if (!validSpan({request, sizeof(OverlapQuery2D), alignof(OverlapQuery2D)})) {
|
|
2468
|
+
return static_cast<std::int32_t>(QueryStatus2D::InvalidArguments);
|
|
2469
|
+
}
|
|
2470
|
+
QueryStatus2D status = validateCommon(context, bodies, bodyCount, geometries,
|
|
2471
|
+
geometryCount, request, filter, excludedIds, outputs, outputCapacity,
|
|
2472
|
+
outputCount, request->maxResults);
|
|
2473
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2474
|
+
if (!validRequestTail(*request)) {
|
|
2475
|
+
return static_cast<std::int32_t>(QueryStatus2D::InvalidRequest);
|
|
2476
|
+
}
|
|
2477
|
+
PreparedConvex2D query;
|
|
2478
|
+
status = prepareQueryShape(
|
|
2479
|
+
request->shape, request->x, request->y, request->angle, query);
|
|
2480
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2481
|
+
status = validateEligibleBodies(
|
|
2482
|
+
context, bodies, bodyCount, geometries, geometryCount, *filter, excludedIds);
|
|
2483
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2484
|
+
if (request->maxResults == 0) {
|
|
2485
|
+
*outputCount = 0;
|
|
2486
|
+
return static_cast<std::int32_t>(QueryStatus2D::Success);
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2489
|
+
Body queryBody{};
|
|
2490
|
+
queryBody.id = 0;
|
|
2491
|
+
queryBody.type = BodyType::Dynamic;
|
|
2492
|
+
queryBody.x = request->x;
|
|
2493
|
+
queryBody.y = request->y;
|
|
2494
|
+
queryBody.angle = request->angle;
|
|
2495
|
+
queryBody.shape = request->shape.shape;
|
|
2496
|
+
queryBody.halfX = request->shape.halfX;
|
|
2497
|
+
queryBody.halfY = request->shape.halfY;
|
|
2498
|
+
queryBody.radius = request->shape.radius;
|
|
2499
|
+
queryBody.mass = 1.0;
|
|
2500
|
+
queryBody.inertia = 1.0;
|
|
2501
|
+
queryBody.friction = 0.0;
|
|
2502
|
+
queryBody.restitution = 0.0;
|
|
2503
|
+
queryBody.layer = 0xffffffffu;
|
|
2504
|
+
queryBody.mask = 0xffffffffu;
|
|
2505
|
+
|
|
2506
|
+
if (queryBody.shape == ShapeType::Polygon) {
|
|
2507
|
+
if (geometries != nullptr && geometryCount > 0) {
|
|
2508
|
+
std::memcpy(context->queryGeometries, geometries, geometryCount * sizeof(PolygonGeometry));
|
|
2509
|
+
}
|
|
2510
|
+
PolygonGeometry& queryGeom = context->queryGeometries[geometryCount];
|
|
2511
|
+
queryGeom = {};
|
|
2512
|
+
queryGeom.vertexCount = request->shape.vertexCount;
|
|
2513
|
+
for (std::uint32_t v = 0; v < request->shape.vertexCount; ++v) {
|
|
2514
|
+
queryGeom.vertices[v] = request->shape.vertices[v];
|
|
2515
|
+
}
|
|
2516
|
+
queryBody.reserved = geometryCount;
|
|
2517
|
+
setPolygonGeometry(context->queryGeometries, geometryCount + 1);
|
|
2518
|
+
} else {
|
|
2519
|
+
if (geometries != nullptr && geometryCount > 0) {
|
|
2520
|
+
setPolygonGeometry(geometries, geometryCount);
|
|
2521
|
+
} else {
|
|
2522
|
+
setPolygonGeometry(nullptr, 0);
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
if (context != nullptr && context->contourEdges != nullptr) {
|
|
2526
|
+
setContourGeometry(nullptr, 0, context->contourEdges, context->contourEdgeCount);
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
std::uint32_t candidateCount = 0;
|
|
2530
|
+
for (std::uint32_t index = 0; index < bodyCount; ++index) {
|
|
2531
|
+
if (!eligible(bodies[index], *filter, excludedIds)) continue;
|
|
2532
|
+
Manifold manifold{};
|
|
2533
|
+
const std::int32_t colStatus = collideChecked(queryBody, bodies[index], manifold);
|
|
2534
|
+
if (colStatus != kStepOk || !manifold.hit || manifold.pointCount == 0) continue;
|
|
2535
|
+
|
|
2536
|
+
OverlapContactHit2D& hit = context->contactCandidates[candidateCount++];
|
|
2537
|
+
hit = {};
|
|
2538
|
+
hit.bodyId = bodies[index].id;
|
|
2539
|
+
hit.pointCount = std::min(manifold.pointCount, 2u);
|
|
2540
|
+
hit.normalX = manifold.normal.x;
|
|
2541
|
+
hit.normalY = manifold.normal.y;
|
|
2542
|
+
hit.depth = manifold.penetration;
|
|
2543
|
+
for (std::uint32_t p = 0; p < hit.pointCount; ++p) {
|
|
2544
|
+
hit.points[p].x = manifold.points[p].position.x;
|
|
2545
|
+
hit.points[p].y = manifold.points[p].position.y;
|
|
2546
|
+
hit.points[p].featureId = manifold.points[p].featureId;
|
|
2547
|
+
hit.points[p].reserved = 0;
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
setPolygonGeometry(nullptr, 0);
|
|
2551
|
+
setContourGeometry(nullptr, 0, nullptr, 0);
|
|
2552
|
+
|
|
2553
|
+
std::sort(context->contactCandidates, context->contactCandidates + candidateCount,
|
|
2554
|
+
[](const OverlapContactHit2D& first, const OverlapContactHit2D& second) {
|
|
2555
|
+
return first.bodyId < second.bodyId;
|
|
2556
|
+
});
|
|
2557
|
+
|
|
2558
|
+
const std::uint32_t resultCount = std::min({
|
|
2559
|
+
candidateCount,
|
|
2560
|
+
outputCapacity,
|
|
2561
|
+
request->maxResults
|
|
2562
|
+
});
|
|
2563
|
+
|
|
2564
|
+
for (std::uint32_t i = 0; i < resultCount; ++i) {
|
|
2565
|
+
outputs[i] = context->contactCandidates[i];
|
|
2566
|
+
}
|
|
2567
|
+
*outputCount = resultCount;
|
|
2568
|
+
return static_cast<std::int32_t>(QueryStatus2D::Success);
|
|
2569
|
+
}
|
|
2570
|
+
|
|
1794
2571
|
std::int32_t closestPointsQuery(
|
|
1795
2572
|
QueryContext2D* context,
|
|
1796
2573
|
const Body* bodies,
|
|
@@ -1820,7 +2597,7 @@ std::int32_t closestPointsQuery(
|
|
|
1820
2597
|
return static_cast<std::int32_t>(QueryStatus2D::NumericalResolution);
|
|
1821
2598
|
}
|
|
1822
2599
|
status = validateEligibleBodies(
|
|
1823
|
-
bodies, bodyCount, geometries, geometryCount, *filter, excludedIds);
|
|
2600
|
+
context, bodies, bodyCount, geometries, geometryCount, *filter, excludedIds);
|
|
1824
2601
|
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
1825
2602
|
if (request->maxResults == 0) {
|
|
1826
2603
|
*outputCount = 0;
|
|
@@ -1833,32 +2610,193 @@ std::int32_t closestPointsQuery(
|
|
|
1833
2610
|
std::uint32_t candidateCount = 0;
|
|
1834
2611
|
for (std::uint32_t index = 0; index < bodyCount; index += 1) {
|
|
1835
2612
|
if (!eligible(bodies[index], *filter, excludedIds)) continue;
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
2613
|
+
if (bodies[index].shape == ShapeType::Contour) {
|
|
2614
|
+
ContourHeader2D header{};
|
|
2615
|
+
const ContourEdge2D* edges = nullptr;
|
|
2616
|
+
if (!getContourBodyData(context, bodies[index], geometries, geometryCount, header, edges)) {
|
|
2617
|
+
continue;
|
|
2618
|
+
}
|
|
2619
|
+
const Vec2 contourOrigin{bodies[index].x, bodies[index].y};
|
|
2620
|
+
const double contourAngle = bodies[index].angle;
|
|
2621
|
+
const Vec2 worldQueryPoint{request->x, request->y};
|
|
2622
|
+
const Vec2 queryPoint = (contourOrigin.x == 0.0 && contourOrigin.y == 0.0 && contourAngle == 0.0)
|
|
2623
|
+
? worldQueryPoint
|
|
2624
|
+
: inverseRotate(subtract(worldQueryPoint, contourOrigin), contourAngle);
|
|
2625
|
+
PreparedConvex2D localQuery = query;
|
|
2626
|
+
localQuery.coreVertices[0] = queryPoint;
|
|
2627
|
+
|
|
2628
|
+
const std::uint32_t totalEdges = header.reserved > 0 ? header.reserved : header.edgeCount;
|
|
2629
|
+
if (header.fill == 1 && windingNumber(queryPoint, edges, totalEdges) != 0) {
|
|
2630
|
+
CastHit2D candidate{};
|
|
2631
|
+
candidate.bodyId = bodies[index].id;
|
|
2632
|
+
candidate.kind = static_cast<CastHitKind2D>(ClosestPointHitKind2D::Inside);
|
|
2633
|
+
candidate.featureId = kNoFeature;
|
|
2634
|
+
candidate.distance = 0.0;
|
|
2635
|
+
candidate.pointX = cleanZero(request->x);
|
|
2636
|
+
candidate.pointY = cleanZero(request->y);
|
|
2637
|
+
context->candidates[candidateCount++] = candidate;
|
|
2638
|
+
continue;
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
CastHit2D bestCandidate{};
|
|
2642
|
+
bestCandidate.distance = std::numeric_limits<double>::infinity();
|
|
2643
|
+
bool found = false;
|
|
2644
|
+
|
|
2645
|
+
for (std::uint32_t e = 0; e < totalEdges; ++e) {
|
|
2646
|
+
const auto& edge = edges[e];
|
|
2647
|
+
if (edge.kind == 2) continue; // ghost
|
|
2648
|
+
if (edge.kind == 0) { // Line
|
|
2649
|
+
PreparedConvex2D target{};
|
|
2650
|
+
target.coreVertices[0] = edge.from;
|
|
2651
|
+
target.coreVertices[1] = edge.to;
|
|
2652
|
+
target.coreCount = 2;
|
|
2653
|
+
target.radius = header.skin;
|
|
2654
|
+
target.sourceShape = ShapeType::Capsule;
|
|
2655
|
+
RoundedHull hull;
|
|
2656
|
+
BoundaryResult boundary;
|
|
2657
|
+
status = makeHull(target, localQuery, hull, boundary);
|
|
2658
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2659
|
+
CastHit2D candidate{};
|
|
2660
|
+
candidate.bodyId = bodies[index].id;
|
|
2661
|
+
if (boundary.classification == BoundaryResult::Class::Overlap) {
|
|
2662
|
+
candidate.kind = static_cast<CastHitKind2D>(ClosestPointHitKind2D::Inside);
|
|
2663
|
+
candidate.featureId = kNoFeature;
|
|
2664
|
+
candidate.distance = 0.0;
|
|
2665
|
+
candidate.pointX = cleanZero(queryPoint.x);
|
|
2666
|
+
candidate.pointY = cleanZero(queryPoint.y);
|
|
2667
|
+
} else {
|
|
2668
|
+
const SurfaceResult surface = surfaceFromBoundary(target, localQuery, boundary);
|
|
2669
|
+
if (surface.status != QueryStatus2D::Success) {
|
|
2670
|
+
return static_cast<std::int32_t>(surface.status);
|
|
2671
|
+
}
|
|
2672
|
+
candidate.kind = static_cast<CastHitKind2D>(ClosestPointHitKind2D::SurfacePoint);
|
|
2673
|
+
candidate.featureId = edgeFeature(e);
|
|
2674
|
+
candidate.distance = cleanZero(boundary.distance);
|
|
2675
|
+
candidate.pointX = cleanZero(surface.point.x);
|
|
2676
|
+
candidate.pointY = cleanZero(surface.point.y);
|
|
2677
|
+
}
|
|
2678
|
+
if (!found || candidate.distance < bestCandidate.distance) {
|
|
2679
|
+
bestCandidate = candidate;
|
|
2680
|
+
found = true;
|
|
2681
|
+
}
|
|
2682
|
+
} else if (edge.kind == 1) { // Arc
|
|
2683
|
+
const Vec2 cp = closestPointOnEdge(queryPoint, edge);
|
|
2684
|
+
const Vec2 diff = subtract(queryPoint, cp);
|
|
2685
|
+
const double len = magnitude(diff);
|
|
2686
|
+
const double dist = len - header.skin;
|
|
2687
|
+
CastHit2D candidate{};
|
|
2688
|
+
candidate.bodyId = bodies[index].id;
|
|
2689
|
+
if (dist < 0.0) {
|
|
2690
|
+
candidate.kind = static_cast<CastHitKind2D>(ClosestPointHitKind2D::Inside);
|
|
2691
|
+
candidate.featureId = kNoFeature;
|
|
2692
|
+
candidate.distance = 0.0;
|
|
2693
|
+
candidate.pointX = cleanZero(queryPoint.x);
|
|
2694
|
+
candidate.pointY = cleanZero(queryPoint.y);
|
|
2695
|
+
} else {
|
|
2696
|
+
Vec2 pt = cp;
|
|
2697
|
+
if (header.skin > 0.0 && len > 1e-12) {
|
|
2698
|
+
pt = add(cp, scale(diff, header.skin / len));
|
|
2699
|
+
}
|
|
2700
|
+
candidate.kind = static_cast<CastHitKind2D>(ClosestPointHitKind2D::SurfacePoint);
|
|
2701
|
+
candidate.featureId = curveFeature(e);
|
|
2702
|
+
candidate.distance = cleanZero(dist);
|
|
2703
|
+
candidate.pointX = cleanZero(pt.x);
|
|
2704
|
+
candidate.pointY = cleanZero(pt.y);
|
|
2705
|
+
}
|
|
2706
|
+
if (!found || candidate.distance < bestCandidate.distance) {
|
|
2707
|
+
bestCandidate = candidate;
|
|
2708
|
+
found = true;
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
if (found) {
|
|
2713
|
+
if (contourOrigin.x != 0.0 || contourOrigin.y != 0.0 || contourAngle != 0.0) {
|
|
2714
|
+
const Vec2 localPt{bestCandidate.pointX, bestCandidate.pointY};
|
|
2715
|
+
const Vec2 worldPt = add(contourOrigin, rotate(localPt, contourAngle));
|
|
2716
|
+
bestCandidate.pointX = cleanZero(worldPt.x);
|
|
2717
|
+
bestCandidate.pointY = cleanZero(worldPt.y);
|
|
2718
|
+
if (bestCandidate.normalX != 0.0 || bestCandidate.normalY != 0.0) {
|
|
2719
|
+
const Vec2 localNorm{bestCandidate.normalX, bestCandidate.normalY};
|
|
2720
|
+
const Vec2 worldNorm = rotate(localNorm, contourAngle);
|
|
2721
|
+
bestCandidate.normalX = cleanZero(worldNorm.x);
|
|
2722
|
+
bestCandidate.normalY = cleanZero(worldNorm.y);
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
context->candidates[candidateCount++] = bestCandidate;
|
|
2726
|
+
}
|
|
2727
|
+
} else if (isChainOrSegment(bodies[index].shape)) {
|
|
2728
|
+
std::array<QueryEdge2D, kMaxPolygonVertices> edges;
|
|
2729
|
+
const std::uint32_t edgeCount = getChainOrSegmentEdges(
|
|
2730
|
+
bodies[index], geometries, geometryCount, edges);
|
|
2731
|
+
CastHit2D bestCandidate{};
|
|
2732
|
+
bestCandidate.distance = std::numeric_limits<double>::infinity();
|
|
2733
|
+
bool found = false;
|
|
2734
|
+
for (std::uint32_t e = 0; e < edgeCount; ++e) {
|
|
2735
|
+
PreparedConvex2D target{};
|
|
2736
|
+
target.coreVertices[0] = edges[e].p1;
|
|
2737
|
+
target.coreVertices[1] = edges[e].p2;
|
|
2738
|
+
target.coreCount = 2;
|
|
2739
|
+
target.radius = edges[e].radius;
|
|
2740
|
+
target.sourceShape = ShapeType::Capsule;
|
|
2741
|
+
RoundedHull hull;
|
|
2742
|
+
BoundaryResult boundary;
|
|
2743
|
+
status = makeHull(target, query, hull, boundary);
|
|
2744
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2745
|
+
CastHit2D candidate{};
|
|
2746
|
+
candidate.bodyId = bodies[index].id;
|
|
2747
|
+
if (boundary.classification == BoundaryResult::Class::Overlap) {
|
|
2748
|
+
candidate.kind = static_cast<CastHitKind2D>(ClosestPointHitKind2D::Inside);
|
|
2749
|
+
candidate.featureId = kNoFeature;
|
|
2750
|
+
candidate.distance = 0.0;
|
|
2751
|
+
candidate.pointX = cleanZero(request->x);
|
|
2752
|
+
candidate.pointY = cleanZero(request->y);
|
|
2753
|
+
} else {
|
|
2754
|
+
const SurfaceResult surface = surfaceFromBoundary(target, query, boundary);
|
|
2755
|
+
if (surface.status != QueryStatus2D::Success) {
|
|
2756
|
+
return static_cast<std::int32_t>(surface.status);
|
|
2757
|
+
}
|
|
2758
|
+
candidate.kind = static_cast<CastHitKind2D>(ClosestPointHitKind2D::SurfacePoint);
|
|
2759
|
+
candidate.featureId = edges[e].featureId;
|
|
2760
|
+
candidate.distance = cleanZero(boundary.distance);
|
|
2761
|
+
candidate.pointX = cleanZero(surface.point.x);
|
|
2762
|
+
candidate.pointY = cleanZero(surface.point.y);
|
|
2763
|
+
}
|
|
2764
|
+
if (!found || candidate.distance < bestCandidate.distance) {
|
|
2765
|
+
bestCandidate = candidate;
|
|
2766
|
+
found = true;
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
if (found) {
|
|
2770
|
+
context->candidates[candidateCount++] = bestCandidate;
|
|
2771
|
+
}
|
|
1851
2772
|
} else {
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
2773
|
+
PreparedConvex2D target;
|
|
2774
|
+
status = prepareBodyForQuery(bodies[index], geometries, geometryCount, target);
|
|
2775
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2776
|
+
RoundedHull hull;
|
|
2777
|
+
BoundaryResult boundary;
|
|
2778
|
+
status = makeHull(target, query, hull, boundary);
|
|
2779
|
+
if (status != QueryStatus2D::Success) return static_cast<std::int32_t>(status);
|
|
2780
|
+
CastHit2D& candidate = context->candidates[candidateCount++];
|
|
2781
|
+
candidate = {};
|
|
2782
|
+
candidate.bodyId = bodies[index].id;
|
|
2783
|
+
if (boundary.classification == BoundaryResult::Class::Overlap) {
|
|
2784
|
+
candidate.kind = static_cast<CastHitKind2D>(ClosestPointHitKind2D::Inside);
|
|
2785
|
+
candidate.featureId = kNoFeature;
|
|
2786
|
+
candidate.pointX = cleanZero(request->x);
|
|
2787
|
+
candidate.pointY = cleanZero(request->y);
|
|
2788
|
+
} else {
|
|
2789
|
+
const SurfaceResult surface = surfaceFromBoundary(target, query, boundary);
|
|
2790
|
+
if (surface.status != QueryStatus2D::Success) {
|
|
2791
|
+
return static_cast<std::int32_t>(surface.status);
|
|
2792
|
+
}
|
|
2793
|
+
candidate.kind = static_cast<CastHitKind2D>(
|
|
2794
|
+
ClosestPointHitKind2D::SurfacePoint);
|
|
2795
|
+
candidate.featureId = surface.feature;
|
|
2796
|
+
candidate.distance = cleanZero(boundary.distance);
|
|
2797
|
+
candidate.pointX = cleanZero(surface.point.x);
|
|
2798
|
+
candidate.pointY = cleanZero(surface.point.y);
|
|
1855
2799
|
}
|
|
1856
|
-
candidate.kind = static_cast<CastHitKind2D>(
|
|
1857
|
-
ClosestPointHitKind2D::SurfacePoint);
|
|
1858
|
-
candidate.featureId = surface.feature;
|
|
1859
|
-
candidate.distance = cleanZero(boundary.distance);
|
|
1860
|
-
candidate.pointX = cleanZero(surface.point.x);
|
|
1861
|
-
candidate.pointY = cleanZero(surface.point.y);
|
|
1862
2800
|
}
|
|
1863
2801
|
}
|
|
1864
2802
|
std::sort(context->candidates, context->candidates + candidateCount, castLess);
|
|
@@ -2206,8 +3144,25 @@ PlatformerSweepSlideResult2D platformerSweepAndSlide(
|
|
|
2206
3144
|
return result;
|
|
2207
3145
|
}
|
|
2208
3146
|
|
|
3147
|
+
void setQueryContourEdges(
|
|
3148
|
+
QueryContext2D* context,
|
|
3149
|
+
const ContourEdge2D* edges,
|
|
3150
|
+
std::uint32_t count) {
|
|
3151
|
+
if (context != nullptr) {
|
|
3152
|
+
context->contourEdges = edges;
|
|
3153
|
+
context->contourEdgeCount = count;
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
|
|
2209
3157
|
} // namespace rundot::kinetix::physics2d
|
|
2210
3158
|
|
|
3159
|
+
extern "C" void rundot_physics2d_query_set_contour_edges(
|
|
3160
|
+
rundot::kinetix::physics2d::QueryContext2D* context,
|
|
3161
|
+
const rundot::kinetix::physics2d::ContourEdge2D* edges,
|
|
3162
|
+
std::uint32_t count) {
|
|
3163
|
+
rundot::kinetix::physics2d::setQueryContourEdges(context, edges, count);
|
|
3164
|
+
}
|
|
3165
|
+
|
|
2211
3166
|
extern "C" std::uint32_t rundot_physics2d_query_abi_version() {
|
|
2212
3167
|
return rundot::kinetix::physics2d::kQueryAbiVersion;
|
|
2213
3168
|
}
|
|
@@ -2290,6 +3245,27 @@ extern "C" std::int32_t rundot_physics2d_overlap(
|
|
|
2290
3245
|
outputCapacity, outputCount);
|
|
2291
3246
|
}
|
|
2292
3247
|
|
|
3248
|
+
extern "C" std::uint32_t rundot_physics2d_overlap_contact_hit_size() {
|
|
3249
|
+
return sizeof(rundot::kinetix::physics2d::OverlapContactHit2D);
|
|
3250
|
+
}
|
|
3251
|
+
|
|
3252
|
+
extern "C" std::int32_t rundot_physics2d_overlap_contacts(
|
|
3253
|
+
rundot::kinetix::physics2d::QueryContext2D* context,
|
|
3254
|
+
const rundot::kinetix::physics2d::Body* bodies,
|
|
3255
|
+
std::uint32_t bodyCount,
|
|
3256
|
+
const rundot::kinetix::physics2d::PolygonGeometry* geometries,
|
|
3257
|
+
std::uint32_t geometryCount,
|
|
3258
|
+
const rundot::kinetix::physics2d::OverlapQuery2D* request,
|
|
3259
|
+
const rundot::kinetix::physics2d::QueryFilter2D* filter,
|
|
3260
|
+
const std::uint32_t* excludedIds,
|
|
3261
|
+
rundot::kinetix::physics2d::OverlapContactHit2D* outputs,
|
|
3262
|
+
std::uint32_t outputCapacity,
|
|
3263
|
+
std::uint32_t* outputCount) {
|
|
3264
|
+
return rundot::kinetix::physics2d::overlapContactsQuery(context, bodies, bodyCount,
|
|
3265
|
+
geometries, geometryCount, request, filter, excludedIds, outputs,
|
|
3266
|
+
outputCapacity, outputCount);
|
|
3267
|
+
}
|
|
3268
|
+
|
|
2293
3269
|
extern "C" std::int32_t rundot_physics2d_shape_cast(
|
|
2294
3270
|
rundot::kinetix::physics2d::QueryContext2D* context,
|
|
2295
3271
|
const rundot::kinetix::physics2d::Body* bodies,
|