Exemplo n.º 1
0
        public void ShadeHitIsGivenIntersectionInShadow()
        {
            var w = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(p.Point(0, 0, -10), RTF.Color.White)
                }
            };

            var s1 = new Sphere();

            w.Objects.Add(s1);

            var s2 = new Sphere(t.Translation(0, 0, 10));

            w.Objects.Add(s2);

            var r = new RTF.Ray(p.Point(0, 0, 5), p.Vector(0, 0, 1));
            var i = new RTF.Intersection(4, s2);

            var comps = RTF.Computation.PrepareComputations(i, r);
            var c     = w.ShadeHit(comps);

            var expected = new RTF.Color(0.1, 0.1, 0.1);

            Assert.Equal(expected, c);
        }
        public void IntersectionEncapsulatesTAndObject()
        {
            var s = new Sphere();
            var i = new RTF.Intersection(3.5, s);

            Assert.Equal(3.5, i.T);
            Assert.Equal(s, i.Object);
        }
        public void HitAllIntersectionNegativeT()
        {
            var s = new Sphere();
            var i1 = new RTF.Intersection(-2, s);
            var i2 = new RTF.Intersection(-1, s);
            var xs = RTF.Intersection.Intersections(i2, i1);

            var i = RTF.Intersection.Hit(xs);

            Assert.Null(i);
        }
        public void HitSomeIntersectionNegativeT()
        {
            var s = new Sphere();
            var i1 = new RTF.Intersection(-1, s);
            var i2 = new RTF.Intersection(1, s);
            var xs = RTF.Intersection.Intersections(i2, i1);

            RTF.Intersection i = RTF.Intersection.Hit(xs);

            Assert.Equal(i2, i);
        }
        public void HitAllIntersectionPositiveT()
        {
            var s = new Sphere();
            var i1 = new RTF.Intersection(1, s);
            var i2 = new RTF.Intersection(2, s);
            var xs = RTF.Intersection.Intersections(i2, i1);

            RTF.Intersection i = RTF.Intersection.Hit(xs);

            Assert.Equal(i1, i);
        }
Exemplo n.º 6
0
        public void HitWhenIntersectionOccursOutside()
        {
            var r = new RTF.Ray(
                RTF.PointType.Point(0, 0, -5),
                RTF.PointType.Vector(0, 0, 1));
            var shape = new Sphere();
            var i     = new RTF.Intersection(4, shape);
            var comps = RTF.Computation.PrepareComputations(i, r);

            Assert.False(comps.Inside);
        }
        public void HitAlwaysLowestNonNegativeIntersec()
        {
            var s = new Sphere();
            var i1 = new RTF.Intersection(5, s);
            var i2 = new RTF.Intersection(7, s);
            var i3 = new RTF.Intersection(-3, s);
            var i4 = new RTF.Intersection(2, s);
            var xs = RTF.Intersection.Intersections(i1, i2, i3, i4);
            RTF.Intersection i = RTF.Intersection.Hit(xs);

            Assert.Equal(i4, i);
        }
        public void AggregatingIntersections()
        {
            var s = new Sphere();
            var i1 = new RTF.Intersection(1, s);
            var i2 = new RTF.Intersection(2, s);

            var xs = RTF.Intersection.Intersections(i1, i2);

            Assert.Equal(2, xs.Length);
            Assert.Equal(1, xs[0].T);
            Assert.Equal(2, xs[1].T);
        }
Exemplo n.º 9
0
        public void TheHitShouldOffsetThePoint()
        {
            var r = new RTF.Ray(p.Point(0, 0, -5), p.Vector(0, 0, 1));

            var shape = new Sphere(t.Translation(0, 0, 1));
            var i     = new RTF.Intersection(5, shape);

            var comps = RTF.Computation.PrepareComputations(i, r);

            Assert.True(comps.OverPoint.Z < -EPSILON / 2);
            Assert.True(comps.Point.Z > comps.OverPoint.Z);
        }
Exemplo n.º 10
0
        public void HitWhenIntersectionOccursInside()
        {
            var r = new RTF.Ray(
                RTF.PointType.Point(0, 0, 0),
                RTF.PointType.Vector(0, 0, 1));
            var shape = new Sphere();
            var i     = new RTF.Intersection(1, shape);
            var comps = RTF.Computation.PrepareComputations(i, r);


            Assert.Equal(RTF.PointType.Point(0, 0, 1), comps.Point);
            Assert.Equal(RTF.PointType.Vector(0, 0, -1), comps.EyeV);
            Assert.True(comps.Inside);
            Assert.Equal(RTF.PointType.Vector(0, 0, -1), comps.NormalV);
        }
Exemplo n.º 11
0
        public void PrecomputingStateIntersection()
        {
            var r = new RTF.Ray(
                RTF.PointType.Point(0, 0, -5),
                RTF.PointType.Vector(0, 0, 1));
            var shape = new Sphere();
            var i     = new RTF.Intersection(4, shape);
            var comps = RTF.Computation.PrepareComputations(i, r);

            Assert.Equal(i.T, comps.T);
            Assert.Equal(i.Object, comps.Object);
            Assert.Equal(RTF.PointType.Point(0, 0, -1), comps.Point);
            Assert.Equal(RTF.PointType.Vector(0, 0, -1), comps.EyeV);
            Assert.Equal(RTF.PointType.Vector(0, 0, -1), comps.NormalV);
        }
Exemplo n.º 12
0
        public void ShadingIntersection()
        {
            var w = RTF.World.Default();
            var r = new RTF.Ray(
                RTF.PointType.Point(0, 0, -5),
                RTF.PointType.Vector(0, 0, 1));
            var shape = w.Objects[0];
            var i     = new RTF.Intersection(4, shape);

            var comps = RTF.Computation.PrepareComputations(i, r);
            var c     = w.ShadeHit(comps);
            var exp   = new RTF.Color(0.38066, 0.47583, 0.2855);

            //var exp = new RTF.Color(0.50066, 0.57583, 0.42550);

            CustomAssert.Equal(exp, c, 5);
        }
Exemplo n.º 13
0
        public void ShadingIntersectionFromInside()
        {
            var w = RTF.World.Default();

            w.Lights = new System.Collections.Generic.List <RTF.Light>()
            {
                new RTF.Light(
                    RTF.PointType.Point(0, 0.25, 0),
                    RTF.Color.White)
            };
            var r = new RTF.Ray(
                RTF.PointType.Point(0, 0, 0),
                RTF.PointType.Vector(0, 0, 1));
            var shape = w.Objects[1];

            var i     = new RTF.Intersection(0.5, shape);
            var comps = RTF.Computation.PrepareComputations(i, r);
            var c     = w.ShadeHit(comps);
            var exp   = new RTF.Color(0.90498, 0.90498, 0.90498);

            CustomAssert.Equal(exp, c, 5);
        }