Exemplo n.º 1
0
        public void SphereDefaultMaterial()
        {
            var s = new Sphere();
            var m = s.Material;
            var e = new RTF.Material();

            Assert.Equal(e, m);
        }
Exemplo n.º 2
0
        public void DefaultMaterial()
        {
            var m = new RTF.Material();

            Assert.Equal(new RTF.Color(1, 1, 1), m.Color);
            Assert.Equal(0.1, m.Ambient);
            Assert.Equal(0.9, m.Diffuse);
            Assert.Equal(0.9, m.Specular);
            Assert.Equal(200, m.Shininess);
        }
Exemplo n.º 3
0
        public void AssigningMaterial()
        {
            var m = new RTF.Material
            {
                Ambient = 1
            };
            var s = new shapes.TestShape(m);

            Assert.Equal(m, s.Material);
        }
Exemplo n.º 4
0
        public void SphereAssignedMaterial()
        {
            var m = new RTF.Material
            {
                Ambient = 1
            };
            var s = new Sphere
            {
                Material = m
            };

            Assert.Equal(1, s.Material.Ambient);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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");
        }