Exemple #1
0
 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)
Exemple #2
0
def get_color(scene, lights, ray):
    # scene, lights, ray -> int
    t, normal = intersect_scene(scene, ray)
    ep = 1

    if not t or t <= 0:
        return 0
    if t:
        # calulate new pos...
        new_pos = ry.at_t(ray, t)
        new_pos = vr.add_vector(new_pos, vr.scale_mul(ep, normal))
        return intersect_lights(scene, lights, new_pos, normal)
Exemple #3
0
def at_t(ray, t):
    # ray, float -> vector
    pos = get_pos(ray)
    dirn = get_dirn(ray)
    new_pos = vr.add_vector(pos, vr.scale_mul(t, dirn))
    return new_pos