def camera(i, j): # int, int -> vector a alpha = math.tan(fovx/2)*((i - (width/2))/(width/2)) beta = math.tan(fovy/2)*(((height/2) - j)/(height/2)) dirn = vr.add_vector(vr.add_vector(vr.scale_mul(alpha, side(geo)), vr.scale_mul(beta, up(geo))), forward(geo)) dirn = vr.normalize(dirn) return ry.make_ray(eye, dirn)
def intersect_lights(scene, lights, pos, normal): # scene, light, vector -> float color = 1 for light in lights: dirn = vr.normalize(vr.sub_vector(lt.get_pos(light), pos)) new_ray = ry.make_ray(pos, dirn) t, n = intersect_scene(scene, new_ray) if not t: dot_or_0 = max([vr.dot_prod(dirn, normal), 0]) incr = dot_or_0 * lt.get_brightness(light) color += incr if color: return min([8, color])