Esempio n. 1
0
    def test_set_origin_xyz(self):
        ray = Ray()

        v = Vector()
        v.x = 1
        v.y = 2
        v.z = 3

        ray.setOriginXYZ(1, 2, 3)
        self.assertTrue(ray.origin.equal(v))
Esempio n. 2
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)
Esempio n. 3
0
    def test_plane_hit(self):
        ray = Ray()
        ray.setOriginXYZ(10, 10, 10)
        ray.setDirXYZ(0, 0, -1)

        pos = Vector()
        normal = Vector()
        normal.z = 1
        plane = Plane(pos, normal)

        result = plane.hit(ray)

        self.assertEqual(result['hit'], True)
        self.assertEqual(result['tmin'], 10)
Esempio n. 4
0
    def render_scene(self):
        zw = 100
        zdir = -1

        image = Image.new('RGB', (self.vp.hres, self.vp.vres), (0, 0, 0))
        draw = ImageDraw.Draw(image)

        for r in range(self.vp.vres):
            for c in range(self.vp.hres):
                x = self.vp.s * (r - 0.5 * (self.vp.hres - 1))
                y = self.vp.s * (c - 0.5 * (self.vp.vres - 1))
                ray = Ray()
                ray.setOriginXYZ(x, y, zw)
                ray.setDirXYZ(0, 0, zdir)
                # pixel = self.tracer.trace_ray(ray)
                pixel = self.mul_tracer.trace_ray(ray).color
                draw.point((r, c), fill=(pixel.r, pixel.g, pixel.b))

        image.save('code.jpg', 'jpeg')
Esempio n. 5
0
    def render_scene(self, world):
        zw = 100
        zdir = -1
        vp = ViewPlane()

        image = Image.new('RGB', (vp.hres, vp.vres), (0, 0, 0))
        draw = ImageDraw.Draw(image)

        for r in range(vp.vres):
            for c in range(vp.hres):
                x = vp.s * (r - 0.5 * (vp.hres - 1))
                y = vp.s * (c - 0.5 * (vp.vres - 1))
                ray = Ray()
                ray.setOriginXYZ(x, y, zw)
                ray.setDirXYZ(0, 0, zdir)
                pixel = world.mul_tracer.trace_ray(ray).color
                draw.point((r, c), fill=(pixel.r, pixel.g, pixel.b))

        image.save('camera.jpg', 'jpeg')