Engine API Reference - v2.23.0-beta.17
    Preparing search index...

    Class OrientedBox

    An oriented bounding box is a box that can be rotated and translated in 3D space. It is defined by a world transform and half extents. Unlike an axis-aligned bounding box, an OBB can be oriented arbitrarily.

    The constructor takes a Mat4 holding the box's position and rotation, then its half extents. Scale is assumed to be one, so size the box with the half extents rather than the matrix. worldTransform can be reassigned at any time and the setter copies the matrix, so assigning an entity's world transform each frame gives a box that follows it. The tests containsPoint, intersectsRay and intersectsBoundingSphere return a boolean and allocate nothing.

    // A 2 x 1 x 4 box that follows an entity
    const box = new OrientedBox(entity.getWorldTransform(), new Vec3(1, 0.5, 2));

    // later, after the entity has moved
    box.worldTransform = entity.getWorldTransform();
    if (box.containsPoint(player.getPosition())) {
    // the player is inside the box
    }
    Index
    • Create a new OrientedBox instance.

      Parameters

      • OptionalworldTransform: Mat4 = ...

        Transform that has the orientation and position of the box. Scale is assumed to be one. Defaults to identity matrix.

      • OptionalhalfExtents: Vec3

        Half the distance across the box in each local axis. Defaults to (0.5, 0.5, 0.5).

      Returns OrientedBox

    • Test if a point is inside an OBB.

      Parameters

      • point: Vec3

        Point to test.

      Returns boolean

      True if the point is inside the OBB and false otherwise.

    • Test if a Bounding Sphere is overlapping, enveloping, or inside this OBB.

      Parameters

      Returns boolean

      True if the Bounding Sphere is overlapping, enveloping or inside this OBB and false otherwise.

    • Test if a ray intersects with the OBB.

      Parameters

      • ray: Ray

        Ray to test against (direction must be normalized).

      • Optionalpoint: Vec3

        If there is an intersection, the intersection point will be copied into here.

      Returns boolean

      True if there is an intersection.