In Files

  • typeprof-0.12.0/testbed/ao.rb

Parent

Methods

Class/Module Index [+]

Quicksearch

Sphere

Attributes

center[R]
radius[R]

Public Class Methods

new(center, radius) click to toggle source
 
               # File typeprof-0.12.0/testbed/ao.rb, line 64
def initialize(center, radius)
  @center = center
  @radius = radius
end
            

Public Instance Methods

intersect(ray, isect) click to toggle source
 
               # File typeprof-0.12.0/testbed/ao.rb, line 71
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