In Files

  • benchmark/bm_ao_render.rb

Sphere

Public Class Methods

new(center, radius) click to toggle source
 
               # File benchmark/bm_ao_render.rb, line 82
def initialize(center, radius)
  @center = center
  @radius = radius
end
            

Public Instance Methods

center() click to toggle source
 
               # File benchmark/bm_ao_render.rb, line 87
def center; @center; end
            
intersect(ray, isect) click to toggle source
 
               # File 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() click to toggle source
 
               # File benchmark/bm_ao_render.rb, line 88
def radius; @radius; end