struct Eagle::AABB

Overview

An axis-aligned 3D box, given by its #min and #max corners.

Eagle uses it for mesh bounds, picking and culling. MeshInstance3D#global_bounds returns one, and Ray#intersect_aabb tests against it.

box = AABB.from_center(v3(0, 1, 0), v3(1, 1, 1))
box.contains?(v3(0.5, 1.5, 0)) # => true

ray = Ray.new(v3(0, 1, 10), Vec3::FORWARD)
if dist = ray.intersect_aabb(box)
  hit_point = ray.at(dist) # => (0, 1, 1)
end

Defined in:

eagle/math/rect.cr

Constructors

Instance Method Summary

Constructor Detail

def self.from_center(center : Vec3, half : Vec3) : AABB #

Creates a box from its center and half-extents.


def self.from_points(points : Enumerable(Vec3)) : AABB #

The smallest box containing all points.


def self.new(min : Vec3, max : Vec3) #

Creates a box from its min and max corners.


Instance Method Detail

def center : Vec3 #

The center point.


def contains?(p : Vec3) : Bool #

True when the point is inside or on the surface.


def half : Vec3 #

Half the extent: the distance from the center to each face.


def intersects?(o : AABB) : Bool #

True when the boxes overlap or touch.


def max : Vec3 #

Corner with the largest coordinates.


def max=(max : Vec3) #

Corner with the largest coordinates.


def min : Vec3 #

Corner with the smallest coordinates.


def min=(min : Vec3) #

Corner with the smallest coordinates.


def size : Vec3 #

The full extent along each axis.


def transformed(m : Mat4) : AABB #

The box that bounds this box after transforming it by m. It can be larger than the original when m rotates.


def union(o : AABB) : AABB #

The smallest box containing both.