lib/cyberarm_engine/lib/ray.rb in cyberarm_engine-0.10.2 vs lib/cyberarm_engine/lib/ray.rb in cyberarm_engine-0.11.0

- old
+ new

@@ -1,13 +1,14 @@ module CyberarmEngine class Ray - def initialize(origin, direction) + def initialize(origin, direction, range = Float::INFINITY) raise "Origin must be a Vector!" unless origin.is_a?(Vector) raise "Direction must be a Vector!" unless direction.is_a?(Vector) @origin = origin @direction = direction + @range = range @inverse_direction = @direction.inverse end def intersect?(intersectable) @@ -18,11 +19,11 @@ end end # Based on: https://tavianator.com/fast-branchless-raybounding-box-intersections/ def intersect_bounding_box?(box) - tmin = -Float::INFINITY - tmax = Float::INFINITY + tmin = -@range + tmax = @range tx1 = (box.min.x - @origin.x) * @inverse_direction.x tx2 = (box.max.x - @origin.x) * @inverse_direction.x tmin = max(tmin, min(tx1, tx2)) \ No newline at end of file