def test_the_view_transformation_moves_the_world():
    # Given
    f = Point(0, 0, 8)
    to = Point(0, 0, 0)
    up = Vector(0, 1, 0)
    # When
    t = view_transform(f, to, up)
    # Then
    assert t == translation(0, 0, -8)
def test_a_view_transformation_matrix_looking_in_positive_z_direction():
    # Given
    f = Point(0, 0, 0)
    to = Point(0, 0, 1)
    up = Vector(0, 1, 0)
    # When
    t = view_transform(f, to, up)
    # Then
    assert t == scaling(-1, 1, -1)
def test_the_transformation_matrix_for_the_default_orientation():
    # Given
    f = Point(0, 0, 0)  # from
    to = Point(0, 0, -1)
    up = Vector(0, 1, 0)
    # When
    t = view_transform(f, to, up)
    # Then
    assert t == identity_matrix()
def test_an_arbitray_view_transformation():
    # Given
    f = Point(1, 3, 2)
    to = Point(4, -2, 8)
    up = Vector(1, 1, 0)
    # When
    t = view_transform(f, to, up)
    # Then
    assert t == Matrix(-0.50709, 0.50709, 0.67612, -2.36643, 0.76772, 0.60609,
                       0.12122, -2.82843, -0.35857, 0.59761, -0.71714, 0.00000,
                       0.00000, 0.00000, 0.00000, 1.00000)
def test_rendering_a_world_with_a_camera():
    # Given
    w = default_world()
    c = Camera(11, 11, pi / 2)
    f = Point(0, 0, -5)
    to = Point(0, 0, 0)
    up = Vector(0, 1, 0)
    c.transform = view_transform(f, to, up)
    # When
    image = c.render(w)
    # Then
    assert image.pixel_at(5, 5) == Color(0.38066, 0.47583, 0.2855)
Exemplo n.º 6
0
    # right.material.pattern = pattern
    # right.material.diffuse = 0.7
    # right.material.specular = 0.3
    right.material.diffuse = 0
    right.material.specular = 0

    left = Sphere()
    left.transform = translation(-1.5, 0.33, -0.75) * scaling(0.33, 0.33, 0.33)
    left.material = Material()
    left.material.color = Color(1, 0.8, 0.1)
    # left.material.pattern = pattern
    left.material.diffuse = 0.7
    left.material.specular = 0.3

    cube = Cube()
    cube.transform = translation(
        0, 0, 1) * rotation_y(pi / 4) * scaling(0.5, 0.5, 0.5)

    world = World()
    # world.objects = [floor, backdrop, backdrop2, middle, right, left]
    world.objects = [cube]
    world.light = PointLight(Point(-10, 10, -10), Color(1, 1, 1))

    camera = Camera(100, 50, pi / 3)
    camera.transform = view_transform(Point(0, 1.5, -5),
                                      Point(0, 1, 0),
                                      Vector(0, 1, 0))

    canvas = camera.render(world)
    print(canvas.to_ppm())