From 6f7bac388031e062adfdce8694a9b1ffe1ecb14c Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Tue, 13 Aug 2019 09:51:53 -0500 Subject: [PATCH] BoundingBox#intersect? now supports Ray --- lib/cyberarm_engine/lib/bounding_box.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/cyberarm_engine/lib/bounding_box.rb b/lib/cyberarm_engine/lib/bounding_box.rb index 83cd68e..591cba3 100644 --- a/lib/cyberarm_engine/lib/bounding_box.rb +++ b/lib/cyberarm_engine/lib/bounding_box.rb @@ -49,11 +49,17 @@ module CyberarmEngine return temp end - # returns whether both bounding boxes intersect + # returns whether bounding box intersects other def intersect?(other) - (@min.x <= other.max.x && @max.x >= other.min.x) && - (@min.y <= other.max.y && @max.y >= other.min.y) && - (@min.z <= other.max.z && @max.z >= other.min.z) + if other.is_a?(Ray) + other.intersect?(self) + elsif other.is_a?(BoundingBox) + (@min.x <= other.max.x && @max.x >= other.min.x) && + (@min.y <= other.max.y && @max.y >= other.min.y) && + (@min.z <= other.max.z && @max.z >= other.min.z) + else + raise "Unknown collider: #{other.class}" + end end # does this bounding box envelop other bounding box? (inclusive of border)