| | | 1 | | //======================================================================= |
| | | 2 | | // Physics3DQueryRequests.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using FixedMathSharp; |
| | | 9 | | using Gravitas.Colliders; |
| | | 10 | | using Gravitas.Support; |
| | | 11 | | |
| | | 12 | | namespace Gravitas.Queries; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Describes one 3D swept-sphere query in a batched query call. |
| | | 16 | | /// </summary> |
| | | 17 | | public readonly struct PhysicsSweepSphere3DRequest |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Creates a 3D swept-sphere request. |
| | | 21 | | /// </summary> |
| | | 22 | | public PhysicsSweepSphere3DRequest( |
| | | 23 | | Vector3d start, |
| | | 24 | | Vector3d end, |
| | | 25 | | Fixed64 radius, |
| | | 26 | | PhysicsLayerMask layerMask, |
| | | 27 | | LSCollider? excludedCollider = null) |
| | | 28 | | { |
| | | 29 | | Start = start; |
| | | 30 | | End = end; |
| | | 31 | | Radius = radius; |
| | | 32 | | LayerMask = layerMask; |
| | | 33 | | ExcludedCollider = excludedCollider; |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Creates a 3D swept-sphere request against all physics layers. |
| | | 38 | | /// </summary> |
| | | 39 | | public PhysicsSweepSphere3DRequest(Vector3d start, Vector3d end, Fixed64 radius) |
| | | 40 | | : this(start, end, radius, PhysicsLayerMask.All) |
| | | 41 | | { |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets the sphere center's world-space start. |
| | | 46 | | /// </summary> |
| | | 47 | | public Vector3d Start { get; } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets the sphere center's world-space end. |
| | | 51 | | /// </summary> |
| | | 52 | | public Vector3d End { get; } |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Gets the swept sphere radius. |
| | | 56 | | /// </summary> |
| | | 57 | | public Fixed64 Radius { get; } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Gets the included physics layers. |
| | | 61 | | /// </summary> |
| | | 62 | | public PhysicsLayerMask LayerMask { get; } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Gets the collider omitted from candidate results, if any. |
| | | 66 | | /// </summary> |
| | | 67 | | public LSCollider? ExcludedCollider { get; } |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Describes one registered 3D capsule-source sweep in a batched query call. |
| | | 72 | | /// </summary> |
| | | 73 | | public readonly struct PhysicsSweepCapsule3DRequest |
| | | 74 | | { |
| | | 75 | | /// <summary> |
| | | 76 | | /// Creates a registered capsule-source sweep request. |
| | | 77 | | /// </summary> |
| | | 78 | | public PhysicsSweepCapsule3DRequest( |
| | | 79 | | LSCapsuleCollider source, |
| | | 80 | | Vector3d displacement, |
| | | 81 | | PhysicsLayerMask layerMask, |
| | | 82 | | LSCollider? excludedCollider = null, |
| | | 83 | | bool includeTriggers = true) |
| | | 84 | | { |
| | | 85 | | Source = source; |
| | | 86 | | Displacement = displacement; |
| | | 87 | | LayerMask = layerMask; |
| | | 88 | | ExcludedCollider = excludedCollider; |
| | | 89 | | IncludeTriggers = includeTriggers; |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | /// <summary> |
| | | 93 | | /// Gets the registered capsule swept from its current transform. |
| | | 94 | | /// </summary> |
| | | 95 | | public LSCapsuleCollider Source { get; } |
| | | 96 | | |
| | | 97 | | /// <summary> |
| | | 98 | | /// Gets the world-space sweep displacement. |
| | | 99 | | /// </summary> |
| | | 100 | | public Vector3d Displacement { get; } |
| | | 101 | | |
| | | 102 | | /// <summary> |
| | | 103 | | /// Gets the included physics layers. |
| | | 104 | | /// </summary> |
| | | 105 | | public PhysicsLayerMask LayerMask { get; } |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// Gets the collider omitted from candidate results, if any. |
| | | 109 | | /// </summary> |
| | | 110 | | public LSCollider? ExcludedCollider { get; } |
| | | 111 | | |
| | | 112 | | /// <summary> |
| | | 113 | | /// Gets whether trigger colliders are included. |
| | | 114 | | /// </summary> |
| | | 115 | | public bool IncludeTriggers { get; } |
| | | 116 | | } |
| | | 117 | | |
| | | 118 | | /// <summary> |
| | | 119 | | /// Describes one registered 3D cuboid-source sweep in a batched query call. |
| | | 120 | | /// </summary> |
| | | 121 | | public readonly struct PhysicsSweepCuboid3DRequest |
| | | 122 | | { |
| | | 123 | | /// <summary> |
| | | 124 | | /// Creates a registered cuboid-source sweep request. |
| | | 125 | | /// </summary> |
| | | 126 | | public PhysicsSweepCuboid3DRequest( |
| | | 127 | | LSCuboidCollider source, |
| | | 128 | | Vector3d displacement, |
| | | 129 | | PhysicsLayerMask layerMask, |
| | | 130 | | LSCollider? excludedCollider = null, |
| | | 131 | | bool includeTriggers = true) |
| | | 132 | | { |
| | | 133 | | Source = source; |
| | | 134 | | Displacement = displacement; |
| | | 135 | | LayerMask = layerMask; |
| | | 136 | | ExcludedCollider = excludedCollider; |
| | | 137 | | IncludeTriggers = includeTriggers; |
| | | 138 | | } |
| | | 139 | | |
| | | 140 | | /// <summary> |
| | | 141 | | /// Gets the registered cuboid swept from its current transform. |
| | | 142 | | /// </summary> |
| | | 143 | | public LSCuboidCollider Source { get; } |
| | | 144 | | |
| | | 145 | | /// <summary> |
| | | 146 | | /// Gets the world-space sweep displacement. |
| | | 147 | | /// </summary> |
| | | 148 | | public Vector3d Displacement { get; } |
| | | 149 | | |
| | | 150 | | /// <summary> |
| | | 151 | | /// Gets the included physics layers. |
| | | 152 | | /// </summary> |
| | | 153 | | public PhysicsLayerMask LayerMask { get; } |
| | | 154 | | |
| | | 155 | | /// <summary> |
| | | 156 | | /// Gets the collider omitted from candidate results, if any. |
| | | 157 | | /// </summary> |
| | | 158 | | public LSCollider? ExcludedCollider { get; } |
| | | 159 | | |
| | | 160 | | /// <summary> |
| | | 161 | | /// Gets whether trigger colliders are included. |
| | | 162 | | /// </summary> |
| | | 163 | | public bool IncludeTriggers { get; } |
| | | 164 | | } |
| | | 165 | | |
| | | 166 | | /// <summary> |
| | | 167 | | /// Describes one registered 3D cylinder-source sweep in a batched query call. |
| | | 168 | | /// </summary> |
| | | 169 | | public readonly struct PhysicsSweepCylinder3DRequest |
| | | 170 | | { |
| | | 171 | | /// <summary> |
| | | 172 | | /// Creates a registered cylinder-source sweep request. |
| | | 173 | | /// </summary> |
| | | 174 | | public PhysicsSweepCylinder3DRequest( |
| | | 175 | | LSCylinderCollider source, |
| | | 176 | | Vector3d displacement, |
| | | 177 | | PhysicsLayerMask layerMask, |
| | | 178 | | LSCollider? excludedCollider = null, |
| | | 179 | | bool includeTriggers = true) |
| | | 180 | | { |
| | | 181 | | Source = source; |
| | | 182 | | Displacement = displacement; |
| | | 183 | | LayerMask = layerMask; |
| | | 184 | | ExcludedCollider = excludedCollider; |
| | | 185 | | IncludeTriggers = includeTriggers; |
| | | 186 | | } |
| | | 187 | | |
| | | 188 | | /// <summary> |
| | | 189 | | /// Gets the registered cylinder swept from its current transform. |
| | | 190 | | /// </summary> |
| | | 191 | | public LSCylinderCollider Source { get; } |
| | | 192 | | |
| | | 193 | | /// <summary> |
| | | 194 | | /// Gets the world-space sweep displacement. |
| | | 195 | | /// </summary> |
| | | 196 | | public Vector3d Displacement { get; } |
| | | 197 | | |
| | | 198 | | /// <summary> |
| | | 199 | | /// Gets the included physics layers. |
| | | 200 | | /// </summary> |
| | | 201 | | public PhysicsLayerMask LayerMask { get; } |
| | | 202 | | |
| | | 203 | | /// <summary> |
| | | 204 | | /// Gets the collider omitted from candidate results, if any. |
| | | 205 | | /// </summary> |
| | | 206 | | public LSCollider? ExcludedCollider { get; } |
| | | 207 | | |
| | | 208 | | /// <summary> |
| | | 209 | | /// Gets whether trigger colliders are included. |
| | | 210 | | /// </summary> |
| | | 211 | | public bool IncludeTriggers { get; } |
| | | 212 | | } |
| | | 213 | | |
| | | 214 | | /// <summary> |
| | | 215 | | /// Describes one registered 3D cone-source sweep in a batched query call. |
| | | 216 | | /// </summary> |
| | | 217 | | public readonly struct PhysicsSweepCone3DRequest |
| | | 218 | | { |
| | | 219 | | /// <summary> |
| | | 220 | | /// Creates a registered cone-source sweep request. |
| | | 221 | | /// </summary> |
| | | 222 | | public PhysicsSweepCone3DRequest( |
| | | 223 | | LSConeCollider source, |
| | | 224 | | Vector3d displacement, |
| | | 225 | | PhysicsLayerMask layerMask, |
| | | 226 | | LSCollider? excludedCollider = null, |
| | | 227 | | bool includeTriggers = true) |
| | | 228 | | { |
| | | 229 | | Source = source; |
| | | 230 | | Displacement = displacement; |
| | | 231 | | LayerMask = layerMask; |
| | | 232 | | ExcludedCollider = excludedCollider; |
| | | 233 | | IncludeTriggers = includeTriggers; |
| | | 234 | | } |
| | | 235 | | |
| | | 236 | | /// <summary> |
| | | 237 | | /// Gets the registered cone swept from its current transform. |
| | | 238 | | /// </summary> |
| | | 239 | | public LSConeCollider Source { get; } |
| | | 240 | | |
| | | 241 | | /// <summary> |
| | | 242 | | /// Gets the world-space sweep displacement. |
| | | 243 | | /// </summary> |
| | | 244 | | public Vector3d Displacement { get; } |
| | | 245 | | |
| | | 246 | | /// <summary> |
| | | 247 | | /// Gets the included physics layers. |
| | | 248 | | /// </summary> |
| | | 249 | | public PhysicsLayerMask LayerMask { get; } |
| | | 250 | | |
| | | 251 | | /// <summary> |
| | | 252 | | /// Gets the collider omitted from candidate results, if any. |
| | | 253 | | /// </summary> |
| | | 254 | | public LSCollider? ExcludedCollider { get; } |
| | | 255 | | |
| | | 256 | | /// <summary> |
| | | 257 | | /// Gets whether trigger colliders are included. |
| | | 258 | | /// </summary> |
| | | 259 | | public bool IncludeTriggers { get; } |
| | | 260 | | } |
| | | 261 | | |
| | | 262 | | /// <summary> |
| | | 263 | | /// Describes one registered convex mesh-source sweep in a batched query call. |
| | | 264 | | /// </summary> |
| | | 265 | | public readonly struct PhysicsSweepConvexMesh3DRequest |
| | | 266 | | { |
| | | 267 | | /// <summary> |
| | | 268 | | /// Creates a registered convex-mesh-source sweep request. |
| | | 269 | | /// </summary> |
| | | 270 | | public PhysicsSweepConvexMesh3DRequest( |
| | | 271 | | LSMeshCollider source, |
| | | 272 | | Vector3d displacement, |
| | | 273 | | PhysicsLayerMask layerMask, |
| | | 274 | | LSCollider? excludedCollider = null, |
| | | 275 | | bool includeTriggers = true) |
| | | 276 | | { |
| | | 277 | | Source = source; |
| | | 278 | | Displacement = displacement; |
| | | 279 | | LayerMask = layerMask; |
| | | 280 | | ExcludedCollider = excludedCollider; |
| | | 281 | | IncludeTriggers = includeTriggers; |
| | | 282 | | } |
| | | 283 | | |
| | | 284 | | /// <summary> |
| | | 285 | | /// Gets the registered convex mesh swept from its current transform. |
| | | 286 | | /// </summary> |
| | | 287 | | public LSMeshCollider Source { get; } |
| | | 288 | | |
| | | 289 | | /// <summary> |
| | | 290 | | /// Gets the world-space sweep displacement. |
| | | 291 | | /// </summary> |
| | | 292 | | public Vector3d Displacement { get; } |
| | | 293 | | |
| | | 294 | | /// <summary> |
| | | 295 | | /// Gets the included physics layers. |
| | | 296 | | /// </summary> |
| | | 297 | | public PhysicsLayerMask LayerMask { get; } |
| | | 298 | | |
| | | 299 | | /// <summary> |
| | | 300 | | /// Gets the collider omitted from candidate results, if any. |
| | | 301 | | /// </summary> |
| | | 302 | | public LSCollider? ExcludedCollider { get; } |
| | | 303 | | |
| | | 304 | | /// <summary> |
| | | 305 | | /// Gets whether trigger colliders are included. |
| | | 306 | | /// </summary> |
| | | 307 | | public bool IncludeTriggers { get; } |
| | | 308 | | } |
| | | 309 | | |
| | | 310 | | /// <summary> |
| | | 311 | | /// Describes one registered compound-source sweep in a batched query call. |
| | | 312 | | /// </summary> |
| | | 313 | | public readonly struct PhysicsSweepCompound3DRequest |
| | | 314 | | { |
| | | 315 | | /// <summary> |
| | | 316 | | /// Creates a registered compound-source sweep request. |
| | | 317 | | /// </summary> |
| | | 318 | | public PhysicsSweepCompound3DRequest( |
| | | 319 | | LSCompoundCollider source, |
| | | 320 | | Vector3d displacement, |
| | | 321 | | PhysicsLayerMask layerMask, |
| | | 322 | | LSCollider? excludedCollider = null, |
| | | 323 | | bool includeTriggers = true) |
| | | 324 | | { |
| | | 325 | | Source = source; |
| | | 326 | | Displacement = displacement; |
| | | 327 | | LayerMask = layerMask; |
| | | 328 | | ExcludedCollider = excludedCollider; |
| | | 329 | | IncludeTriggers = includeTriggers; |
| | | 330 | | } |
| | | 331 | | |
| | | 332 | | /// <summary> |
| | | 333 | | /// Gets the registered compound collider swept from its current transform. |
| | | 334 | | /// </summary> |
| | | 335 | | public LSCompoundCollider Source { get; } |
| | | 336 | | |
| | | 337 | | /// <summary> |
| | | 338 | | /// Gets the world-space sweep displacement. |
| | | 339 | | /// </summary> |
| | | 340 | | public Vector3d Displacement { get; } |
| | | 341 | | |
| | | 342 | | /// <summary> |
| | | 343 | | /// Gets the included physics layers. |
| | | 344 | | /// </summary> |
| | | 345 | | public PhysicsLayerMask LayerMask { get; } |
| | | 346 | | |
| | | 347 | | /// <summary> |
| | | 348 | | /// Gets the collider omitted from candidate results, if any. |
| | | 349 | | /// </summary> |
| | | 350 | | public LSCollider? ExcludedCollider { get; } |
| | | 351 | | |
| | | 352 | | /// <summary> |
| | | 353 | | /// Gets whether trigger colliders are included. |
| | | 354 | | /// </summary> |
| | | 355 | | public bool IncludeTriggers { get; } |
| | | 356 | | } |
| | | 357 | | |
| | | 358 | | /// <summary> |
| | | 359 | | /// Describes one 3D X/Z circle overlap in a batched query call. |
| | | 360 | | /// </summary> |
| | | 361 | | public readonly struct PhysicsOverlapCircle3DRequest |
| | | 362 | | { |
| | | 363 | | /// <summary> |
| | | 364 | | /// Creates a 3D collider-projection overlap request with an X/Z circle and include layer mask. |
| | | 365 | | /// </summary> |
| | | 366 | | public PhysicsOverlapCircle3DRequest(Vector3d position, Fixed64 radius, PhysicsLayerMask layerMask) |
| | | 367 | | { |
| | | 368 | | Position = position; |
| | | 369 | | Radius = radius; |
| | | 370 | | LayerMask = layerMask; |
| | | 371 | | } |
| | | 372 | | |
| | | 373 | | /// <summary> |
| | | 374 | | /// Creates a 3D collider-projection overlap request against all physics layers. |
| | | 375 | | /// </summary> |
| | | 376 | | public PhysicsOverlapCircle3DRequest(Vector3d position, Fixed64 radius) |
| | | 377 | | : this(position, radius, PhysicsLayerMask.All) |
| | | 378 | | { |
| | | 379 | | } |
| | | 380 | | |
| | | 381 | | /// <summary> |
| | | 382 | | /// Gets the circle center; only its X/Z components are used. |
| | | 383 | | /// </summary> |
| | | 384 | | public Vector3d Position { get; } |
| | | 385 | | |
| | | 386 | | /// <summary> |
| | | 387 | | /// Gets the projected circle radius. |
| | | 388 | | /// </summary> |
| | | 389 | | public Fixed64 Radius { get; } |
| | | 390 | | |
| | | 391 | | /// <summary> |
| | | 392 | | /// Gets the included physics layers. |
| | | 393 | | /// </summary> |
| | | 394 | | public PhysicsLayerMask LayerMask { get; } |
| | | 395 | | } |
| | | 396 | | |
| | | 397 | | /// <summary> |
| | | 398 | | /// Describes one directional 3D X/Z projected-circle overlap in a batched query call. |
| | | 399 | | /// </summary> |
| | | 400 | | public readonly struct PhysicsOverlapCircleInDirection3DRequest |
| | | 401 | | { |
| | | 402 | | /// <summary> |
| | | 403 | | /// Creates a directional X/Z projected-circle overlap request with an include layer mask. |
| | | 404 | | /// </summary> |
| | | 405 | | public PhysicsOverlapCircleInDirection3DRequest( |
| | | 406 | | Vector3d position, |
| | | 407 | | Fixed64 radius, |
| | | 408 | | Vector3d direction, |
| | | 409 | | Fixed64 maxDistance, |
| | | 410 | | PhysicsLayerMask layerMask) |
| | | 411 | | { |
| | 7 | 412 | | Position = position; |
| | 7 | 413 | | Radius = radius; |
| | 7 | 414 | | Direction = direction; |
| | 7 | 415 | | MaxDistance = maxDistance; |
| | 7 | 416 | | LayerMask = layerMask; |
| | 7 | 417 | | } |
| | | 418 | | |
| | | 419 | | /// <summary> |
| | | 420 | | /// Creates a directional X/Z projected-circle overlap request against all physics layers. |
| | | 421 | | /// </summary> |
| | | 422 | | public PhysicsOverlapCircleInDirection3DRequest( |
| | | 423 | | Vector3d position, |
| | | 424 | | Fixed64 radius, |
| | | 425 | | Vector3d direction, |
| | | 426 | | Fixed64 maxDistance) |
| | 1 | 427 | | : this(position, radius, direction, maxDistance, PhysicsLayerMask.All) |
| | | 428 | | { |
| | 1 | 429 | | } |
| | | 430 | | |
| | | 431 | | /// <summary> |
| | | 432 | | /// Gets the circle center; only its X/Z components are used. |
| | | 433 | | /// </summary> |
| | | 434 | | public Vector3d Position { get; } |
| | | 435 | | |
| | | 436 | | /// <summary> |
| | | 437 | | /// Gets the projected circle radius. |
| | | 438 | | /// </summary> |
| | | 439 | | public Fixed64 Radius { get; } |
| | | 440 | | |
| | | 441 | | /// <summary> |
| | | 442 | | /// Gets the direction used to filter exact projected separations. |
| | | 443 | | /// </summary> |
| | | 444 | | public Vector3d Direction { get; } |
| | | 445 | | |
| | | 446 | | /// <summary> |
| | | 447 | | /// Gets the maximum admitted projected separation distance. |
| | | 448 | | /// </summary> |
| | | 449 | | public Fixed64 MaxDistance { get; } |
| | | 450 | | |
| | | 451 | | /// <summary> |
| | | 452 | | /// Gets the included physics layers. |
| | | 453 | | /// </summary> |
| | | 454 | | public PhysicsLayerMask LayerMask { get; } |
| | | 455 | | } |
| | | 456 | | |
| | | 457 | | /// <summary> |
| | | 458 | | /// Describes one directional 3D cone-volume overlap in a batched query call. |
| | | 459 | | /// </summary> |
| | | 460 | | public readonly struct PhysicsOverlapCone3DRequest |
| | | 461 | | { |
| | | 462 | | /// <summary> |
| | | 463 | | /// Creates an apex-origin 3D cone-volume overlap request with an include layer mask. |
| | | 464 | | /// </summary> |
| | | 465 | | public PhysicsOverlapCone3DRequest( |
| | | 466 | | Vector3d origin, |
| | | 467 | | Vector3d direction, |
| | | 468 | | Fixed64 length, |
| | | 469 | | Fixed64 endRadius, |
| | | 470 | | PhysicsLayerMask layerMask) |
| | | 471 | | { |
| | | 472 | | Origin = origin; |
| | | 473 | | Direction = direction; |
| | | 474 | | Length = length; |
| | | 475 | | EndRadius = endRadius; |
| | | 476 | | LayerMask = layerMask; |
| | | 477 | | } |
| | | 478 | | |
| | | 479 | | /// <summary> |
| | | 480 | | /// Creates an apex-origin 3D cone-volume overlap request against all physics layers. |
| | | 481 | | /// </summary> |
| | | 482 | | public PhysicsOverlapCone3DRequest( |
| | | 483 | | Vector3d origin, |
| | | 484 | | Vector3d direction, |
| | | 485 | | Fixed64 length, |
| | | 486 | | Fixed64 endRadius) |
| | | 487 | | : this(origin, direction, length, endRadius, PhysicsLayerMask.All) |
| | | 488 | | { |
| | | 489 | | } |
| | | 490 | | |
| | | 491 | | /// <summary> |
| | | 492 | | /// Gets the world-space cone apex. |
| | | 493 | | /// </summary> |
| | | 494 | | public Vector3d Origin { get; } |
| | | 495 | | |
| | | 496 | | /// <summary> |
| | | 497 | | /// Gets the cone axis direction. |
| | | 498 | | /// </summary> |
| | | 499 | | public Vector3d Direction { get; } |
| | | 500 | | |
| | | 501 | | /// <summary> |
| | | 502 | | /// Gets the cone length from apex to base. |
| | | 503 | | /// </summary> |
| | | 504 | | public Fixed64 Length { get; } |
| | | 505 | | |
| | | 506 | | /// <summary> |
| | | 507 | | /// Gets the cone radius at its base. |
| | | 508 | | /// </summary> |
| | | 509 | | public Fixed64 EndRadius { get; } |
| | | 510 | | |
| | | 511 | | /// <summary> |
| | | 512 | | /// Gets the included physics layers. |
| | | 513 | | /// </summary> |
| | | 514 | | public PhysicsLayerMask LayerMask { get; } |
| | | 515 | | } |