Class: Ra::Shape::Base
- Inherits:
-
Object
- Object
- Ra::Shape::Base
- Defined in:
- lib/ra/shape/base.rb
Overview
An abstract shape. Any concrete subclass of shape must implement the methods l_normal and t_intersect. Both methods use a point / ray with a local transform applied.
Instance Attribute Summary collapse
-
#material ⇒ Object
Returns the value of attribute material.
-
#transform ⇒ Object
Returns the value of attribute transform.
Instance Method Summary collapse
- #color(point:) ⇒ Color
-
#initialize(material:, transform: Transform::IDENTITY) ⇒ Base
constructor
A new instance of Base.
- #intersect(ray:) ⇒ Array<Ra::Intersection>
- #normal(point:) ⇒ Vector
Constructor Details
#initialize(material:, transform: Transform::IDENTITY) ⇒ Base
Returns a new instance of Base.
13 14 15 16 |
# File 'lib/ra/shape/base.rb', line 13 def initialize(material:, transform: Transform::IDENTITY) @material = material @transform = transform end |
Instance Attribute Details
#material ⇒ Object
Returns the value of attribute material.
9 10 11 |
# File 'lib/ra/shape/base.rb', line 9 def material @material end |
#transform ⇒ Object
Returns the value of attribute transform.
9 10 11 |
# File 'lib/ra/shape/base.rb', line 9 def transform @transform end |
Instance Method Details
#color(point:) ⇒ Color
35 36 37 |
# File 'lib/ra/shape/base.rb', line 35 def color(point:) @material.color(point: transform.inverse * point) end |
#intersect(ray:) ⇒ Array<Ra::Intersection>
20 21 22 23 |
# File 'lib/ra/shape/base.rb', line 20 def intersect(ray:) t_intersect(ray: ray.transform(transform.inverse)) .map { |t| Ra::Intersection.new(ray:, shape: self, t:) } end |
#normal(point:) ⇒ Vector
27 28 29 30 31 |
# File 'lib/ra/shape/base.rb', line 27 def normal(point:) normal = transform.inverse.transpose * l_normal(point: transform.inverse * point) Vector[normal[0], normal[1], normal[2], Ra::Tuple::VECTOR].normalize end |