public RTF.Canvas CreateWorld(List <shapes.Shape> shapes)
        {
            //var ceilling = new shapes.Plane()
            //{
            //    Material = new RTF.Material()
            //    {
            //        Color = new RTF.Color(1, 0.9, 0.9),
            //        Specular = 0
            //    }
            //};

            //shapes.Add(ceilling);

            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White)
                },
                Objects = shapes
            };

            var camera = new RTF.Camera(200, 100, Math.PI / 3)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 6, -20),
                    point.Point(0, 3, 0),
                    point.Vector(0, 1, 0))
            };

            return(RTF.Canvas.Render(camera, world));
        }
        public void ConstructingRayThroughCenterCanvas()
        {
            var c = new RTF.Camera(201, 101, Math.PI / 2);
            var r = c.RayForPixel(100, 50);

            Assert.Equal(RTF.PointType.Point(0, 0, 0), r.Origin);
            CustomAssert.Equal(RTF.PointType.Vector(0, 0, -1), r.Direction, 5);
        }
        public void ConstructingRayThroughCornerCanvas()
        {
            var c = new RTF.Camera(201, 101, Math.PI / 2);
            var r = c.RayForPixel(0, 0);

            Assert.Equal(RTF.PointType.Point(0, 0, 0), r.Origin);
            CustomAssert.Equal(
                RTF.PointType.Vector(0.66519, 0.33259, -0.66851),
                r.Direction,
                5);
        }
        public void ConstructionCamera()
        {
            var hsize         = 160;
            var vsize         = 120;
            var field_of_view = Math.PI / 2;

            RTF.Camera c = new RTF.Camera(hsize, vsize, field_of_view);

            Assert.Equal(hsize, c.HorizontalSize);
            Assert.Equal(vsize, c.VerticalSize);
            Assert.Equal(field_of_view, c.FieldOfView);
            Assert.Equal(RTF.Matrix.GetIdentity(), c.Transform);
        }
        public RTF.Canvas CreateCircle()
        {
            var ceilling = new RTF.Shapes.Plane()
            {
                Material = new RTF.Material()
                {
                    Color    = new RTF.Color(1, 0.9, 0.9),
                    Specular = 0
                }
            };

            var middle = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(-0.5, 1, 0.5),
                Material  = new RTF.Material(RTF.Color.Purple, 0.7, 0.3)
            };
            var right = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(1.5, 0.5, -0.5) * transform.Scaling(0.5, 0.5, 0.5),
                Material  = new RTF.Material(RTF.Color.Lime, 0.7, 0.3)
            };
            var left = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(-1.5, 0.33, -0.75) * transform.Scaling(0.33, 0.33, 0.33),
                Material  = new RTF.Material(RTF.Color.Cyan, 0.7, 0.3)
            };

            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White)
                },
                Objects = new List <RTF.Shapes.Shape>()
                {
                    ceilling, right, middle, right, left
                }
            };

            var camera = new RTF.Camera(200, 100, Math.PI / 3)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 1.5, -5),
                    point.Point(0, 1, 0),
                    point.Vector(0, 1, 0))
            };

            return(RTF.Canvas.Render(camera, world));
        }
        public void ConstructingRayWhenCameraTransformed()
        {
            var c = new RTF.Camera(201, 101, Math.PI / 2)
            {
                Transform = RTH.Transformations.RotationY(Math.PI / 4)
                            * RTH.Transformations.Translation(0, -2, 5)
            };
            var r = c.RayForPixel(100, 50);

            Assert.Equal(RTF.PointType.Point(0, 2, -5), r.Origin);
            CustomAssert.Equal(
                RTF.PointType.Vector(Math.Sqrt(2) / 2, 0, -Math.Sqrt(2) / 2),
                r.Direction,
                5);
        }
        public RTF.Canvas CreatingPerturbedSphere()
        {
            var p_ceiling = new RTF.Patterns.Checker(RTF.Color.Black, RTF.Color.White);

            var ceilling = new RTF.Shapes.Plane()
            {
                Material = new RTF.Material()
                {
                    Pattern  = new RTF.Patterns.Perturbed(p_ceiling),
                    Color    = RTF.Color.Black,
                    Specular = 0
                }
            };

            var p_sphere = new RTF.Patterns.Ring(RTF.Color.Purple, RTF.Color.Pink);
            var middle   = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(-0.5, 1, 0.5),
                Material  = new RTF.Material()
                {
                    Pattern  = new RTF.Patterns.Perturbed(p_sphere),
                    Color    = RTF.Color.Black,
                    Specular = 0
                }
            };

            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White)
                },
                Objects = new List <RTF.Shapes.Shape>()
                {
                    ceilling, middle
                }
            };

            var camera = new RTF.Camera(400, 200, Math.PI / 3)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 1.5, -5),
                    point.Point(0, 1, 0),
                    point.Vector(0, 1, 0))
            };

            return(RTF.Canvas.Render(camera, world));
        }
