public bool Intersects(ref AABox3d aabb3d, out double t) { if (Math.Abs(Direction.X) < double.Epsilon && (Position.X < aabb3d.Min.X || Position.X > aabb3d.Max.X)) { t = 0; return false; } double tmin = 0, tmax = double.MaxValue; double inverseDirection = 1 / Direction.X; double t1 = (aabb3d.Min.X - Position.X) * inverseDirection; double t2 = (aabb3d.Max.X - Position.X) * inverseDirection; if (t1 > t2) { double temp = t1; t1 = t2; t2 = temp; } tmin = Math.Max(tmin, t1); tmax = Math.Min(tmax, t2); if (tmin > tmax) { t = 0; return false; } if (Math.Abs(Direction.Y) < double.Epsilon && (Position.Y < aabb3d.Min.Y || Position.Y > aabb3d.Max.Y)) { t = 0; return false; } inverseDirection = 1 / Direction.Y; t1 = (aabb3d.Min.Y - Position.Y) * inverseDirection; t2 = (aabb3d.Max.Y - Position.Y) * inverseDirection; if (t1 > t2) { double temp = t1; t1 = t2; t2 = temp; } tmin = Math.Max(tmin, t1); tmax = Math.Min(tmax, t2); if (tmin > tmax) { t = 0; return false; } if (Math.Abs(Direction.Z) < double.Epsilon && (Position.Z < aabb3d.Min.Z || Position.Z > aabb3d.Max.Z)) { t = 0; return false; } inverseDirection = 1 / Direction.Z; t1 = (aabb3d.Min.Z - Position.Z) * inverseDirection; t2 = (aabb3d.Max.Z - Position.Z) * inverseDirection; if (t1 > t2) { double temp = t1; t1 = t2; t2 = temp; } tmin = Math.Max(tmin, t1); tmax = Math.Min(tmax, t2); if (tmin > tmax) { t = 0; return false; } t = tmin; return true; }
public bool Intersects(AABox3d boundingBox, out double t) { return Intersects(ref boundingBox, out t); }