| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="AABB" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | A 3D axis-aligned bounding box. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | The [AABB] built-in [Variant] type represents an axis-aligned bounding box in a 3D space. It is defined by its [member position] and [member size], which are [Vector3]. It is frequently used for fast overlap tests (see [method intersects]). Although [AABB] itself is axis-aligned, it can be combined with [Transform3D] to represent a rotated or skewed bounding box. |
| 8 | It uses floating-point coordinates. The 2D counterpart to [AABB] is [Rect2]. There is no version of [AABB] that uses integer coordinates. |
| 9 | [b]Note:[/b] Negative values for [member size] are not supported. With negative size, most [AABB] methods do not work correctly. Use [method abs] to get an equivalent [AABB] with a non-negative size. |
| 10 | [b]Note:[/b] In a boolean context, an [AABB] evaluates to [code]false[/code] if both [member position] and [member size] are zero (equal to [constant Vector3.ZERO]). Otherwise, it always evaluates to [code]true[/code]. |
| 11 | </description> |
| 12 | <tutorials> |
| 13 | <link title="Math documentation index">$DOCS_URL/tutorials/math/index.html</link> |
| 14 | <link title="Vector math">$DOCS_URL/tutorials/math/vector_math.html</link> |
| 15 | <link title="Advanced vector math">$DOCS_URL/tutorials/math/vectors_advanced.html</link> |
| 16 | </tutorials> |
| 17 | <constructors> |
| 18 | <constructor name="AABB"> |
| 19 | <return type="AABB" /> |
| 20 | <description> |
| 21 | Constructs an [AABB] with its [member position] and [member size] set to [constant Vector3.ZERO]. |
| 22 | </description> |
| 23 | </constructor> |
| 24 | <constructor name="AABB"> |
| 25 | <return type="AABB" /> |
| 26 | <param index="0" name="from" type="AABB" /> |
| 27 | <description> |
| 28 | Constructs an [AABB] as a copy of the given [AABB]. |
| 29 | </description> |
| 30 | </constructor> |
| 31 | <constructor name="AABB"> |
| 32 | <return type="AABB" /> |
| 33 | <param index="0" name="position" type="Vector3" /> |
| 34 | <param index="1" name="size" type="Vector3" /> |
| 35 | <description> |
| 36 | Constructs an [AABB] by [param position] and [param size]. |
| 37 | </description> |
| 38 | </constructor> |
| 39 | </constructors> |
| 40 | <methods> |
| 41 | <method name="abs" qualifiers="const"> |
| 42 | <return type="AABB" /> |
| 43 | <description> |
| 44 | Returns an [AABB] equivalent to this bounding box, with its width, height, and depth modified to be non-negative values. |
| 45 | [codeblocks] |
| 46 | [gdscript] |
| 47 | var box = AABB(Vector3(5, 0, 5), Vector3(-20, -10, -5)) |
| 48 | var absolute = box.abs() |
| 49 | print(absolute.position) # Prints (-15.0, -10.0, 0.0) |
| 50 | print(absolute.size) # Prints (20.0, 10.0, 5.0) |
| 51 | [/gdscript] |
| 52 | [csharp] |
| 53 | var box = new Aabb(new Vector3(5, 0, 5), new Vector3(-20, -10, -5)); |
| 54 | var absolute = box.Abs(); |
| 55 | GD.Print(absolute.Position); // Prints (-15, -10, 0) |
| 56 | GD.Print(absolute.Size); // Prints (20, 10, 5) |
| 57 | [/csharp] |
| 58 | [/codeblocks] |
| 59 | [b]Note:[/b] It's recommended to use this method when [member size] is negative, as most other methods in Godot assume that the [member size]'s components are greater than [code]0[/code]. |
| 60 | </description> |
| 61 | </method> |
| 62 | <method name="encloses" qualifiers="const"> |
| 63 | <return type="bool" /> |
| 64 | <param index="0" name="with" type="AABB" /> |
| 65 | <description> |
| 66 | Returns [code]true[/code] if this bounding box [i]completely[/i] encloses the [param with] box. The edges of both boxes are included. |
| 67 | [codeblocks] |
| 68 | [gdscript] |
| 69 | var a = AABB(Vector3(0, 0, 0), Vector3(4, 4, 4)) |
| 70 | var b = AABB(Vector3(1, 1, 1), Vector3(3, 3, 3)) |
| 71 | var c = AABB(Vector3(2, 2, 2), Vector3(8, 8, 8)) |
| 72 | |
| 73 | print(a.encloses(a)) # Prints true |
| 74 | print(a.encloses(b)) # Prints true |
| 75 | print(a.encloses(c)) # Prints false |
| 76 | [/gdscript] |
| 77 | [csharp] |
| 78 | var a = new Aabb(new Vector3(0, 0, 0), new Vector3(4, 4, 4)); |
| 79 | var b = new Aabb(new Vector3(1, 1, 1), new Vector3(3, 3, 3)); |
| 80 | var c = new Aabb(new Vector3(2, 2, 2), new Vector3(8, 8, 8)); |
| 81 | |
| 82 | GD.Print(a.Encloses(a)); // Prints True |
| 83 | GD.Print(a.Encloses(b)); // Prints True |
| 84 | GD.Print(a.Encloses(c)); // Prints False |
| 85 | [/csharp] |
| 86 | [/codeblocks] |
| 87 | </description> |
| 88 | </method> |
| 89 | <method name="expand" qualifiers="const"> |
| 90 | <return type="AABB" /> |
| 91 | <param index="0" name="to_point" type="Vector3" /> |
| 92 | <description> |
| 93 | Returns a copy of this bounding box expanded to align the edges with the given [param to_point], if necessary. |
| 94 | [codeblocks] |
| 95 | [gdscript] |
| 96 | var box = AABB(Vector3(0, 0, 0), Vector3(5, 2, 5)) |
| 97 | |
| 98 | box = box.expand(Vector3(10, 0, 0)) |
| 99 | print(box.position) # Prints (0.0, 0.0, 0.0) |
| 100 | print(box.size) # Prints (10.0, 2.0, 5.0) |
| 101 | |
| 102 | box = box.expand(Vector3(-5, 0, 5)) |
| 103 | print(box.position) # Prints (-5.0, 0.0, 0.0) |
| 104 | print(box.size) # Prints (15.0, 2.0, 5.0) |
| 105 | [/gdscript] |
| 106 | [csharp] |
| 107 | var box = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 5)); |
| 108 | |
| 109 | box = box.Expand(new Vector3(10, 0, 0)); |
| 110 | GD.Print(box.Position); // Prints (0, 0, 0) |
| 111 | GD.Print(box.Size); // Prints (10, 2, 5) |
| 112 | |
| 113 | box = box.Expand(new Vector3(-5, 0, 5)); |
| 114 | GD.Print(box.Position); // Prints (-5, 0, 0) |
| 115 | GD.Print(box.Size); // Prints (15, 2, 5) |
| 116 | [/csharp] |
| 117 | [/codeblocks] |
| 118 | </description> |
| 119 | </method> |
| 120 | <method name="get_center" qualifiers="const"> |
| 121 | <return type="Vector3" /> |
| 122 | <description> |
| 123 | Returns the center point of the bounding box. This is the same as [code]position + (size / 2.0)[/code]. |
| 124 | </description> |
| 125 | </method> |
| 126 | <method name="get_endpoint" qualifiers="const"> |
| 127 | <return type="Vector3" /> |
| 128 | <param index="0" name="idx" type="int" /> |
| 129 | <description> |
| 130 | Returns the position of one of the 8 vertices that compose this bounding box. With an [param idx] of [code]0[/code] this is the same as [member position], and an [param idx] of [code]7[/code] is the same as [member end]. |
| 131 | </description> |
| 132 | </method> |
| 133 | <method name="get_longest_axis" qualifiers="const"> |
| 134 | <return type="Vector3" /> |
| 135 | <description> |
| 136 | Returns the longest normalized axis of this bounding box's [member size], as a [Vector3] ([constant Vector3.RIGHT], [constant Vector3.UP], or [constant Vector3.BACK]). |
| 137 | [codeblocks] |
| 138 | [gdscript] |
| 139 | var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8)) |
| 140 | |
| 141 | print(box.get_longest_axis()) # Prints (0.0, 0.0, 1.0) |
| 142 | print(box.get_longest_axis_index()) # Prints 2 |
| 143 | print(box.get_longest_axis_size()) # Prints 8.0 |
| 144 | [/gdscript] |
| 145 | [csharp] |
| 146 | var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8)); |
| 147 | |
| 148 | GD.Print(box.GetLongestAxis()); // Prints (0, 0, 1) |
| 149 | GD.Print(box.GetLongestAxisIndex()); // Prints Z |
| 150 | GD.Print(box.GetLongestAxisSize()); // Prints 8 |
| 151 | [/csharp] |
| 152 | [/codeblocks] |
| 153 | See also [method get_longest_axis_index] and [method get_longest_axis_size]. |
| 154 | </description> |
| 155 | </method> |
| 156 | <method name="get_longest_axis_index" qualifiers="const"> |
| 157 | <return type="int" /> |
| 158 | <description> |
| 159 | Returns the index to the longest axis of this bounding box's [member size] (see [constant Vector3.AXIS_X], [constant Vector3.AXIS_Y], and [constant Vector3.AXIS_Z]). |
| 160 | For an example, see [method get_longest_axis]. |
| 161 | </description> |
| 162 | </method> |
| 163 | <method name="get_longest_axis_size" qualifiers="const"> |
| 164 | <return type="float" /> |
| 165 | <description> |
| 166 | Returns the longest dimension of this bounding box's [member size]. |
| 167 | For an example, see [method get_longest_axis]. |
| 168 | </description> |
| 169 | </method> |
| 170 | <method name="get_shortest_axis" qualifiers="const"> |
| 171 | <return type="Vector3" /> |
| 172 | <description> |
| 173 | Returns the shortest normalized axis of this bounding box's [member size], as a [Vector3] ([constant Vector3.RIGHT], [constant Vector3.UP], or [constant Vector3.BACK]). |
| 174 | [codeblocks] |
| 175 | [gdscript] |
| 176 | var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8)) |
| 177 | |
| 178 | print(box.get_shortest_axis()) # Prints (1.0, 0.0, 0.0) |
| 179 | print(box.get_shortest_axis_index()) # Prints 0 |
| 180 | print(box.get_shortest_axis_size()) # Prints 2.0 |
| 181 | [/gdscript] |
| 182 | [csharp] |
| 183 | var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8)); |
| 184 | |
| 185 | GD.Print(box.GetShortestAxis()); // Prints (1, 0, 0) |
| 186 | GD.Print(box.GetShortestAxisIndex()); // Prints X |
| 187 | GD.Print(box.GetShortestAxisSize()); // Prints 2 |
| 188 | [/csharp] |
| 189 | [/codeblocks] |
| 190 | See also [method get_shortest_axis_index] and [method get_shortest_axis_size]. |
| 191 | </description> |
| 192 | </method> |
| 193 | <method name="get_shortest_axis_index" qualifiers="const"> |
| 194 | <return type="int" /> |
| 195 | <description> |
| 196 | Returns the index to the shortest axis of this bounding box's [member size] (see [constant Vector3.AXIS_X], [constant Vector3.AXIS_Y], and [constant Vector3.AXIS_Z]). |
| 197 | For an example, see [method get_shortest_axis]. |
| 198 | </description> |
| 199 | </method> |
| 200 | <method name="get_shortest_axis_size" qualifiers="const"> |
| 201 | <return type="float" /> |
| 202 | <description> |
| 203 | Returns the shortest dimension of this bounding box's [member size]. |
| 204 | For an example, see [method get_shortest_axis]. |
| 205 | </description> |
| 206 | </method> |
| 207 | <method name="get_support" qualifiers="const"> |
| 208 | <return type="Vector3" /> |
| 209 | <param index="0" name="direction" type="Vector3" /> |
| 210 | <description> |
| 211 | Returns the vertex's position of this bounding box that's the farthest in the given direction. This point is commonly known as the support point in collision detection algorithms. |
| 212 | </description> |
| 213 | </method> |
| 214 | <method name="get_volume" qualifiers="const"> |
| 215 | <return type="float" /> |
| 216 | <description> |
| 217 | Returns the bounding box's volume. This is equivalent to [code]size.x * size.y * size.z[/code]. See also [method has_volume]. |
| 218 | </description> |
| 219 | </method> |
| 220 | <method name="grow" qualifiers="const"> |
| 221 | <return type="AABB" /> |
| 222 | <param index="0" name="by" type="float" /> |
| 223 | <description> |
| 224 | Returns a copy of this bounding box extended on all sides by the given amount [param by]. A negative amount shrinks the box instead. |
| 225 | [codeblocks] |
| 226 | [gdscript] |
| 227 | var a = AABB(Vector3(4, 4, 4), Vector3(8, 8, 8)).grow(4) |
| 228 | print(a.position) # Prints (0.0, 0.0, 0.0) |
| 229 | print(a.size) # Prints (16.0, 16.0, 16.0) |
| 230 | |
| 231 | var b = AABB(Vector3(0, 0, 0), Vector3(8, 4, 2)).grow(2) |
| 232 | print(b.position) # Prints (-2.0, -2.0, -2.0) |
| 233 | print(b.size) # Prints (12.0, 8.0, 6.0) |
| 234 | [/gdscript] |
| 235 | [csharp] |
| 236 | var a = new Aabb(new Vector3(4, 4, 4), new Vector3(8, 8, 8)).Grow(4); |
| 237 | GD.Print(a.Position); // Prints (0, 0, 0) |
| 238 | GD.Print(a.Size); // Prints (16, 16, 16) |
| 239 | |
| 240 | var b = new Aabb(new Vector3(0, 0, 0), new Vector3(8, 4, 2)).Grow(2); |
| 241 | GD.Print(b.Position); // Prints (-2, -2, -2) |
| 242 | GD.Print(b.Size); // Prints (12, 8, 6) |
| 243 | [/csharp] |
| 244 | [/codeblocks] |
| 245 | </description> |
| 246 | </method> |
| 247 | <method name="has_point" qualifiers="const"> |
| 248 | <return type="bool" /> |
| 249 | <param index="0" name="point" type="Vector3" /> |
| 250 | <description> |
| 251 | Returns [code]true[/code] if the bounding box contains the given [param point]. By convention, points exactly on the right, top, and front sides are [b]not[/b] included. |
| 252 | [b]Note:[/b] This method is not reliable for [AABB] with a [i]negative[/i] [member size]. Use [method abs] first to get a valid bounding box. |
| 253 | </description> |
| 254 | </method> |
| 255 | <method name="has_surface" qualifiers="const"> |
| 256 | <return type="bool" /> |
| 257 | <description> |
| 258 | Returns [code]true[/code] if this bounding box has a surface or a length, that is, at least one component of [member size] is greater than [code]0[/code]. Otherwise, returns [code]false[/code]. |
| 259 | </description> |
| 260 | </method> |
| 261 | <method name="has_volume" qualifiers="const"> |
| 262 | <return type="bool" /> |
| 263 | <description> |
| 264 | Returns [code]true[/code] if this bounding box's width, height, and depth are all positive. See also [method get_volume]. |
| 265 | </description> |
| 266 | </method> |
| 267 | <method name="intersection" qualifiers="const"> |
| 268 | <return type="AABB" /> |
| 269 | <param index="0" name="with" type="AABB" /> |
| 270 | <description> |
| 271 | Returns the intersection between this bounding box and [param with]. If the boxes do not intersect, returns an empty [AABB]. If the boxes intersect at the edge, returns a flat [AABB] with no volume (see [method has_surface] and [method has_volume]). |
| 272 | [codeblocks] |
| 273 | [gdscript] |
| 274 | var box1 = AABB(Vector3(0, 0, 0), Vector3(5, 2, 8)) |
| 275 | var box2 = AABB(Vector3(2, 0, 2), Vector3(8, 4, 4)) |
| 276 | |
| 277 | var intersection = box1.intersection(box2) |
| 278 | print(intersection.position) # Prints (2.0, 0.0, 2.0) |
| 279 | print(intersection.size) # Prints (3.0, 2.0, 4.0) |
| 280 | [/gdscript] |
| 281 | [csharp] |
| 282 | var box1 = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 8)); |
| 283 | var box2 = new Aabb(new Vector3(2, 0, 2), new Vector3(8, 4, 4)); |
| 284 | |
| 285 | var intersection = box1.Intersection(box2); |
| 286 | GD.Print(intersection.Position); // Prints (2, 0, 2) |
| 287 | GD.Print(intersection.Size); // Prints (3, 2, 4) |
| 288 | [/csharp] |
| 289 | [/codeblocks] |
| 290 | [b]Note:[/b] If you only need to know whether two bounding boxes are intersecting, use [method intersects], instead. |
| 291 | </description> |
| 292 | </method> |
| 293 | <method name="intersects" qualifiers="const"> |
| 294 | <return type="bool" /> |
| 295 | <param index="0" name="with" type="AABB" /> |
| 296 | <description> |
| 297 | Returns [code]true[/code] if this bounding box overlaps with the box [param with]. The edges of both boxes are [i]always[/i] excluded. |
| 298 | </description> |
| 299 | </method> |
| 300 | <method name="intersects_plane" qualifiers="const"> |
| 301 | <return type="bool" /> |
| 302 | <param index="0" name="plane" type="Plane" /> |
| 303 | <description> |
| 304 | Returns [code]true[/code] if this bounding box is on both sides of the given [param plane]. |
| 305 | </description> |
| 306 | </method> |
| 307 | <method name="intersects_ray" qualifiers="const"> |
| 308 | <return type="Variant" /> |
| 309 | <param index="0" name="from" type="Vector3" /> |
| 310 | <param index="1" name="dir" type="Vector3" /> |
| 311 | <description> |
| 312 | Returns the first point where this bounding box and the given ray intersect, as a [Vector3]. If no intersection occurs, returns [code]null[/code]. |
| 313 | The ray begin at [param from], faces [param dir] and extends towards infinity. |
| 314 | </description> |
| 315 | </method> |
| 316 | <method name="intersects_segment" qualifiers="const"> |
| 317 | <return type="Variant" /> |
| 318 | <param index="0" name="from" type="Vector3" /> |
| 319 | <param index="1" name="to" type="Vector3" /> |
| 320 | <description> |
| 321 | Returns the first point where this bounding box and the given segment intersect, as a [Vector3]. If no intersection occurs, returns [code]null[/code]. |
| 322 | The segment begins at [param from] and ends at [param to]. |
| 323 | </description> |
| 324 | </method> |
| 325 | <method name="is_equal_approx" qualifiers="const"> |
| 326 | <return type="bool" /> |
| 327 | <param index="0" name="aabb" type="AABB" /> |
| 328 | <description> |
| 329 | Returns [code]true[/code] if this bounding box and [param aabb] are approximately equal, by calling [method Vector3.is_equal_approx] on the [member position] and the [member size]. |
| 330 | </description> |
| 331 | </method> |
| 332 | <method name="is_finite" qualifiers="const"> |
| 333 | <return type="bool" /> |
| 334 | <description> |
| 335 | Returns [code]true[/code] if this bounding box's values are finite, by calling [method Vector3.is_finite] on the [member position] and the [member size]. |
| 336 | </description> |
| 337 | </method> |
| 338 | <method name="merge" qualifiers="const"> |
| 339 | <return type="AABB" /> |
| 340 | <param index="0" name="with" type="AABB" /> |
| 341 | <description> |
| 342 | Returns an [AABB] that encloses both this bounding box and [param with] around the edges. See also [method encloses]. |
| 343 | </description> |
| 344 | </method> |
| 345 | </methods> |
| 346 | <members> |
| 347 | <member name="end" type="Vector3" setter="" getter="" default="Vector3(0, 0, 0)"> |
| 348 | The ending point. This is usually the corner on the top-right and back of the bounding box, and is equivalent to [code]position + size[/code]. Setting this point affects the [member size]. |
| 349 | </member> |
| 350 | <member name="position" type="Vector3" setter="" getter="" default="Vector3(0, 0, 0)"> |
| 351 | The origin point. This is usually the corner on the bottom-left and forward of the bounding box. |
| 352 | </member> |
| 353 | <member name="size" type="Vector3" setter="" getter="" default="Vector3(0, 0, 0)"> |
| 354 | The bounding box's width, height, and depth starting from [member position]. Setting this value also affects the [member end] point. |
| 355 | [b]Note:[/b] It's recommended setting the width, height, and depth to non-negative values. This is because most methods in Godot assume that the [member position] is the bottom-left-forward corner, and the [member end] is the top-right-back corner. To get an equivalent bounding box with non-negative size, use [method abs]. |
| 356 | </member> |
| 357 | </members> |
| 358 | <operators> |
| 359 | <operator name="operator !="> |
| 360 | <return type="bool" /> |
| 361 | <param index="0" name="right" type="AABB" /> |
| 362 | <description> |
| 363 | Returns [code]true[/code] if the [member position] or [member size] of both bounding boxes are not equal. |
| 364 | [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable. |
| 365 | </description> |
| 366 | </operator> |
| 367 | <operator name="operator *"> |
| 368 | <return type="AABB" /> |
| 369 | <param index="0" name="right" type="Transform3D" /> |
| 370 | <description> |
| 371 | Inversely transforms (multiplies) the [AABB] by the given [Transform3D] transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not). |
| 372 | [code]aabb * transform[/code] is equivalent to [code]transform.inverse() * aabb[/code]. See [method Transform3D.inverse]. |
| 373 | For transforming by inverse of an affine transformation (e.g. with scaling) [code]transform.affine_inverse() * aabb[/code] can be used instead. See [method Transform3D.affine_inverse]. |
| 374 | </description> |
| 375 | </operator> |
| 376 | <operator name="operator =="> |
| 377 | <return type="bool" /> |
| 378 | <param index="0" name="right" type="AABB" /> |
| 379 | <description> |
| 380 | Returns [code]true[/code] if both [member position] and [member size] of the bounding boxes are exactly equal, respectively. |
| 381 | [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable. |
| 382 | </description> |
| 383 | </operator> |
| 384 | </operators> |
| 385 | </class> |