Class: Sphere
- Defined in:
- ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb
Instance Method Summary collapse
- #center ⇒ Object
-
#initialize(center, radius) ⇒ Sphere
constructor
A new instance of Sphere.
- #intersect(ray, isect) ⇒ Object
- #radius ⇒ Object
Constructor Details
#initialize(center, radius) ⇒ Sphere
Returns a new instance of Sphere.
82 83 84 85 |
# File 'ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb', line 82 def initialize(center, radius) @center = center @radius = radius end |
Instance Method Details
#center ⇒ Object
87 |
# File 'ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb', line 87 def center; @center; end |
#intersect(ray, isect) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb', line 90 def intersect(ray, isect) rs = ray.org.vsub(@center) b = rs.vdot(ray.dir) c = rs.vdot(rs) - (@radius * @radius) d = b * b - c if d > 0.0 t = - b - Math.sqrt(d) if t > 0.0 and t < isect.t isect.t = t isect.hit = true isect.pl = Vec.new(ray.org.x + ray.dir.x * t, ray.org.y + ray.dir.y * t, ray.org.z + ray.dir.z * t) n = isect.pl.vsub(@center) isect.n = n.vnormalize end end end |
#radius ⇒ Object
88 |
# File 'ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb', line 88 def radius; @radius; end |