In Files

  • benchmark/ao-render.rb

Sphere

Public Class Methods

new(center, radius) click to toggle source
 
               # File benchmark/ao-render.rb, line 83
def initialize(center, radius)
  @center = center
  @radius = radius
end
            

Public Instance Methods

center() click to toggle source
 
               # File benchmark/ao-render.rb, line 88
def center; @center; end
            
intersect(ray, isect) click to toggle source
 
               # File benchmark/ao-render.rb, line 91
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 then
    t = - b - Math.sqrt(d)

    if t > 0.0 and t < isect.t then
      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/ao-render.rb, line 89
def radius; @radius; end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus