def test_positive_z_orientation_matrix(): f = Point(0, 0, 0) to = Point(0, 0, 1) up = Vector(0, 1, 0) t = ViewTransform(f, to, up) print(t) assert t == Scaling(-1, 1, -1)
def test_default_orientation_matrix(): f = Point(0, 0, 0) to = Point(0, 0, -1) up = Vector(0, 1, 0) t = ViewTransform(f, to, up) print(t) assert t == Identity()
def test_render(): w = World.default() c = Camera(11, 11, math.pi / 2) f = Point(0, 0, -5) to = Point(0, 0, 0) up = Vector(0, 1, 0) c.transform = ViewTransform(f, to, up) image = c.render(w) assert image.read_pixel(5, 5) == Color(0.38066, 0.47583, 0.2855)
def test_arbitrary_orientation(): f = Point(1, 3, 2) to = Point(4, -2, 8) up = Vector(1, 1, 0) t = ViewTransform(f, to, up) 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], ])
from raytracer.parser import Parser from raytracer.world import World from raytracer.camera import Camera from raytracer.lights import PointLight from raytracer.base import Point, Color, ViewTransform, Vector f = open("tests/obj_files/face.obj", "r") p = Parser(f) w = World() w.objects.append(p.obj_to_group()) w.light = PointLight(Point(10, 5, 5), Color(1, 1, 1)) c = Camera(10, 10, 0.785) c.transform = ViewTransform(Point(-6, 6, -10), Point(6, 0, 6), Vector(-0.45, 1, 0)) canvas = c.render(w) with open("images/triangl.ppm", "w") as f: f.write(canvas.to_ppm()) # This is wayyy too slow we're gonna need a triangle mesh or something
middle.material.refractive_index = 1.5 middle.material.specular = 1 middle.material.shininess = 300 right = Sphere() right.set_transform(Translation(1.5, 0.5, -0.5) * Scaling(0.5, 1, 0.5)) right.material.pattern = StripePattern(Color(1, 1, 1), Color(0, 1, 0)) right.material.pattern.set_pattern_transform( Scaling(0.1, 0.1, 0.1) * RotationY(math.pi / 4)) right.material.color = Color(0.1, 1, 0.5) 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 world = World() world.objects.extend([floor, middle, right, left]) world.light = PointLight(Point(-10, 10, -10), Color(1, 1, 1)) camera = Camera(1024, 512, math.pi / 3) camera.transform = ViewTransform(Point(0, 1.5, -5), Point(0, 1, 0), Vector(0, 1, 0)) canvas = camera.render(world) with open("pattern.ppm", "w") as f: f.write(canvas.to_ppm())
def test_movement(): f = Point(0, 0, 8) to = Point(0, 0, 0) up = Vector(0, 1, 0) t = ViewTransform(f, to, up) assert t == Translation(0, 0, -8)