Ejemplo n.º 1
0
        public void TestSomething()
        {
            var world = World.DefaultWorld();
            var A     = world.Shapes[0];

            A.Material.Pattern = new TestPattern();
            A.Material.Ambient = 1.0;

            var B = world.Shapes[1];

            B.Material.Transparency    = 1.0;
            B.Material.RefractiveIndex = 1.5;

            var ray           = new Ray(new RtPoint(0, 0, 0.1), new RtVector(0, 1, 0));
            var intersections = new IntersectionList();

            intersections.Add(new Intersection(-0.9899, A));
            intersections.Add(new Intersection(-0.4899, B));
            intersections.Add(new Intersection(0.4899, B));
            intersections.Add(new Intersection(0.9899, A));
            var computations = intersections[2].PrepareComputations(ray, intersections);
            var color        = world.RefractedColor(computations, 5);

            Assert.Equal(new RtColor(0, 0.99888, 0.04725), color);
        }
        public void ConstructorTest()
        {
            IntersectionList target = new IntersectionList();

            // TODO: Implement code to verify target
            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Ejemplo n.º 3
0
        public void RefractedColorWithRefractedRay()
        {
            var w = new DefaultWorld();

            var a = w.Objects[0];

            a.Material.Ambient = 1.0;
            a.Material.Pattern = new TestPattern();

            var b = w.Objects[1];

            b.Material.Transparency    = 1.0;
            b.Material.RefractiveIndex = 1.5;

            var r = new Ray(
                Vector4.CreatePosition(0, 0, 0.1),
                Vector4.CreateDirection(0, 1, 0));

            var xs = IntersectionList.Create(
                new Intersection(-0.9899, a),
                new Intersection(-0.4899, b),
                new Intersection(0.4899, b),
                new Intersection(0.9899, a));

            var comps    = xs[2].Precompute(r, xs);
            var c        = w.GetRefractedColor(comps, 5);
            var expected = new Color(0, 0.99888, 0.04725);

            const double eps      = 0.0001;
            var          comparer = Color.GetEqualityComparer(eps);

            Assert.Equal(expected, c, comparer);
        }
Ejemplo n.º 4
0
        public void ShadeWithReflectiveTransparentMaterial()
        {
            var w = new DefaultWorld();
            var r = new Ray(
                Vector4.CreatePosition(0, 0, -3),
                Vector4.CreateDirection(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2));

            var floor = new Plane();

            floor.Transform                = Transform.Translate(0, -1, 0);
            floor.Material.Reflective      = 0.5;
            floor.Material.Transparency    = 0.5;
            floor.Material.RefractiveIndex = 1.5;

            var ball = new Sphere();

            ball.Transform        = Transform.Translate(0, -3.5, -0.5);
            ball.Material.Color   = new Color(1, 0, 0);
            ball.Material.Ambient = 0.5;

            w.Objects.Add(floor);
            w.Objects.Add(ball);

            var xs = IntersectionList.Create(
                new Intersection(Math.Sqrt(2), floor));

            var          comps    = xs[0].Precompute(r, xs);
            var          c        = w.Render(comps, 5);
            var          expected = new Color(0.93391, 0.69643, 0.69243);
            const double eps      = 0.00001;
            var          comparer = Color.GetEqualityComparer(eps);

            Assert.Equal(expected, c, comparer);
        }
Ejemplo n.º 5
0
        public void FindingN1AndN2AtVariousIntersections(int index, double n1, double n2)
        {
            var a = new GlassSphere()
            {
                Transform = Transform.Scale(2, 2, 2),
            };

            var b = new GlassSphere()
            {
                Transform = Transform.Translate(0, 0, -0.25),
            };

            var c = new GlassSphere()
            {
                Transform = Transform.Translate(0, 0, 25),
            };

            a.Material.RefractiveIndex = 1.5;
            b.Material.RefractiveIndex = 2.0;
            c.Material.RefractiveIndex = 2.5;

            var r = new Ray(Vector4.CreatePosition(0, 0, -4), Vector4.CreateDirection(0, 0, 1));
            var xs = IntersectionList.Create(
                new Intersection(2, a),
                new Intersection(2.75, b),
                new Intersection(3.25, c),
                new Intersection(4.75, b),
                new Intersection(5.25, c),
                new Intersection(6, a));

            var comps = xs[index].Precompute(r, xs);
            Assert.Equal(n1, comps.N1);
            Assert.Equal(n2, comps.N2);
        }
        public IntersectionList GetAllFromFile(string filePath, EdgePipeList edgePipes)
        {
            IntersectionList intersectionList = new IntersectionList();

            LoadAllFromXmlFileToList(filePath, edgePipes, ref intersectionList);

            return(intersectionList);
        }
        public void DropTest()
        {
            IntersectionList target = new IntersectionList();

            target.Drop();

            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Ejemplo n.º 8
0
        public void Intersect_should_intersect_with_both_spheres_when_looking_at_the_origin()
        {
            var world = World.CreateDefaultWorld();
            var ray   = new Ray(new Point(0, 0, -5), Vector.UnitZ);
            IntersectionList intersections = world.Intersect(ray);

            intersections.Ts.Should().HaveCount(4).And.ContainInOrder(4, 4.5, 5.5, 6);
        }
Ejemplo n.º 9
0
        public void LocalIntersect_should_miss_properly(double px, double py, double pz, double vx, double vy, double vz)
        {
            var cube = new Cube();
            var ray  = new Ray(new Point(px, py, pz), new Vector(vx, vy, vz));
            IntersectionList intersections = cube.LocalIntersect(ray);

            intersections.Should().BeEmpty();
        }
        public void Hit_should_return_the_smallest_t_when_all_intersections_have_positive_t()
        {
            var s    = new Sphere();
            var i1   = new Intersection(1, s);
            var i2   = new Intersection(2, s);
            var list = new IntersectionList(i1, i2);

            list.Hit.Should().Be(i1);
        }
        public void The_hit_should_be_preserved_when_calculating_the_intersection_state()
        {
            var hit           = new Intersection(1, _triangle, 0.45, 0.25);
            var ray           = new Ray(new Point(-0.2, 0.3, -2), Vector.UnitZ);
            var intersections = new IntersectionList(hit);
            var state         = IntersectionState.Create(hit, ray, intersections);

            state.Normal.Should().Be(new Vector(-0.5547, 0.83205, 0));
        }
        public void Hit_should_return_the_smallest_non_negative_t_when_some_intersections_have_negative_t()
        {
            var s    = new Sphere();
            var i1   = new Intersection(-1, s);
            var i2   = new Intersection(2, s);
            var list = new IntersectionList(i1, i2);

            list.Hit.Should().Be(i2);
        }
Ejemplo n.º 13
0
        //// ===========================================================================================================
        //// Methods
        //// ===========================================================================================================

        protected internal override IntersectionList LocalIntersect(Ray localRay)
        {
            double dx = localRay.Direction.X;
            double dz = localRay.Direction.Z;

            double a = (dx * dx) + (dz * dz);

            // Ray is parallel to the y axis.
            if (a.IsApproximatelyEqual(0))
            {
                var xs = new IntersectionList();
                IntersectCaps(localRay, xs);
                return(xs);
            }

            double ox = localRay.Origin.X;
            double oz = localRay.Origin.Z;

            double b            = (2 * ox * dx) + (2 * oz * dz);
            double c            = ((ox * ox) + (oz * oz)) - 1;
            double discriminant = (b * b) - (4 * a * c);

            // Ray does not intersect the cylinder.
            if (discriminant < 0)
            {
                return(IntersectionList.Empty);
            }

            double sqrtDiscriminant = Math.Sqrt(discriminant);
            double t0 = (-b - sqrtDiscriminant) / (2 * a);
            double t1 = (-b + sqrtDiscriminant) / (2 * a);

            if (t0 > t1)
            {
                double temp = t0;
                t0 = t1;
                t1 = temp;
            }

            var intersections = new IntersectionList();

            double y0 = localRay.Origin.Y + (t0 * localRay.Direction.Y);
            double y1 = localRay.Origin.Y + (t1 * localRay.Direction.Y);

            if (y0 > MinimumY && y0 < MaximumY)
            {
                intersections.Add((t0, this));
            }

            if (y1 > MinimumY && y1 < MaximumY)
            {
                intersections.Add((t1, this));
            }

            IntersectCaps(localRay, intersections);
            return(intersections);
        }
        public void Hit_should_return_null_when_all_intersections_have_negative_t()
        {
            var s    = new Sphere();
            var i1   = new Intersection(-2, s);
            var i2   = new Intersection(-1, s);
            var list = new IntersectionList(i1, i2);

            list.Hit.Should().BeNull();
        }
Ejemplo n.º 15
0
 public void HitWhenAllIntersectionsHaveNegativeT()
 {
     var s = new Sphere();
     var i1 = new Intersection(-2, s);
     var i2 = new Intersection(-1, s);
     var xs = IntersectionList.Create(i1, i2);
     var hit = xs.TryGetHit(out var i);
     Assert.False(hit);
 }
Ejemplo n.º 16
0
        //// ===========================================================================================================
        //// Methods
        //// ===========================================================================================================

        protected internal override IntersectionList LocalIntersect(Ray localRay)
        {
            var leftIntersections     = Left.Intersect(localRay);
            var rightIntersections    = Right.Intersect(localRay);
            var combinedIntersections = new IntersectionList(leftIntersections.Concat(rightIntersections));
            var filtered = FilterIntersections(combinedIntersections);

            return(filtered);
        }
Ejemplo n.º 17
0
 public void HitWhenSomeIntersectionsHaveNegativeT()
 {
     var s = new Sphere();
     var i1 = new Intersection(-1, s);
     var i2 = new Intersection(1, s);
     var xs = IntersectionList.Create(i1, i2);
     var hit = xs.TryGetHit(out var i);
     Assert.True(hit);
     Assert.Equal(i2, i);
 }
Ejemplo n.º 18
0
 public void CreateIntersectionList()
 {
     var s = new Sphere();
     var i1 = new Intersection(1, s);
     var i2 = new Intersection(2, s);
     var xs = IntersectionList.Create(i1, i2);
     Assert.Equal(2, xs.Count);
     Assert.Equal(1, xs[0].T);
     Assert.Equal(2, xs[1].T);
 }
        public void HitSomeIntersectionsNegativeT()
        {
            var sphere = new Sphere();
            var i1     = new Intersection(-1, sphere);
            var i2     = new Intersection(1, sphere);
            var list   = new IntersectionList(i1, i2);
            var i      = list.Hit();

            Assert.That(i, Is.EqualTo(i2));
        }
        public void HitAllIntersectionsNegativeT()
        {
            var sphere = new Sphere();
            var i1     = new Intersection(-2, sphere);
            var i2     = new Intersection(-1, sphere);
            var list   = new IntersectionList(i1, i2);
            var i      = list.Hit();

            Assert.That(i, Is.Null);
        }
        public void HitAllIntersectionsPositiveT()
        {
            var sphere = new Sphere();
            var i1     = new Intersection(1, sphere);
            var i2     = new Intersection(2, sphere);
            var list   = new IntersectionList(i1, i2);
            var i      = list.Hit();

            Assert.That(i, Is.EqualTo(i1));
        }
Ejemplo n.º 22
0
            public void Can_track_some_negative_hits()
            {
                var s  = new Sphere();
                var i1 = new Intersection(-1, s);
                var i2 = new Intersection(1, s);
                var xs = new IntersectionList(i1, i2);
                var i  = xs.Hit();

                Assert.Equal(i2, i);
            }
Ejemplo n.º 23
0
            public void Can_track_all_negative_hits()
            {
                var s  = new Sphere();
                var i1 = new Intersection(-2, s);
                var i2 = new Intersection(-1, s);
                var xs = new IntersectionList(i1, i2);
                var i  = xs.Hit();

                Assert.Equal(Intersection.Empty(), i);
            }
        public void Hit_should_return_the_lowest_non_negative_intersection()
        {
            var s    = new Sphere();
            var i1   = new Intersection(5, s);
            var i2   = new Intersection(7, s);
            var i3   = new Intersection(-3, s);
            var i4   = new Intersection(2, s);
            var list = new IntersectionList(i1, i2, i3, i4);

            list.Hit.Should().Be(i4);
        }
Ejemplo n.º 25
0
            public void Can_aggregate_intersections()
            {
                var s  = new Sphere();
                var i1 = new Intersection(1, s);
                var i2 = new Intersection(2, s);
                var xs = new IntersectionList(i1, i2);

                Assert.Equal(2, xs.Count);
                Assert.Equal(1, xs[0].T);
                Assert.Equal(2, xs[1].T);
            }
        public void AggregatingIntersections()
        {
            var sphere = new Sphere();
            var i1     = new Intersection(1, sphere);
            var i2     = new Intersection(2, sphere);
            var list   = new IntersectionList(i1, i2);

            Assert.That(list.Count, Is.EqualTo(2), "list count");
            Assert.That(list[0].Time, Is.EqualTo(1), "t1");
            Assert.That(list[1].Time, Is.EqualTo(2), "t2");
        }
Ejemplo n.º 27
0
 public void SchlickApproxWithSmallAngleAndN2GreaterThanN1()
 {
     var shape = new GlassSphere();
     var r = new Ray(Vector4.CreatePosition(0, 0.99, -2), Vector4.CreateDirection(0, 0, 1));
     var xs = IntersectionList.Create(
         new Intersection(1.8589, shape));
     var comps = xs[0].Precompute(r, xs);
     var reflectance = comps.SchlicksApproximation();
     const int prec = 5;
     Assert.Equal(0.48873, reflectance, prec);
 }
Ejemplo n.º 28
0
 public void HitIsAlwaysLowestNonNegativeIntersection()
 {
     var s = new Sphere();
     var i1 = new Intersection(5, s);
     var i2 = new Intersection(7, s);
     var i3 = new Intersection(-3, s);
     var i4 = new Intersection(2, s);
     var xs = IntersectionList.Create(i1, i2, i3, i4);
     var hit = xs.TryGetHit(out var i);
     Assert.True(hit);
     Assert.Equal(i4, i);
 }
Ejemplo n.º 29
0
            public void Can_acquire_nearest_hit()
            {
                var s  = new Sphere();
                var i1 = new Intersection(5, s);
                var i2 = new Intersection(7, s);
                var i3 = new Intersection(-3, s);
                var i4 = new Intersection(2, s);
                var xs = new IntersectionList(i1, i2, i3, i4);
                var i  = xs.Hit();

                Assert.Equal(i4, i);
            }
        public void HitAlwaysLowestNonNegativeIntersection()
        {
            var sphere = new Sphere();
            var i1     = new Intersection(5, sphere);
            var i2     = new Intersection(7, sphere);
            var i3     = new Intersection(-3, sphere);
            var i4     = new Intersection(2, sphere);
            var list   = new IntersectionList(i1, i2, i3, i4);
            var i      = list.Hit();

            Assert.That(i, Is.EqualTo(i4));
        }