Ejemplo n.º 1
0
    def test_perspective_camera(self):
        cam = PerspectiveCamera(screen_distance=1.0, aspect_ratio=2.0)

        # Fire one ray for each corner of the image plane
        ray1 = cam.fire_ray(0.0, 0.0)
        ray2 = cam.fire_ray(1.0, 0.0)
        ray3 = cam.fire_ray(0.0, 1.0)
        ray4 = cam.fire_ray(1.0, 1.0)

        # Verify that all the rays depart from the same point
        assert ray1.origin.is_close(ray2.origin)
        assert ray1.origin.is_close(ray3.origin)
        assert ray1.origin.is_close(ray4.origin)

        # Verify that the ray hitting the corners have the right coordinates
        assert ray1.at(1.0).is_close(Point(0.0, 2.0, -1.0))
        assert ray2.at(1.0).is_close(Point(0.0, -2.0, -1.0))
        assert ray3.at(1.0).is_close(Point(0.0, 2.0, 1.0))
        assert ray4.at(1.0).is_close(Point(0.0, -2.0, 1.0))
Ejemplo n.º 2
0
    def test_perspective_camera_transform(self):
        cam = PerspectiveCamera(transformation=translation(-VEC_Y * 2.0) *
                                rotation_z(pi / 2.0))

        ray = cam.fire_ray(0.5, 0.5)
        assert ray.at(1.0).is_close(Point(0.0, -2.0, 0.0))