| | | 1 | | //======================================================================= |
| | | 2 | | // Physics2DQueryRequests.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 pure 2D segment raycast in a batched query call. |
| | | 16 | | /// </summary> |
| | | 17 | | public readonly struct PhysicsRaycast2DRequest |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Creates a pure 2D segment raycast request with an include layer mask. |
| | | 21 | | /// </summary> |
| | | 22 | | public PhysicsRaycast2DRequest(Vector2d start, Vector2d end, PhysicsLayerMask layerMask) |
| | | 23 | | { |
| | 6 | 24 | | Start = start; |
| | 6 | 25 | | End = end; |
| | 6 | 26 | | LayerMask = layerMask; |
| | 6 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Creates a pure 2D segment raycast request against all physics layers. |
| | | 31 | | /// </summary> |
| | | 32 | | public PhysicsRaycast2DRequest(Vector2d start, Vector2d end) |
| | 1 | 33 | | : this(start, end, PhysicsLayerMask.All) |
| | | 34 | | { |
| | 1 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets the segment start in the X/Z plane. |
| | | 39 | | /// </summary> |
| | | 40 | | public Vector2d Start { get; } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Gets the segment end in the X/Z plane. |
| | | 44 | | /// </summary> |
| | | 45 | | public Vector2d End { get; } |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Gets the included physics layers. |
| | | 49 | | /// </summary> |
| | | 50 | | public PhysicsLayerMask LayerMask { get; } |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Describes one pure 2D circle overlap in a batched query call. |
| | | 55 | | /// </summary> |
| | | 56 | | public readonly struct PhysicsOverlapCircle2DRequest |
| | | 57 | | { |
| | | 58 | | /// <summary> |
| | | 59 | | /// Creates a pure 2D circle-overlap request with an include layer mask. |
| | | 60 | | /// </summary> |
| | | 61 | | public PhysicsOverlapCircle2DRequest(Vector2d center, Fixed64 radius, PhysicsLayerMask layerMask) |
| | | 62 | | { |
| | | 63 | | Center = center; |
| | | 64 | | Radius = radius; |
| | | 65 | | LayerMask = layerMask; |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Creates a pure 2D circle-overlap request against all physics layers. |
| | | 70 | | /// </summary> |
| | | 71 | | public PhysicsOverlapCircle2DRequest(Vector2d center, Fixed64 radius) |
| | | 72 | | : this(center, radius, PhysicsLayerMask.All) |
| | | 73 | | { |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// Gets the circle center in the X/Z plane. |
| | | 78 | | /// </summary> |
| | | 79 | | public Vector2d Center { get; } |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// Gets the circle radius. |
| | | 83 | | /// </summary> |
| | | 84 | | public Fixed64 Radius { get; } |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Gets the included physics layers. |
| | | 88 | | /// </summary> |
| | | 89 | | public PhysicsLayerMask LayerMask { get; } |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | /// <summary> |
| | | 93 | | /// Describes one pure 2D axis-aligned box overlap in a batched query call. |
| | | 94 | | /// </summary> |
| | | 95 | | public readonly struct PhysicsOverlapAabb2DRequest |
| | | 96 | | { |
| | | 97 | | /// <summary> |
| | | 98 | | /// Creates a pure 2D axis-aligned box-overlap request with an include layer mask. |
| | | 99 | | /// </summary> |
| | | 100 | | public PhysicsOverlapAabb2DRequest(Vector2d center, Vector2d size, PhysicsLayerMask layerMask) |
| | | 101 | | { |
| | | 102 | | Center = center; |
| | | 103 | | Size = size; |
| | | 104 | | LayerMask = layerMask; |
| | | 105 | | } |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// Creates a pure 2D axis-aligned box-overlap request against all physics layers. |
| | | 109 | | /// </summary> |
| | | 110 | | public PhysicsOverlapAabb2DRequest(Vector2d center, Vector2d size) |
| | | 111 | | : this(center, size, PhysicsLayerMask.All) |
| | | 112 | | { |
| | | 113 | | } |
| | | 114 | | |
| | | 115 | | /// <summary> |
| | | 116 | | /// Gets the box center in the X/Z plane. |
| | | 117 | | /// </summary> |
| | | 118 | | public Vector2d Center { get; } |
| | | 119 | | |
| | | 120 | | /// <summary> |
| | | 121 | | /// Gets the full box size in the X/Z plane. |
| | | 122 | | /// </summary> |
| | | 123 | | public Vector2d Size { get; } |
| | | 124 | | |
| | | 125 | | /// <summary> |
| | | 126 | | /// Gets the included physics layers. |
| | | 127 | | /// </summary> |
| | | 128 | | public PhysicsLayerMask LayerMask { get; } |
| | | 129 | | } |
| | | 130 | | |
| | | 131 | | /// <summary> |
| | | 132 | | /// Describes one pure 2D convex polygon overlap by referencing a flat vertex buffer. |
| | | 133 | | /// </summary> |
| | | 134 | | public readonly struct PhysicsOverlapPolygon2DRequest |
| | | 135 | | { |
| | | 136 | | /// <summary> |
| | | 137 | | /// Creates a pure 2D convex-polygon overlap request with an include layer mask. |
| | | 138 | | /// </summary> |
| | | 139 | | public PhysicsOverlapPolygon2DRequest(int vertexStart, int vertexCount, PhysicsLayerMask layerMask) |
| | | 140 | | { |
| | | 141 | | VertexStart = vertexStart; |
| | | 142 | | VertexCount = vertexCount; |
| | | 143 | | LayerMask = layerMask; |
| | | 144 | | } |
| | | 145 | | |
| | | 146 | | /// <summary> |
| | | 147 | | /// Creates a pure 2D convex-polygon overlap request against all physics layers. |
| | | 148 | | /// </summary> |
| | | 149 | | public PhysicsOverlapPolygon2DRequest(int vertexStart, int vertexCount) |
| | | 150 | | : this(vertexStart, vertexCount, PhysicsLayerMask.All) |
| | | 151 | | { |
| | | 152 | | } |
| | | 153 | | |
| | | 154 | | /// <summary> |
| | | 155 | | /// Gets the first polygon vertex index in the batch's shared vertex buffer. |
| | | 156 | | /// </summary> |
| | | 157 | | public int VertexStart { get; } |
| | | 158 | | |
| | | 159 | | /// <summary> |
| | | 160 | | /// Gets the number of polygon vertices in the shared vertex buffer. |
| | | 161 | | /// </summary> |
| | | 162 | | public int VertexCount { get; } |
| | | 163 | | |
| | | 164 | | /// <summary> |
| | | 165 | | /// Gets the included physics layers. |
| | | 166 | | /// </summary> |
| | | 167 | | public PhysicsLayerMask LayerMask { get; } |
| | | 168 | | } |
| | | 169 | | |
| | | 170 | | /// <summary> |
| | | 171 | | /// Describes one pure 2D swept-circle query in a batched query call. |
| | | 172 | | /// </summary> |
| | | 173 | | public readonly struct PhysicsSweepCircle2DRequest |
| | | 174 | | { |
| | | 175 | | /// <summary> |
| | | 176 | | /// Creates a pure 2D swept-circle request. |
| | | 177 | | /// </summary> |
| | | 178 | | public PhysicsSweepCircle2DRequest( |
| | | 179 | | Vector2d start, |
| | | 180 | | Vector2d end, |
| | | 181 | | Fixed64 radius, |
| | | 182 | | PhysicsLayerMask layerMask, |
| | | 183 | | LSCollider2D? excludedCollider = null, |
| | | 184 | | bool includeTriggers = true) |
| | | 185 | | { |
| | | 186 | | Start = start; |
| | | 187 | | End = end; |
| | | 188 | | Radius = radius; |
| | | 189 | | LayerMask = layerMask; |
| | | 190 | | ExcludedCollider = excludedCollider; |
| | | 191 | | IncludeTriggers = includeTriggers; |
| | | 192 | | } |
| | | 193 | | |
| | | 194 | | /// <summary> |
| | | 195 | | /// Creates a pure 2D swept-circle request against all physics layers. |
| | | 196 | | /// </summary> |
| | | 197 | | public PhysicsSweepCircle2DRequest(Vector2d start, Vector2d end, Fixed64 radius) |
| | | 198 | | : this(start, end, radius, PhysicsLayerMask.All) |
| | | 199 | | { |
| | | 200 | | } |
| | | 201 | | |
| | | 202 | | /// <summary> |
| | | 203 | | /// Gets the swept-circle center's start in the X/Z plane. |
| | | 204 | | /// </summary> |
| | | 205 | | public Vector2d Start { get; } |
| | | 206 | | |
| | | 207 | | /// <summary> |
| | | 208 | | /// Gets the swept-circle center's end in the X/Z plane. |
| | | 209 | | /// </summary> |
| | | 210 | | public Vector2d End { get; } |
| | | 211 | | |
| | | 212 | | /// <summary> |
| | | 213 | | /// Gets the swept circle radius. |
| | | 214 | | /// </summary> |
| | | 215 | | public Fixed64 Radius { get; } |
| | | 216 | | |
| | | 217 | | /// <summary> |
| | | 218 | | /// Gets the included physics layers. |
| | | 219 | | /// </summary> |
| | | 220 | | public PhysicsLayerMask LayerMask { get; } |
| | | 221 | | |
| | | 222 | | /// <summary> |
| | | 223 | | /// Gets the collider omitted from candidate results, if any. |
| | | 224 | | /// </summary> |
| | | 225 | | public LSCollider2D? ExcludedCollider { get; } |
| | | 226 | | |
| | | 227 | | /// <summary> |
| | | 228 | | /// Gets whether trigger colliders are included. |
| | | 229 | | /// </summary> |
| | | 230 | | public bool IncludeTriggers { get; } |
| | | 231 | | } |