示例#1
0
        public void PointLightHasPositionAndIntensity()
        {
            var intensity = new RTF.Color(1, 1, 1);
            var position  = pt.Point(0, 0, 0);
            var light     = new RTF.Light(position, intensity);

            Assert.Equal(position, light.Position);
            Assert.Equal(intensity, light.Intensity);
        }
示例#2
0
        public RTF.Canvas CreateCircle(RTF.Shapes.Sphere s)
        {
            var lightPos = RTF.PointType.Point(-10, 10, -10);
            var light    = new RTF.Light(lightPos, RTF.Color.White);

            var    rayOrigin   = RTF.PointType.Point(0, 0, -5);
            double wallZ       = 10;
            double wallSize    = 7;
            var    canvasPixel = 100;
            double pixelSize   = wallSize / canvasPixel;
            double half        = wallSize / 2;

            var canvas = new RTF.Canvas(canvasPixel, canvasPixel, RTF.Color.Black);

            var shape = s;

            shape.Material.Color = RTF.Color.Magenta;

            for (int y = 0; y < canvasPixel; y++)
            {
                var worldY = half - pixelSize * y;
                for (int x = 0; x < canvasPixel; x++)
                {
                    var worldX   = -half + pixelSize * x;
                    var position = RTF.PointType.Point(worldX, worldY, wallZ);

                    var r  = new RTF.Ray(rayOrigin, (position - rayOrigin).Normalize());
                    var xs = shape.Intersect(r);

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

                    if (hit != null)
                    {
                        var point  = RTH.Transformations.Position(r, hit.T);
                        var normal = hit.Object.NormalAt(point);
                        var eye    = -r.Direction;

                        var color = RTF.Light.Lighting(
                            (hit.Object as RTF.Shapes.Sphere).Material,
                            hit.Object,
                            light,
                            point,
                            eye,
                            normal,
                            false);

                        canvas.WritePixel(x, y, color);
                    }
                }
            }

            return(canvas);
        }
示例#3
0
        public void LightingWithEyeBetweenLightSurface()
        {
            var m        = new RTF.Material();
            var position = pt.Point(0, 0, 0);

            var eyeVector    = pt.Vector(0, 0, -1);
            var normalVector = pt.Vector(0, 0, -1);

            var light = new RTF.Light
                            (pt.Point(0, 0, -10), new RTF.Color(1, 1, 1));
            var result = RTF.Light.Lighting(m, new Sphere(), light, position, eyeVector, normalVector, false);

            CustomAssert.Equal(new RTF.Color(1.9, 1.9, 1.9), result, 5);
        }
示例#4
0
        public void LightingWithEyeBetweenLightSurfaceOffset45()
        {
            var m        = new RTF.Material();
            var position = pt.Point(0, 0, 0);

            var eyeVector    = pt.Vector(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2);
            var normalVector = pt.Vector(0, 0, -1);

            var light = new RTF.Light
                            (pt.Point(0, 0, -10), new RTF.Color(1, 1, 1));
            var result = light.Lighting(m, new Sphere(), position, eyeVector, normalVector, false);

            Assert.Equal(new RTF.Color(1, 1, 1), result);
        }
示例#5
0
        public void LightingWithEyeOppositeSurfaceOffset45()
        {
            var m        = new RTF.Material();
            var position = pt.Point(0, 0, 0);

            var eyeVector    = pt.Vector(0, 0, -1);
            var normalVector = pt.Vector(0, 0, -1);

            var light = new RTF.Light
                            (pt.Point(0, 10, -10), new RTF.Color(1, 1, 1));
            var result = light.Lighting(m, new Sphere(), position, eyeVector, normalVector, false);

            CustomAssert.Equal(new RTF.Color(0.7364, 0.7364, 0.7364), result, 4);
        }
示例#6
0
        public void LightingWithEyePathReflection()
        {
            var m        = new RTF.Material();
            var position = pt.Point(0, 0, 0);

            var eyeVector    = pt.Vector(0, -Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2);
            var normalVector = pt.Vector(0, 0, -1);

            var light = new RTF.Light
                            (pt.Point(0, 10, -10), new RTF.Color(1, 1, 1));
            var result = light.Lighting(m, new Sphere(), position, eyeVector, normalVector, false);

            CustomAssert.Equal(new RTF.Color(1.6364, 1.6364, 1.6364), result, 4);
        }
示例#7
0
        public void LightingWithEyeBehindSurface()
        {
            var m        = new RTF.Material();
            var position = pt.Point(0, 0, 0);

            var eyeVector    = pt.Vector(0, 0, -1);
            var normalVector = pt.Vector(0, 0, -1);

            var light = new RTF.Light
                            (pt.Point(0, 0, 10), new RTF.Color(1, 1, 1));
            var result = light.Lighting(m, new Sphere(), position, eyeVector, normalVector, false);

            Assert.Equal(new RTF.Color(0.1, 0.1, 0.1), result);
        }
示例#8
0
        public void LightingSurfaceShadow()
        {
            var m        = new RTF.Material();
            var position = p.Point(0, 0, 0);

            var eyeV     = p.Vector(0, 0, -1);
            var normalV  = p.Vector(0, 0, -1);
            var light    = new RTF.Light(p.Point(0, 0, -10), RTF.Color.White);
            var inShadow = true;


            var result   = light.Lighting(m, new Sphere(), position, eyeV, normalV, inShadow);
            var expected = new RTF.Color(0.1, 0.1, 0.1);

            Assert.Equal(expected, result);
        }
示例#9
0
        public void LightingWithPatternApplied()
        {
            var m = new RTF.Material
            {
                Pattern  = Pattern.GetStripePattern(RTF.Color.White, RTF.Color.Black),
                Ambient  = 1,
                Diffuse  = 0,
                Specular = 0
            };
            var eyev    = pt.Vector(0, 0, -1);
            var normalv = pt.Vector(0, 0, -1);
            var light   = new RTF.Light(pt.Point(0, 0, -10), RTF.Color.White);

            var c1 = light.Lighting(m, new shapes.Sphere(), pt.Point(0.9, 0, 0), eyev, normalv, false);
            var c2 = light.Lighting(m, new shapes.Sphere(), pt.Point(1.1, 0, 0), eyev, normalv, false);

            Assert.Equal(RTF.Color.White, c1);
            Assert.Equal(RTF.Color.Black, c2);
        }
示例#10
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");
        }
示例#11
0
        /*
         *- 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");
        }
示例#12
0
        public void TheDefaultWorld()
        {
            var light = new RTF.Light(
                RTF.PointType.Point(-10, 10, -10),
                RTF.Color.White);

            var s1 = new Sphere(
                new RTF.Material(
                    new RTF.Color(0.8, 1, 0.6),
                    0.7,
                    0.2
                    )
                );
            var s2 = new Sphere(
                RTH.Transformations.Scaling(0.5, 0.5, 0.5)
                );

            RTF.World w = RTF.World.Default();

            Assert.Equal(light, w.Lights.First());
            Assert.Contains(s1, w.Objects);
            Assert.Contains(s2, w.Objects);
        }
示例#13
0
        /*
         * - 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");
        }
示例#14
0
        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);
        }
示例#15
0
        /*
         * - 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");
        }
示例#16
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");
        }
示例#17
0
        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");
        }