示例#1
0
def colored_sphere(i, j, nx, ny):
    s = Sphere(Vec3(0, 0, -1), 0.5)
    r = origin_to_pixel(i, j, nx, ny)
    if s.hit(r, 0, float("inf")):
        return (s.normal + Vec3(1, 1, 1)) * 255.99 / 2
    else:
        return blue_to_white(i, j, nx, ny)
示例#2
0
def naive_sphere(i, j, nx, ny):
    s = Sphere(Vec3(0, 0, -1), 0.5)
    r = origin_to_pixel(i, j, nx, ny)
    if s.hit(r, 0, float("inf")):
        # return Vec3(255, 0, 0)
        k = (abs(s.normal.dot(r.direction().unit_vector())) + 1) / 2
        return Vec3(200, 100, 30) * k
    else:
        return blue_to_white(i, j, nx, ny)
示例#3
0
    def test_sphere_hit(self):
        ray = Ray()
        ray.setOriginXYZ(0, 0, 10)
        ray.setDirXYZ(0, 0, -1)

        pos = Vector()
        pos.x = pos.y = pos.z = 0
        r = 1
        sphere = Sphere(pos, r)

        result = sphere.hit(ray)
        self.assertEqual(result['hit'], True)
        self.assertEqual(result['tmin'], 9)