Exemple #8
0
        public RTF.Canvas CreateWorld()
        {
            var ceilling = new RTF.Shapes.Plane()
            {
                Material = new RTF.Material()
                {
                    Color    = new RTF.Color(1, 0.9, 0.9),
                    Specular = 0
                }
            };

            var middle = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(-0.5, 1, 0.5),
                Material  = new RTF.Material()
                {
                    Color        = RTF.Color.Green,
                    Diffuse      = 0.1,
                    Specular     = 1,
                    Transparency = 1,
                    Shininess    = 300,
                    Reflective   = 0.9
                }
            };

            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White)
                },
                Objects = new List <RTF.Shapes.Shape>()
                {
                    ceilling, middle
                }
            };

            var camera = new RTF.Camera(200, 100, Math.PI / 3)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 1.5, -5),
                    point.Point(0, 1, 0),
                    point.Vector(0, 1, 0))
            };

            return(RTF.Canvas.Render(camera, world));
        }
        public void RenderingWorldWithCamera()
        {
            var w = RTF.World.Default();
            var c = new RTF.Camera(11, 11, Math.PI / 2);

            var from = RTF.PointType.Point(0, 0, -5);
            var to   = RTF.PointType.Point(0, 0, 0);
            var up   = RTF.PointType.Vector(0, 1, 0);

            c.Transform = RTH.Transformations.ViewTransform(from, to, up);

            RTF.Canvas image = RTF.Canvas.Render(c, w);

            var exp = new RTF.Color(0.38066, 0.47583, 0.2855);

            CustomAssert.Equal(exp, image.PixelAt(5, 5), 5);
        }
        /*
         *  - 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");
        }
        /*
         *- add: camera
         *  width: 400
         *  height: 400
         *  field-of-view: 0.5
         *  from: [0, 0, -5]
         *  to: [0, 0, 0]
         *  up: [0, 1, 0]
         *
         * - add: light
         *  at: [-10, 10, -10]
         *  intensity: [1, 1, 1]
         *
         * - add: sphere
         *  material:
         *  pattern:
         *      type: map
         *      mapping: spherical
         *      uv_pattern:
         *          type: checkers
         *          width: 20
         *          height: 10
         *          colors:
         *              - [0, 0.5, 0]
         *              - [1, 1, 1]
         *  ambient: 0.1
         *  specular: 0.4
         *  shininess: 10
         *  diffuse: 0.6
         */
        private void CheckersOnSphere_Click(object sender, RoutedEventArgs e)
        {
            var camera = new RTF.Camera(400, 400, 0.5)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 0, -5),
                    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(20, 10, new RTF.Color(0, 0.5, 0), new RTF.Color(1, 1, 1));
            var pattern = new patterns.TextureMap(UV.Pattern.SphericalMap, checker);
            var sphere  = new shapes.Sphere()
            {
                Material = new RTF.Material()
                {
                    Pattern   = pattern,
                    Ambient   = 0.1,
                    Specular  = 0.4,
                    Shininess = 10,
                    Diffuse   = 0.6
                }
            };

            var world = new RTF.World();

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

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

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

            canvas.SaveAsPPMFile(FolderPath.Text + $"\\TextureMap_2DCheckers3DSphere[{elapsedMs}ms].ppm");
        }
        /*
         * - add: camera
         *    width: 400
         *    height: 400
         *    field-of-view: 0.5
         *    from: [1, 2, -5]
         *    to: [0, 0, 0]
         *    up: [0, 1, 0]
         *
         *  - add: light
         *    at: [-10, 10, -10]
         *    intensity: [1, 1, 1]
         *
         *  - add: plane
         *    material:
         *      pattern:
         *        type: map
         *        mapping: planar
         *        uv_pattern:
         *          type: align_check
         *          colors:
         *            main: [1, 1, 1] # white
         *            ul: [1, 0, 0]   # red
         *            ur: [1, 1, 0]   # yellow
         *            bl: [0, 1, 0]   # green
         *            br: [0, 1, 1]   # cyan
         *      ambient: 0.1
         *      diffuse: 0.8
         */
        private void AlignCheck_Click(object sender, RoutedEventArgs e)
        {
            var camera = new RTF.Camera(400, 400, 0.5)
            {
                Transform = transform.ViewTransform(
                    point.Point(1, 2, -5),
                    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.AlignCheck(RTF.Color.White, RTF.Color.Red, RTF.Color.Yellow, RTF.Color.Lime, RTF.Color.Cyan);
            var pattern = new patterns.TextureMap(UV.Pattern.PlanarMap, checker);
            var plane   = new shapes.Plane()
            {
                Material = new RTF.Material()
                {
                    Pattern = pattern,
                    Ambient = 0.1,
                    Diffuse = 0.8
                }
            };

            var world = new RTF.World();

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

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

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

            canvas.SaveAsPPMFile(FolderPath.Text + $"\\TextureMap_AlignCheck[{elapsedMs}ms].ppm");
        }
        public RTF.Canvas CreateCeiling(RTF.Shapes.Shape ceilling)
        {
            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White)
                },
                Objects = new List <RTF.Shapes.Shape>()
                {
                    ceilling
                }
            };

            var camera = new RTF.Camera(400, 200, Math.PI / 3)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 1.5, -5),
                    point.Point(0, 1, 0),
                    point.Vector(0, 1, 0))
            };

            return(RTF.Canvas.Render(camera, world));
        }
