Skip to main content

BoundingBox

Axis Aligned collision primitive for Excalibur.

Index

Constructors

constructor

  • Constructor allows passing of either an object with all coordinate components, or the coordinate components passed separately.


    Parameters

    • leftOrOptions: number | BoundingBoxOptions = 0

      Either x coordinate of the left edge or an options object containing the four coordinate components.

    • top: number = 0

      y coordinate of the top edge

    • right: number = 0

      x coordinate of the right edge

    • bottom: number = 0

      y coordinate of the bottom edge

    Returns BoundingBox

Properties

publicbottom

bottom: number

publicleft

left: number

publicright

right: number

publictop

top: number

Accessors

publicbottomLeft

publicbottomRight

publiccenter

  • Returns the center of the bounding box


    Returns Vector

publicdimensions

publicheight

  • get height(): number
  • Returns the calculated height of the bounding box


    Returns number

publictopLeft

publictopRight

publicwidth

  • get width(): number
  • Returns the calculated width of the bounding box


    Returns number

Methods

publicclone

publiccombine

  • Combines this bounding box and another together returning a new bounding box


    Parameters

    Returns BoundingBox

publiccontains

  • Tests whether a point is contained within the bounding box


    Parameters

    Returns boolean

publicdraw

publicgetPerimeter

  • getPerimeter(): number
  • Returns the perimeter of the bounding box


    Returns number

publicgetPoints

  • Returns the world space points that make up the corners of the bounding box as a polygon


    Returns Vector[]

publichasZeroDimensions

  • hasZeroDimensions(): boolean
  • Return whether the bounding box has zero dimensions in height,width or both


    Returns boolean

publicintersect

  • Test wether this bounding box intersects with another returning the intersection vector that can be used to resolve the collision. If there is no intersection null is returned.


    Parameters

    Returns Vector

    A Vector in the direction of the current BoundingBox, this <- other

publicintersectWithSide

  • Test whether the bounding box has intersected with another bounding box, returns the side of the current bb that intersected.


    Parameters

    Returns Side

publicoverlaps

  • overlaps(other: BoundingBox, epsilon?: number): boolean
  • Returns true if the bounding boxes overlap.


    Parameters

    • other: BoundingBox
    • optionalepsilon: number

      Optionally specify a small epsilon (default 0) as amount of overlap to ignore as overlap. This epsilon is useful in stable collision simulations.

    Returns boolean

publicrayCast

  • rayCast(ray: Ray, farClipDistance?: number): boolean
  • Determines whether a ray intersects with a bounding box


    Parameters

    • ray: Ray
    • farClipDistance: number = Infinity

    Returns boolean

publicrayCastTime

  • rayCastTime(ray: Ray, farClipDistance?: number): number
  • Parameters

    • ray: Ray
    • farClipDistance: number = Infinity

    Returns number

publicreset

  • reset(): void
  • Resets the bounds to a zero width/height box


    Returns void

publicrotate

  • Rotates a bounding box by and angle and around a point, if no point is specified (0, 0) is used by default. The resulting bounding box is also axis-align. This is useful when a new axis-aligned bounding box is needed for rotated geometry.


    Parameters

    • angle: number
    • point: Vector = Vector.Zero

    Returns BoundingBox

publicscale

  • Scale a bounding box by a scale factor, optionally provide a point


    Parameters

    Returns BoundingBox

publictransform

publictranslate

publicstaticfromDimension

  • Creates a bounding box from a width and height


    Parameters

    • width: number
    • height: number
    • anchor: Vector = Vector.Half

      Default Vector.Half

    • pos: Vector = Vector.Zero

      Default Vector.Zero

    Returns BoundingBox

publicstaticfromPoints

publicstaticgetSideFromIntersection

  • getSideFromIntersection(intersection: Vector): Side
  • Given bounding box A & B, returns the side relative to A when intersection is performed.


    Parameters

    • intersection: Vector

      Intersection vector between 2 bounding boxes

    Returns Side