AABB

package
v0.0.0-...-029f470 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package AABB provides a 3D axis-aligned bounding box.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Center

func Center(a PositionSize) Vector3.XYZ

Center returns the center of the AABB, which is equal to position + (size / 2).

func End

func End(rect PositionSize) Vector3.XYZ

End returns the ending point. This is usually the corner on the top-right and forward of the bounding box, and is equivalent to position + size.

func Endpoint

func Endpoint(a PositionSize, idx int) Vector3.XYZ

Endpoint gets the position of the 8 endpoints of the AABB in space.

func HasPoint

func HasPoint(point Vector3.XYZ, a PositionSize) bool

HasPoint returns true if the AABB contains a point. Points on the faces of the AABB are considered included, though float-point precision errors may impact the accuracy of such checks.

Note: This method is not reliable for AABB with a negative size. Use abs to get a positive sized equivalent AABB to check for contained points.

func HasSurface

func HasSurface(a PositionSize) bool

HasSurface returns true if the AABB has a surface or a length, and false if the AABB is empty (all components of size are zero or negative).

func HasVolume

func HasVolume(a PositionSize) bool

HasVolume returns true if the AABB has a volume, and false if the AABB is flat, empty, or has a negative size.

func Inside

func Inside(a, b PositionSize) bool

Inside returns true if a completely encloses b.

func Intersects

func Intersects(a, b PositionSize) bool

Intersects returns true if the AABB overlaps with another.

func IntersectsPlane

func IntersectsPlane(a PositionSize, plane Plane.NormalD) bool

IntersectsPlane returns true if the AABB is on both sides of a plane.

func IntersectsRay

func IntersectsRay(a PositionSize, fromv, dirv Vector3.XYZ) (clip, normal Vector3.XYZ, ok bool)

IntersectsRay returns the point of intersection of the given ray with this AABB along with the normal or false if there is no intersection. Ray length is infinite.

func IntesectsSegment

func IntesectsSegment(a PositionSize, from, to Vector3.XYZ) (clip, normal Vector3.XYZ, ok bool)

IntesectsSegment returns the point of intersection between from and to along with this AABB along with the normal or false if there is no intersection.

func IsAproximatelyEqual

func IsAproximatelyEqual(a, b PositionSize) bool

IsAproximatelyEqual returns true if this AABB and other are approximately equal, by running [IsApproximatelyEqual] on each component.

func IsFinite

func IsFinite(a PositionSize) bool

IsFinite returns true if this AABB is finite, by calling IsFinite on each component.

func LongestAxis

func LongestAxis(a PositionSize) Vector3.XYZ

LongestAxis returns the normalized longest axis of the AABB.

func LongestAxisIndex

func LongestAxisIndex(a PositionSize) Vector3.Axis

LongestAxisIndex returns the index of the longest axis of the AABB (according to [Axis] constants).

func LongestAxisSize

func LongestAxisSize(a PositionSize) Float.X

LongestAxisSize returns the scalar length of the longest axis of the AABB.

func ShortestAxis

func ShortestAxis(a PositionSize) Vector3.XYZ

ShortestAxis returns the normalized shortest axis of the AABB.

func ShortestAxisIndex

func ShortestAxisIndex(a PositionSize) Vector3.Axis

ShortestAxisIndex returns the index of the shortest axis of the AABB (according to [Axis] constants).

func ShortestAxisSize

func ShortestAxisSize(a PositionSize) Float.X

ShortestAxisSize returns the scalar length of the shortest axis of the AABB.

func Support

func Support(dir Vector3.XYZ, a PositionSize) Vector3.XYZ

Support returns the vertex of the AABB that's the farthest in a given direction. This point is commonly known as the support point in collision detection algorithms.

func Volume

func Volume(a PositionSize) Float.X

Volume returns the volume of the AABB.

Types

type PositionSize

type PositionSize = struct {
	Position Vector3.XYZ // The origin point. This is usually the corner on the bottom-left and back of the bounding box.

	// The bounding box's width, height, and depth starting from position. Setting
	// this value also affects the end point.
	//
	// Note: It's recommended setting the width, height, and depth to non-negative
	// values. This is because most methods in Godot assume that the position is
	// the bottom-left-back corner, and the end is the top-right-forward corner.
	// To get an equivalent bounding box with non-negative size, use [Abs].
	Size Vector3.XYZ
}

AABB built-in Variant type represents an axis-aligned bounding box in a 3D space. It is defined by its position and size, which are Vector3. It is frequently used for fast overlap tests (see intersects). Although AABB itself is axis-aligned, it can be combined with Transform3D to represent a rotated or skewed bounding box.

It uses floating-point coordinates. The 2D counterpart to AABB is Rect2. There is no version of AABB that uses integer coordinates.

Note: Negative values for size are not supported. With negative size, most functions do not work correctly. Use Abs to get an equivalent AABB with a non-negative size.

func Abs

Abs returns an AABB equivalent to this bounding box, with its width, height, and depth modified to be non-negative values.

func Expand

func Expand[X Float.Any](a PositionSize, by X) PositionSize

Expand returns a copy of the AABB grown a given number of units towards all the sides.

func ExpandTo

func ExpandTo(to Vector3.XYZ, a PositionSize) PositionSize

Expand returns a copy of this AABB expanded to include a given point.

// position (-3, 2, 0), size (1, 1, 1)
var box = AABB{Vector3{-3,2,0}, Vector3{1,1,1}}
// position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2)
var box2 = box.Expand(Vector3{0, -1, 2})

func Intersection

func Intersection(a, b PositionSize) PositionSize

Intersection returns the intersection between two AABB. An empty AABB (size (0, 0, 0)) is returned on failure.

func Merge

func Merge(a, b PositionSize) PositionSize

Merge returns the smallest AABB enclosing both this AABB and b.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL