def test_transformation_matrix_for_the_default_orientation(self): from_where = point(0, 0, 0) to = point(0, 0, -1) up = vector(0, 1, 0) t = view_transform(from_where, to, up) self.assert_matrix_equals(identity_matrix, t)
def test_the_view_trasnformation_move_the_world(self): from_where = point(0, 0, 8) to = point(0, 0, 0) up = vector(0, 1, 0) t = view_transform(from_where, to, up) self.assert_matrix_equals(translation(0, 0, -8), t)
def test_view_transformation_matrix_looking_in_positive_z_direction(self): from_where = point(0, 0, 0) to = point(0, 0, 1) up = vector(0, 1, 0) t = view_transform(from_where, to, up) self.assertEqual(scaling(-1, 1, -1), t)
def test_arbitrary_view_transformation(self): from_where = point(1, 3, 2) to = point(4, -2, 8) up = vector(1, 1, 0) t = view_transform(from_where, to, up) m = Matrix4(-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) self.assert_matrix_equals(m, t)
def test_rendering_world_with_camera(self): w = default_world() c = Camera(11, 11, pi / 2.0) from_where = point(0, 0, -5) to = point(0, 0, 0) up = vector(0, 1, 0) c.transform = view_transform(from_where, to, up) image = render(c, w) self.assert_tuple_equals(color(0.38066, 0.47583, 0.2855), image.pixel_at(5, 5), 0.001)
middle.material.color = color(0.1, 1, 0.5) middle.material.ambient = 0.1 middle.material.diffuse = 0.7 middle.material.specular = 0.3 right = Sphere() right.transform = translation(1.5, 0.5, -0.5) * scaling(0.5, 0.5, 0.5) right.material.color = color(0.5, 1, 0.1) right.material.diffuse = 0.7 right.material.specular = 0.3 left = Sphere() left.transform = translation(-1.5, 0.33, -0.75) * scaling(0.33, 0.33, 0.33) left.material.color = color(1, 0.8, 0.1) left.material.diffuse = 0.7 left.material.specular = 0.3 light_position = point(-10, 10, -10) light_color = color(1, 1, 1) light = PointLight(light_position, light_color) world = World(light=light, objects=[left, right, middle, left_wall, right_wall, floor]) camera = Camera(200, 100, pi / 3) camera.transform = view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0)) r = render(camera, world) r.save_to_file('scene2.ppm')