Пример #1
0
        public void DefaultMinAndMaxCylinder()
        {
            var cyl = new shape.Cylinder();

            Assert.True(double.IsNegativeInfinity(cyl.Minimum));
            Assert.True(double.IsPositiveInfinity(cyl.Maximum));
        }
Пример #2
0
        public void UnboundedCylinderBoundingBox()
        {
            var s   = new shape.Cylinder();
            var box = s.Bounds();

            Assert.Equal(pt.Point(-1, double.NegativeInfinity, -1), box.Minimum);
            Assert.Equal(pt.Point(1, double.PositiveInfinity, 1), box.Maximum);
        }
Пример #3
0
        public void NormalOnCylinder(double pX, double pY, double pZ, double vX, double vY, double vZ)
        {
            var point  = pt.Point(pX, pY, pZ);
            var normal = pt.Vector(vX, vY, vZ);
            var cyl    = new shape.Cylinder();
            var n      = cyl.NormalAt(point);

            Assert.Equal(normal, n);
        }
Пример #4
0
        public void RayMissCylinder(double pX, double pY, double pZ, double vX, double vY, double vZ)
        {
            var origin    = pt.Point(pX, pY, pZ);
            var direction = pt.Vector(vX, vY, vZ).Normalize();
            var cyl       = new shape.Cylinder();
            var ray       = new Ray(origin, direction);
            var xs        = cyl.Intersect(ray);

            Assert.Empty(xs);
        }
Пример #5
0
        public void BoundedCylinderBoundingBox()
        {
            var s = new shape.Cylinder()
            {
                Minimum = -5,
                Maximum = 3
            };

            var box = s.Bounds();

            Assert.Equal(pt.Point(-1, -5, -1), box.Minimum);
            Assert.Equal(pt.Point(1, 3, 1), box.Maximum);
        }
Пример #6
0
        public void RayStrikeCylinder(double pX, double pY, double pZ, double vX, double vY, double vZ, double t0, double t1)
        {
            var cyl = new shape.Cylinder();

            var origin    = pt.Point(pX, pY, pZ);
            var direction = pt.Vector(vX, vY, vZ).Normalize();

            var ray = new Ray(origin, direction);
            var xs  = cyl.Intersect(ray);

            Assert.Equal(2, xs.Length);
            Assert.Equal(t0, xs[0].T, 5);
            Assert.Equal(t1, xs[1].T, 5);
        }
Пример #7
0
        public void NormalOnCylinderEndCap(double pX, double pY, double pZ, double vX, double vY, double vZ)
        {
            var point  = pt.Point(pX, pY, pZ);
            var normal = pt.Vector(vX, vY, vZ);
            var cyl    = new shape.Cylinder()
            {
                Minimum = 1,
                Maximum = 2,
                Closed  = true
            };
            var n = cyl.NormalAt(point);

            Assert.Equal(normal, n);
        }
Пример #8
0
        public void IntersectingConstrainedCylinder(double pX, double pY, double pZ, double vX, double vY, double vZ, int count)
        {
            var point     = pt.Point(pX, pY, pZ);
            var direction = pt.Vector(vX, vY, vZ).Normalize();

            var cyl = new shape.Cylinder
            {
                Minimum = 1,
                Maximum = 2
            };

            var r  = new Ray(point, direction);
            var xs = cyl.Intersect(r);

            Assert.Equal(count, xs.Length);
        }
Пример #9
0
        /*
         *  - add: camera
         *    width: 400
         *    height: 400
         *    field-of-view: 0.5
         *    from: [0, 0, -10]
         *    to: [0, 0, 0]
         *    up: [0, 1, 0]
         *
         *  - add: light
         *    at: [-10, 10, -10]
         *    intensity: [1, 1, 1]
         *
         *  - add: cylinder
         *    min: 0
         *    max: 1
         *    transform:
         *      - [translate, 0, -0.5, 0]
         *      - [scale, 1, 3.1415, 1]
         *    material:
         *      pattern:
         *        type: map
         *        mapping: cylindrical
         *        uv_pattern:
         *          type: checkers
         *          width: 16
         *          height: 8
         *          colors:
         *            - [0, 0.5, 0]
         *            - [1, 1, 1]
         *      ambient: 0.1
         *      specular: 0.6
         *      shininess: 15
         *      diffuse: 0.8
         *
         */
        private void CheckersOnCylinder_Click(object sender, RoutedEventArgs e)
        {
            var camera = new RTF.Camera(400, 400, 0.5)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 0, -10),
                    point.Point(0, 0, 0),
                    point.Vector(0, 1, 0))
            };

            var light = new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White);

            var checker  = new UV.Checker(16, 8, new RTF.Color(0, 0.5, 0), new RTF.Color(1, 1, 1));
            var pattern  = new patterns.TextureMap(UV.Pattern.CylindricalMap, checker);
            var cylinder = new shapes.Cylinder()
            {
                Minimum   = 0,
                Maximum   = 1,
                Transform = transform.Translation(0, -0.5, 0) * transform.Scaling(1, Math.PI, 1),
                Material  = new RTF.Material()
                {
                    Pattern   = pattern,
                    Ambient   = 0.1,
                    Specular  = 0.6,
                    Shininess = 15,
                    Diffuse   = 0.8
                }
            };

            var world = new RTF.World();

            world.Lights.Add(light);
            world.Objects.Add(cylinder);

            var watch  = System.Diagnostics.Stopwatch.StartNew();
            var canvas = RTF.Canvas.Render(camera, world);

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            canvas.SaveAsPPMFile(FolderPath.Text + $"\\TextureMap_2DCheckersCylinder[{elapsedMs}ms].ppm");
        }
