예제 #1
0
        public void IntersectInsideSphereTest()
        {
            var ray    = Helper.Ray(Helper.CreatePoint(0, 0, 0), Helper.CreateVector(0, 0, 1));
            var sphere = Helper.Sphere();
            var xs     = new Intersections();

            sphere.Intersect(ref ray.Origin, ref ray.Direction, xs);
            Check.That(xs.Select(i => i.T)).ContainsExactly(-1, 1);
            Check.That(xs.Select(i => i.Object)).ContainsExactly(sphere, sphere);
        }
예제 #2
0
        public void IntersectSphereBehindRayTest()
        {
            var ray    = Helper.Ray(Helper.CreatePoint(0, 0, 5), Helper.CreateVector(0, 0, 1));
            var sphere = Helper.Sphere();
            var xs     = new Intersections();

            sphere.Intersect(ref ray.Origin, ref ray.Direction, xs);
            Check.That(xs.Select(i => i.T)).ContainsExactly(-6, -4);
        }
예제 #3
0
        public void WorldIntersectsTest()
        {
            var world         = GetDefaultWorld();
            var ray           = Helper.Ray(Helper.CreatePoint(0, 0, -5), Helper.CreateVector(0, 0, 1));
            var intersections = new Intersections();

            world.Intersect(ray, intersections);
            Check.That(intersections.Select(intersection => intersection.T)).ContainsExactly(4, 4.5, 5.5, 6);
        }
예제 #4
0
        public void IntersectScaledTest()
        {
            var ray    = Helper.Ray(Helper.CreatePoint(0, 0, -5), Helper.CreateVector(0, 0, 1));
            var sphere = Helper.Sphere();

            sphere.Transform = Helper.Scaling(2, 2, 2);

            var xs = new Intersections();

            sphere.Intersect(ref ray.Origin, ref ray.Direction, xs);
            Check.That(xs.Select(i => i.T)).ContainsExactly(3, 7);
        }