Exemple #14
0
        public void PixelSizeHorizontalCanvas()
        {
            RTF.Camera c = new RTF.Camera(200, 125, Math.PI / 2);

            Assert.Equal(0.01, c.PixelSize, 2);
        }
Exemple #15
0
        public RTF.Canvas CreateCircle()
        {
            var floor = new shapes.Sphere()
            {
                Transform = transform.Scaling(10, 0.01, 10),
                Material  = new RTF.Material()
                {
                    Color    = new RTF.Color(1, 0.9, 0.9),
                    Specular = 0
                }
            };

            var leftWall = new shapes.Sphere()
            {
                Transform = transform.Translation(0, 0, 5)
                            * transform.RotationY(-Math.PI / 4)
                            * transform.RotationX(Math.PI / 2)
                            * transform.Scaling(10, 0.01, 10),
                Material = floor.Material
            };

            var rightWall = new shapes.Sphere()
            {
                Transform = transform.Translation(0, 0, 5)
                            * transform.RotationY(Math.PI / 4)
                            * transform.RotationX(Math.PI / 2)
                            * transform.Scaling(10, 0.01, 10),
                Material = floor.Material
            };

            var middle = new shapes.Sphere()
            {
                Transform = transform.Translation(-0.5, 1, 0.5),
                Material  = new RTF.Material(new RTF.Color(0.1, 1, 0.5), 0.7, 0.3)
            };

            var right = new shapes.Sphere()
            {
                Transform = transform.Translation(1.5, 0.5, -0.5) * transform.Scaling(0.5, 0.5, 0.5),
                Material  = new RTF.Material(new RTF.Color(0.5, 1, 0.1), 0.7, 0.3)
            };

            var left = new shapes.Sphere()
            {
                Transform = transform.Translation(-1.5, 0.33, -0.75) * transform.Scaling(0.33, 0.33, 0.33),
                Material  = new RTF.Material(new RTF.Color(1, 0.8, 0.1), 0.7, 0.3)
            };

            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White)
                },
                Objects = new List <shapes.Shape>()
                {
                    floor, leftWall, rightWall, right, middle, right, left
                }
            };

            var camera = new RTF.Camera(100, 50, Math.PI / 3)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 1.5, -5),
                    point.Point(0, 1, 0),
                    point.Vector(0, 1, 0))
            };

            return(RTF.Canvas.Render(camera, world));
        }
        public RTF.Canvas CreateWorld()
        {
            var camera = new RTF.Camera(100, 100, 0.785)
            {
                Transform = transform.ViewTransform(
                    point.Point(-6, 6, -10),
                    point.Point(6, 0, 6),
                    point.Vector(-0.45, 1, 0))
            };

            var light1 = new RTF.Light(point.Point(50, 100, -50), RTF.Color.White);
            var light2 = new RTF.Light(point.Point(-400, 50, -10), RTF.Color.White);

            var whiteMaterial = new RTF.Material()
            {
                Color = RTF.Color.White,
                Diffuse = 0.7,
                Ambient = 0.1,
                Specular = 0,
                Reflective = 0.1
            };
            var blueMaterial = new RTF.Material()
            {
                Color = new RTF.Color(0.537, 0.831, 0.914),
                Diffuse = 0.7,
                Ambient = 0.1,
                Specular = 0,
                Reflective = 0.1
            };
            var redMaterial = new RTF.Material()
            {
                Color = new RTF.Color(0.941, 0.322, 0.388),
                Diffuse = 0.7,
                Ambient = 0.1,
                Specular = 0,
                Reflective = 0.1
            };
            var purpleMaterial = new RTF.Material()
            {
                Color = new RTF.Color(0.373, 0.404, 0.550),
                Diffuse = 0.7,
                Ambient = 0.1,
                Specular = 0,
                Reflective = 0.1
            };

            var standardTransform = transform.Translation(1, -1, 1) * transform.Scaling(0.5, 0.5, 0.5);
            var largeObject = standardTransform * transform.Scaling(3.5, 3.5, 3.5);
            var mediumObject = standardTransform * transform.Scaling(3, 3, 3);
            var smallObject = standardTransform * transform.Scaling(2, 2, 2);

            var whitebackdrop = new shapes.Plane()
            {
                Material = new RTF.Material()
                {
                    Color = RTF.Color.White,
                    Ambient = 1,
                    Diffuse = 0,
                    Specular = 0
                },
                Transform = transform.RotationX(Math.PI / 2) * transform.Translation(0, 0, 500)
            };

            var group = new shapes.Group(
                new List<shapes.Shape>()
                {
                    new shapes.Sphere()
                    {
                        Material = new RTF.Material()
                        {
                            Color = purpleMaterial.Color,
                            Diffuse = 0.2,
                            Ambient = 0,
                            Specular = 1,
                            Shininess = 200,
                            Reflective = 0.7,
                            Transparency = 0.7,
                            RefractiveIndex = 1.5
                        },
                        Transform = largeObject
                    },
                    new shapes.Cube(whiteMaterial, mediumObject * transform.Translation(4, 0, 0)),
                    new shapes.Cube(blueMaterial, largeObject * transform.Translation(8.5, 1.5, -0.5)),
                    new shapes.Cube(redMaterial, largeObject * transform.Translation(0, 0, 4)),
                    new shapes.Cube(whiteMaterial, smallObject * transform.Translation(4, 0, 4)),
                    new shapes.Cube(purpleMaterial, mediumObject * transform.Translation(7.5, 0.5, 4)),
                    new shapes.Cube(whiteMaterial, mediumObject * transform.Translation(-0.25, 0.25, 8)),
                    new shapes.Cube(blueMaterial,  largeObject * transform.Translation(4, 1, 7.5)),
                    new shapes.Cube(redMaterial,  mediumObject * transform.Translation(10, 2, 7.5)),
                    new shapes.Cube(whiteMaterial,  smallObject * transform.Translation(8, 2, 12)),
                    new shapes.Cube(whiteMaterial,  smallObject * transform.Translation(20, 1, 9)),
                    new shapes.Cube(blueMaterial,  largeObject * transform.Translation(-0.5, -5, 0.25)),
                    new shapes.Cube(redMaterial,  largeObject * transform.Translation(4, -4, 0)),
                    new shapes.Cube(whiteMaterial,  largeObject * transform.Translation(8.5, -4, 0)),
                    new shapes.Cube(whiteMaterial,  largeObject * transform.Translation(0, -4, 4)),
                    new shapes.Cube(purpleMaterial,  largeObject * transform.Translation(-0.5, -4.5, 8)),
                    new shapes.Cube(whiteMaterial,  largeObject * transform.Translation(0, -8, 4)),
                    new shapes.Cube(whiteMaterial,  largeObject * transform.Translation(-0.5, -8.5, 8))
                }
            );


            var world = new RTF.World()
            {
                Lights = new List<RTF.Light>() { light1, light2 },

                Objects = new List<shapes.Shape>()
                {
                    group, whitebackdrop
                }
            };

            return RTF.Canvas.Render(camera, world);
        }
        /*
         * - add: camera
         *    width: 800
         *    height: 400
         *    field-of-view: 0.8
         *    from: [0, 0, -20]
         *    to: [0, 0, 0]
         *    up: [0, 1, 0]
         *
         *  - add: light
         *    at: [0, 100, -100]
         *    intensity: [0.25, 0.25, 0.25]
         *  - add: light
         *    at: [0, -100, -100]
         *    intensity: [0.25, 0.25, 0.25]
         *  - add: light
         *    at: [-100, 0, -100]
         *    intensity: [0.25, 0.25, 0.25]
         *  - add: light
         *    at: [100, 0, -100]
         *    intensity: [0.25, 0.25, 0.25]
         *
         *  - define: MappedCube
         *    value:
         *      add: cube
         *      material:
         *        pattern:
         *          type: map
         *          mapping: cube
         *          left:
         *            type: align_check
         *            colors:
         *              main: [1, 1, 0] # yellow
         *              ul: [0, 1, 1]   # cyan
         *              ur: [1, 0, 0]   # red
         *              bl: [0, 0, 1]   # blue
         *              br: [1, 0.5, 0] # brown
         *          front:
         *            type: align_check
         *            colors:
         *              main: [0, 1, 1] # cyan
         *              ul: [1, 0, 0]   # red
         *              ur: [1, 1, 0]   # yellow
         *              bl: [1, 0.5, 0] # brown
         *              br: [0, 1, 0]   # green
         *          right:
         *            type: align_check
         *            colors:
         *              main: [1, 0, 0] # red
         *              ul: [1, 1, 0]   # yellow
         *              ur: [1, 0, 1]   # purple
         *              bl: [0, 1, 0]   # green
         *              br: [1, 1, 1]   # white
         *          back:
         *            type: align_check
         *            colors:
         *              main: [0, 1, 0] # green
         *              ul: [1, 0, 1]   # purple
         *              ur: [0, 1, 1]   # cyan
         *              bl: [1, 1, 1]   # white
         *              br: [0, 0, 1]   # blue
         *          up:
         *            type: align_check
         *            colors:
         *              main: [1, 0.5, 0] # brown
         *              ul: [0, 1, 1]   # cyan
         *              ur: [1, 0, 1]   # purple
         *              bl: [1, 0, 0]   # red
         *              br: [1, 1, 0]   # yellow
         *          down:
         *            type: align_check
         *            colors:
         *              main: [1, 0, 1] # purple
         *              ul: [1, 0.5, 0] # brown
         *              ur: [0, 1, 0]   # green
         *              bl: [0, 0, 1]   # blue
         *              br: [1, 1, 1]   # white
         *        ambient: 0.2
         *        specular: 0
         *        diffuse: 0.8
         *
         *  - add: MappedCube
         *    transform:
         *      - [rotate-y, 0.7854]
         *      - [rotate-x, 0.7854]
         *      - [translate, -6, 2, 0]
         *
         *  - add: MappedCube
         *    transform:
         *      - [rotate-y, 2.3562]
         *      - [rotate-x, 0.7854]
         *      - [translate, -2, 2, 0]
         *
         *  - add: MappedCube
         *    transform:
         *      - [rotate-y, 3.927]
         *      - [rotate-x, 0.7854]
         *      - [translate, 2, 2, 0]
         *
         *  - add: MappedCube
         *    transform:
         *      - [rotate-y, 5.4978]
         *      - [rotate-x, 0.7854]
         *      - [translate, 6, 2, 0]
         *
         *  - add: MappedCube
         *    transform:
         *      - [rotate-y, 0.7854]
         *      - [rotate-x, -0.7854]
         *      - [translate, -6, -2, 0]
         *
         *  - add: MappedCube
         *    transform:
         *      - [rotate-y, 2.3562]
         *      - [rotate-x, -0.7854]
         *      - [translate, -2, -2, 0]
         *
         *  - add: MappedCube
         *    transform:
         *      - [rotate-y, 3.927]
         *      - [rotate-x, -0.7854]
         *      - [translate, 2, -2, 0]
         *
         *  - add: MappedCube
         *    transform:
         *      - [rotate-y, 5.4978]
         *      - [rotate-x, -0.7854]
         *      - [translate, 6, -2, 0]
         */
        private void CubeAlignCheck_Click(object sender, RoutedEventArgs e)
        {
            var camera = new RTF.Camera(800, 400, 0.8)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 0, -20),
                    point.Point(0, 0, 0),
                    point.Vector(0, 1, 0))
            };

            var light1 = new RTF.Light(point.Point(0, 100, -100), new RTF.Color(0.25, 0.25, 0.25));
            var light2 = new RTF.Light(point.Point(0, -100, -100), new RTF.Color(0.25, 0.25, 0.25));
            var light3 = new RTF.Light(point.Point(-100, 0, -100), new RTF.Color(0.25, 0.25, 0.25));
            var light4 = new RTF.Light(point.Point(100, 0, -100), new RTF.Color(0.25, 0.25, 0.25));

            var material = new RTF.Material()
            {
                Pattern = new UV.Cube(
                    new UV.AlignCheck(RTF.Color.Yellow, RTF.Color.Cyan, RTF.Color.Red, RTF.Color.Blue, RTF.Color.Brown),
                    new UV.AlignCheck(RTF.Color.Cyan, RTF.Color.Red, RTF.Color.Yellow, RTF.Color.Brown, RTF.Color.Green),
                    new UV.AlignCheck(RTF.Color.Red, RTF.Color.Yellow, RTF.Color.Purple, RTF.Color.Green, RTF.Color.White),
                    new UV.AlignCheck(RTF.Color.Green, RTF.Color.Purple, RTF.Color.Cyan, RTF.Color.White, RTF.Color.Blue),
                    new UV.AlignCheck(RTF.Color.Brown, RTF.Color.Cyan, RTF.Color.Purple, RTF.Color.Red, RTF.Color.Yellow),
                    new UV.AlignCheck(RTF.Color.Purple, RTF.Color.Brown, RTF.Color.Green, RTF.Color.Blue, RTF.Color.White)
                    ),
                Ambient  = 0.2,
                Specular = 0,
                Diffuse  = 0.8
            };

            var mappedCube1 = new shapes.Cube
                                  (material, transform.Translation(-6, 2, 0) * transform.RotationX(0.7854) * transform.RotationY(0.7854));
            var mappedCube2 = new shapes.Cube
                                  (material, transform.Translation(-2, 2, 0) * transform.RotationX(0.7854) * transform.RotationY(2.3562));
            var mappedCube3 = new shapes.Cube
                                  (material, transform.Translation(2, 2, 0) * transform.RotationX(0.7854) * transform.RotationY(3.927));
            var mappedCube4 = new shapes.Cube
                                  (material, transform.Translation(6, 2, 0) * transform.RotationX(0.7854) * transform.RotationY(5.4978));
            var mappedCube5 = new shapes.Cube
                                  (material, transform.Translation(-6, -2, 0) * transform.RotationX(-0.7854) * transform.RotationY(0.7854));
            var mappedCube6 = new shapes.Cube
                                  (material, transform.Translation(-2, -2, 0) * transform.RotationX(-0.7854) * transform.RotationY(2.3562));
            var mappedCube7 = new shapes.Cube
                                  (material, transform.Translation(2, -2, 0) * transform.RotationX(-0.7854) * transform.RotationY(3.927));
            var mappedCube8 = new shapes.Cube
                                  (material, transform.Translation(6, -2, 0) * transform.RotationX(-0.7854) * transform.RotationY(5.4978));


            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    light1, light2, light3, light4
                },
                Objects = new List <shapes.Shape>()
                {
                    mappedCube1, mappedCube2, mappedCube3, mappedCube4, mappedCube5, mappedCube6, mappedCube7, mappedCube8
                }
            };

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

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

            canvas.SaveAsPPMFile(FolderPath.Text + $"\\TextureMap_CubeAlignCheck[{elapsedMs}ms].ppm");
        }
        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");
        }
