public AABB3D Join(AABB3D b) { Vector3 position = new(Math.Min(Left, b.Left), Math.Min(Bottom, b.Bottom), Math.Min(Back, b.Back)); Vector3 size = new Vector3(Math.Max(Right, b.Right), Math.Max(Top, b.Top), Math.Max(Front, b.Front)) - position; return(new AABB3D(position, size)); }
public AABB2D Join(AABB3D b) { Vector2 position = new(Math.Min(Left, b.Left), Math.Min(Top, b.Top)); Vector2 size = new Vector2(Math.Max(Right, b.Right), Math.Max(Bottom, b.Bottom)) - position; return(new AABB2D(position, size)); }
public static AABB3DIntersectionResult IntersectMovingAABBToAABB(AABB3D a, Vector3 movement, AABB3D b) { LineSegment3D segment = new(a.Center, a.Center + movement); AABB3D other = b.Inflate(a.Size); return(IntersectLineSegmentToAABB(segment, other)); }
public bool Intersects(AABB3D b) { return(Right > b.Left && Left < b.Right && Front > b.Back && Back < b.Front && Top > b.Bottom && Bottom < b.Top); }
public AABB3DIntersectionResult(Vector3 position, Vector3 movement, AABBFace face, AABB3D other) { Position = position; Movement = movement; Face = face; Other = other; Normal = Face switch { AABBFace.Left => - Vector3.UnitX, AABBFace.Right => Vector3.UnitX, AABBFace.Bottom => - Vector3.UnitY, AABBFace.Top => Vector3.UnitY, AABBFace.Back => - Vector3.UnitZ, AABBFace.Front => Vector3.UnitZ, _ => Vector3.One.Normalized() }; } }
public static AABB3DIntersectionResult IntersectLineSegmentToAABB(LineSegment3D line, AABB3D box) { float tMax = 1; float tMin = 0; Vector3 direction = line.Movement; for (int i = 0; i < 3; i++) { if (Math.Abs(direction[i]) < float.Epsilon) { if (line.Start[i] <= box.Min[i] || line.Start[i] >= box.Max[i]) { return(default);