Class: Stagecraft::Bounding::Box3
- Inherits:
-
Object
- Object
- Stagecraft::Bounding::Box3
- Defined in:
- lib/stagecraft/core/bounding.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Instance Method Summary collapse
- #center ⇒ Object
- #empty? ⇒ Boolean
- #expand_by_point(point) ⇒ Object
-
#initialize(min = nil, max = nil) ⇒ Box3
constructor
A new instance of Box3.
- #intersects_ray?(origin, inverse_direction) ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize(min = nil, max = nil) ⇒ Box3
Returns a new instance of Box3.
8 9 10 11 |
# File 'lib/stagecraft/core/bounding.rb', line 8 def initialize(min = nil, max = nil) @min = min || Larb::Vec3.new(Float::INFINITY, Float::INFINITY, Float::INFINITY) @max = max || Larb::Vec3.new(-Float::INFINITY, -Float::INFINITY, -Float::INFINITY) end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
6 7 8 |
# File 'lib/stagecraft/core/bounding.rb', line 6 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
6 7 8 |
# File 'lib/stagecraft/core/bounding.rb', line 6 def min @min end |
Instance Method Details
#center ⇒ Object
23 24 25 26 27 |
# File 'lib/stagecraft/core/bounding.rb', line 23 def center return Larb::Vec3.new if empty? (min + max) * 0.5 end |
#empty? ⇒ Boolean
19 20 21 |
# File 'lib/stagecraft/core/bounding.rb', line 19 def empty? min.x > max.x || min.y > max.y || min.z > max.z end |
#expand_by_point(point) ⇒ Object
13 14 15 16 17 |
# File 'lib/stagecraft/core/bounding.rb', line 13 def (point) @min = min.min(point) @max = max.max(point) self end |
#intersects_ray?(origin, inverse_direction) ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/stagecraft/core/bounding.rb', line 33 def intersects_ray?(origin, inverse_direction) tmin = -Float::INFINITY tmax = Float::INFINITY 3.times do |axis| first = (min[axis] - origin[axis]) * inverse_direction[axis] second = (max[axis] - origin[axis]) * inverse_direction[axis] first, second = second, first if first > second tmin = [tmin, first].max tmax = [tmax, second].min return false if tmax < [tmin, 0.0].max end true end |
#size ⇒ Object
29 30 31 |
# File 'lib/stagecraft/core/bounding.rb', line 29 def size empty? ? Larb::Vec3.new : max - min end |