Exemple #19
0
        public void PixelSizeVerticalCanvas()
        {
            RTF.Camera c = new RTF.Camera(125, 200, Math.PI / 2);

            Assert.Equal(0.01, c.PixelSize, 2);
        }
        private void LancellottiChapel_Click(object sender, RoutedEventArgs e)
        {
            var light = new RTF.Light(point.Point(0, 100, 0), RTF.Color.White);

            var camera = new RTF.Camera(800, 400, 1.2)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 0, 0),
                    point.Point(0, 0, 5),
                    point.Vector(0, 1, 0))
            };

            var sphere = new shapes.Sphere()
            {
                Transform = transform.Translation(0, 0, 5) * transform.Scaling(0.75, 0.75, 0.75),
                Material  = new RTF.Material()
                {
                    Diffuse    = 0.4,
                    Specular   = 0.6,
                    Shininess  = 20,
                    Reflective = 0.6,
                    Ambient    = 0
                }
            };
            var negx = new List <string>();
            var negy = new List <string>();
            var negz = new List <string>();
            var posx = new List <string>();
            var posy = new List <string>();
            var posz = new List <string>();

            try
            {
                using (StreamReader sr = new StreamReader(@".\Files\negx.ppm"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        negx.Add(line);
                    }
                }
                using (StreamReader sr = new StreamReader(@".\Files\negy.ppm"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        negy.Add(line);
                    }
                }
                using (StreamReader sr = new StreamReader(@".\Files\negz.ppm"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        negz.Add(line);
                    }
                }
                using (StreamReader sr = new StreamReader(@".\Files\posx.ppm"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        posx.Add(line);
                    }
                }
                using (StreamReader sr = new StreamReader(@".\Files\posy.ppm"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        posy.Add(line);
                    }
                }
                using (StreamReader sr = new StreamReader(@".\Files\posz.ppm"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        posz.Add(line);
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                throw ex;
            }

            var pattern = new UV.Cube(new UV.Image(RTF.Canvas.CanvasFromPPM(negx)),
                                      new UV.Image(RTF.Canvas.CanvasFromPPM(posx)),
                                      new UV.Image(RTF.Canvas.CanvasFromPPM(posz)),
                                      new UV.Image(RTF.Canvas.CanvasFromPPM(negz)),
                                      new UV.Image(RTF.Canvas.CanvasFromPPM(posy)),
                                      new UV.Image(RTF.Canvas.CanvasFromPPM(negy)));

            var cube = new shapes.Sphere()
            {
                Transform = transform.Scaling(1000, 1000, 1000),
                Material  = new RTF.Material()
                {
                    Pattern  = pattern,
                    Diffuse  = 0,
                    Specular = 0,
                    Ambient  = 1
                }
            };

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

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

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

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