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
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
Instance Attribute Details
Instance Method Details
#color(point:) ⇒ Color
37 38 39 |
# File 'lib/ra/shape/base.rb', line 37 def color(point:) @material.color(point: uv_point(point: @transform.inverse * point)) end |
#intersect(ray:) ⇒ Array<Ra::Intersection>
22 23 24 25 |
# File 'lib/ra/shape/base.rb', line 22 def intersect(ray:) t_intersect(ray: ray.transform(@transform.inverse)) .map { |t| Ra::Intersection.new(ray:, shape: self, t:) } end |
#l_normal(point:) ⇒ Vector
55 56 57 |
# File 'lib/ra/shape/base.rb', line 55 def l_normal(point:) raise NotImplementedError, '#l_normal must be implemented by a concrete subclass' end |
#normal(point:) ⇒ Vector
Returns <x, y, z, Tuple::POINT>.
29 30 31 32 33 |
# File 'lib/ra/shape/base.rb', line 29 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>
49 50 51 |
# File 'lib/ra/shape/base.rb', line 49 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>.
43 44 45 |
# File 'lib/ra/shape/base.rb', line 43 def uv_point(point:) raise NotImplementedError, '#uv_point must be implemented by a concrete subclass' end |