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.
Instance Method Summary collapse
- #color(point:) ⇒ Color
-
#initialize(material:, transform: Transform::IDENTITY) ⇒ Base
constructor
A new instance of Base.
- #intersect(ray:) ⇒ Array<Ra::Intersection>
- #l_normal(point:) ⇒ Vector
-
#normal(point:) ⇒ Vector
<x, y, z, Tuple::POINT>.
- #t_intersect(ray:) ⇒ Array<Intersection>
-
#uv_point(point:) ⇒ Vector
<u = 0.0..1.0, v = 0.0..1.0>.
Constructor Details
#initialize(material:, transform: Transform::IDENTITY) ⇒ 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 |
Instance Method Details
#color(point:) ⇒ Color
35 36 37 |
# File 'lib/ra/shape/base.rb', line 35 def color(point:) @material.color(point: uv_point(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 |
#l_normal(point:) ⇒ Vector
53 54 55 |
# File 'lib/ra/shape/base.rb', line 53 def l_normal(point:) raise NotImplementedError, '#l_normal must be implemented by a concrete subclass' 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 |
#t_intersect(ray:) ⇒ Array<Intersection>
47 48 49 |
# File 'lib/ra/shape/base.rb', line 47 def t_intersect(ray:) raise NotImplementedError, '#t_intersect must be implemented by a concrete subclass' end |
#uv_point(point:) ⇒ Vector
Returns <u = 0.0..1.0, v = 0.0..1.0>.
41 42 43 |
# File 'lib/ra/shape/base.rb', line 41 def uv_point(point:) raise NotImplementedError, '#uv_point must be implemented by a concrete subclass' end |