コード例 #1
0
        public void CubeBoundingBox()
        {
            var s   = new shape.Cube();
            var box = s.Bounds();

            Assert.Equal(pt.Point(-1, -1, -1), box.Minimum);
            Assert.Equal(pt.Point(1, 1, 1), box.Maximum);
        }
コード例 #2
0
ファイル: Cubes.cs プロジェクト: AlyCrunch/RayTracerChallenge
        public void NormalSurfaceCube(double px, double py, double pz, double vx, double vy, double vz)
        {
            var p         = pt.Point(px, py, pz);
            var expNormal = pt.Vector(vx, vy, vz);

            var c      = new shape.Cube();
            var normal = c.NormalAt(p);

            Assert.Equal(expNormal, normal);
        }
コード例 #3
0
ファイル: Cubes.cs プロジェクト: AlyCrunch/RayTracerChallenge
        public void RayMissCube(double px, double py, double pz, double vx, double vy, double vz)
        {
            var point     = pt.Point(px, py, pz);
            var direction = pt.Vector(vx, vy, vz);

            var c = new shape.Cube();
            var r = new Ray(point, direction);

            var xs = c.Intersect(r);

            Assert.Empty(xs);
        }
コード例 #4
0
        public void CSGCreatedWithOperationAndTwoShapes()
        {
            var s1 = new shape.Sphere();
            var s2 = new shape.Cube();
            var c  = new shape.CSG(shape.Operation.Union, s1, s2);

            Assert.Equal(shape.Operation.Union, c.Operation);
            Assert.Equal(s1, c.Left);
            Assert.Equal(s2, c.Right);
            Assert.Equal(c, s1.Parent);
            Assert.Equal(c, s2.Parent);
        }
コード例 #5
0
ファイル: Cubes.cs プロジェクト: AlyCrunch/RayTracerChallenge
        public void RayIntersectCube(double px, double py, double pz, double vx, double vy, double vz, double t1, double t2)
        {
            var point     = pt.Point(px, py, pz);
            var direction = pt.Vector(vx, vy, vz);

            var c = new shape.Cube();
            var r = new Ray(point, direction);

            var xs = c.Intersect(r);

            Assert.Equal(2, xs.Length);
            Assert.Equal(t1, xs[0].T);
            Assert.Equal(t2, xs[1].T);
        }
コード例 #6
0
        public void FilteringListIntersections(string op, int x0, int x1)
        {
            var operation = (shape.Operation)Enum.Parse(typeof(shape.Operation), op);
            var s1        = new shape.Sphere();
            var s2        = new shape.Cube();

            var c  = new shape.CSG(operation, s1, s2);
            var xs = Intersection.Intersections(
                new Intersection(1, s1),
                new Intersection(2, s2),
                new Intersection(3, s1),
                new Intersection(4, s2)
                );

            List <Intersection> result = c.FilterIntersections(xs);

            Assert.Equal(2, result.Count);
            Assert.Equal(xs[x0], result[0]);
            Assert.Equal(xs[x1], result[1]);
        }
コード例 #7
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");
        }