Пример #10
0
        public void GroupHasBoundingBoxContainsItsChildren()
        {
            var s = new shape.Sphere()
            {
                Transform = transform.Translation(2, 5, -3) * transform.Scaling(2, 2, 2)
            };
            var c = new shape.Cylinder()
            {
                Minimum   = -2,
                Maximum   = 2,
                Transform = transform.Translation(-4, -1, 4) * transform.Scaling(0.5, 1, 0.5)
            };
            var shape = new shape.Group();

            shape.Add(s);
            shape.Add(c);

            var box = shape.Bounds();

            Assert.Equal(pt.Point(-4.5, -3, -5), box.Minimum);
            Assert.Equal(pt.Point(4, 7, 4.5), box.Maximum);
        }
Пример #11
0
        private List <Intersection> IntersectCaps(Cylinder cyl, Ray ray)
        {
            var xs = new List <Intersection>();

            if (cyl.Closed == false || Math.Abs(ray.Direction.Y) <= EPSILON)
            {
                return(xs);
            }

            var t = (cyl.Minimum - ray.Origin.Y) / ray.Direction.Y;

            if (CheckCap(ray, t))
            {
                xs.Add(new Intersection(t, cyl));
            }

            t = (cyl.Maximum - ray.Origin.Y) / ray.Direction.Y;
            if (CheckCap(ray, t))
            {
                xs.Add(new Intersection(t, cyl));
            }

            return(xs);
        }
Пример #12
0
        public void DefaultClosedValueCylinder()
        {
            var cyl = new shape.Cylinder();

            Assert.False(cyl.Closed);
        }
Пример #13
0
        private void Earth_Click(object sender, RoutedEventArgs e)
        {
            var file = new List <string>();

            try
            {
                using (StreamReader sr = new StreamReader(@".\Files\EarthMap.ppm"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        file.Add(line);
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                throw ex;
            }

            var canvas  = RTF.Canvas.CanvasFromPPM(file);
            var pattern = new UV.Image(canvas);

            var light = new RTF.Light(point.Point(-100, 100, -100), RTF.Color.White);

            var camera = new RTF.Camera(800, 400, 0.8)
            {
                Transform = transform.ViewTransform(
                    point.Point(1, 2, -10),
                    point.Point(0, 1.1, 0),
                    point.Vector(0, 1, 0))
            };

            var cylinder = new shapes.Cylinder()
            {
                Minimum  = 0,
                Maximum  = 0.1,
                Closed   = true,
                Material = new RTF.Material()
                {
                    Color      = RTF.Color.White,
                    Diffuse    = 0.2,
                    Specular   = 0,
                    Ambient    = 0,
                    Reflective = 0.1
                }
            };

            var plane = new shapes.Plane()
            {
                Material = new RTF.Material()
                {
                    Color      = RTF.Color.White,
                    Diffuse    = 0.1,
                    Specular   = 0,
                    Ambient    = 0,
                    Reflective = 0.4
                }
            };

            var sphere = new shapes.Sphere()
            {
                Transform = transform.Translation(0, 1.1, 0) * transform.RotationY(1.9),
                Material  = new RTF.Material()
                {
                    Pattern   = new patterns.TextureMap(UV.Pattern.SphericalMap, pattern),
                    Diffuse   = 0.9,
                    Specular  = 0.1,
                    Shininess = 10,
                    Ambient   = 0.1
                }
            };

            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    light
                },
                Objects = new List <shapes.Shape>()
                {
                    cylinder, plane, sphere
                }
            };

            var watch       = System.Diagnostics.Stopwatch.StartNew();
            var finalCanvas = RTF.Canvas.Render(camera, world);

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            finalCanvas.SaveAsPPMFile(FolderPath.Text + $"\\TextureMap_Earth[{elapsedMs}ms].ppm");
        }