Class: Plane

Inherits:
Object show all
Defined in:
ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb

Instance Method Summary collapse

Constructor Details

#initialize(p, n) ⇒ Plane



112
113
114
115
# File 'ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb', line 112

def initialize(p, n)
  @p = p
  @n = n
end

Instance Method Details

#intersect(ray, isect) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb', line 117

def intersect(ray, isect)
  d = -@p.vdot(@n)
  v = ray.dir.vdot(@n)
  v0 = v
  if v < 0.0
    v0 = -v
  end
  if v0 < 1.0e-17
    return
  end

  t = -(ray.org.vdot(@n) + d) / v

  if t > 0.0 and t < isect.t
    isect.hit = true
    isect.t = t
    isect.n = @n
    isect.pl = Vec.new(ray.org.x + t * ray.dir.x,
                      ray.org.y + t * ray.dir.y,
                      ray.org.z + t * ray.dir.z)
  end
end