Exemplo n.º 1
0
        public static void DrawLine(Graphics img, Coordinate3D start, Coordinate3D end, int screenZ)
        {
            Coordinate2D start2d = ConvertTo2DCoords(start, screenZ);
            Coordinate2D end2d = ConvertTo2DCoords(end, screenZ);

            img.DrawLine(new Pen(Color.Red, 2), start2d, end2d);
        }
Exemplo n.º 2
0
        private static int CalculateScreenY(Coordinate3D point, Coordinate3D viewPoint, int screenZ)
        {
            //not sure if this is correct
            if (point.Z == 0 || viewPoint.Z == 0) return point.Y;

            return (((point.Y - viewPoint.Y) * (screenZ - viewPoint.Z)) / (point.Z * viewPoint.Z))  +viewPoint.Y;
        }
Exemplo n.º 3
0
        public void DrawLine(Coordinate3D start, Coordinate3D end)
        {
            Coordinate2D start2d = ConvertTo2DCoords(start,_viewPoint, _screenZ);
            Coordinate2D end2d = ConvertTo2DCoords(end, _viewPoint, _screenZ);

            _img.DrawLine(new Pen(Color.Red, 2), new Point(start2d.X+500, start2d.Y+500), new Point(end2d.X+500, end2d.Y+500));
        }
Exemplo n.º 4
0
        private static Coordinate2D ConvertTo2DCoords(Coordinate3D coord, int screenZ)
        {
            Coordinate2D coord2d = new Coordinate2D();
            coord2d.X = CalculateScreenX(screenZ, coord);
            coord2d.Y = CalculateScreenY(screenZ, coord);

            return coord2d;
        }
Exemplo n.º 5
0
        private static Coordinate2D ConvertTo2DCoords(Coordinate3D point, Coordinate3D viewPoint, int screenZ)
        {
            Coordinate2D coord2D = new Coordinate2D();
            coord2D.X = CalculateScreenX(point, viewPoint, screenZ);
            coord2D.Y = CalculateScreenY(point, viewPoint, screenZ);

            return coord2D;
        }
Exemplo n.º 6
0
 public AdvancedDrawer(
     int screenZ,
     Coordinate3D viewPoint,
     Graphics img)
 {
     _screenZ = screenZ;
     _viewPoint = viewPoint;
     _img = img;
 }
Exemplo n.º 7
0
        private static int CalculateScreenY(int screenZ, Coordinate3D point)
        {
            if (point.Z == 0) return point.Y;

            return (point.Y * screenZ) / point.Z;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Application main method.
        /// </summary>
        /// <param name="args">Command line arguments</param>
        static void Main(string[] args)
        {
            CommandLineArguments cArgs = new CommandLineArguments(args);

            Configuration config = new Configuration();

            var something = new Driven.Metrics.DrivenMetrics.Factory().Create(
                 cArgs.Assemblies.ToArray(),
                 config.Container.ResolveAll<IMetricCalculator>() ,
                     "TestReport",
                 config.Container.Resolve<IReport>());

            something.RunAllMetricsAndGenerateReport();

            CodeStadt.Core.DrivenMetrics.Reporting.ResultOutput results = something.Report.As<Core.DrivenMetrics.Reporting.ResultOutput>();

            if (results != null)
            {
                results.Results.ForEach(x =>
                {
                    Console.WriteLine("Metric: {0}".Formatted(x.Name));
                    Console.WriteLine("");

                    x.ClassResults.ForEach(y =>
                    {
                        Console.WriteLine("  Class: {0}".Formatted(y.Name));
                        Console.WriteLine("");
                        y.MethodResults.ForEach(z =>
                        {
                            Console.WriteLine("    Method: {0} \n\r    Result: {1}".Formatted(z.Name, z.Result));
                            Console.WriteLine("");

                        });
                    });
                });
            }

              // Console.ReadLine();

            Console.WriteLine("Going to try and draw an image :-)");

            int screenZ = 49;

            string simpleFileName = "simple.jpg";
            if (File.Exists(simpleFileName)) File.Delete(simpleFileName);

            Bitmap simpleMap = new Bitmap(1000, 1000);

            Graphics simpleImage = Graphics.FromImage(simpleMap);

            //front square
            Coordinate3D coord1 = new Coordinate3D(430, 430, 1);
            Coordinate3D coord2 = new Coordinate3D(480, 430, 1);
            Coordinate3D coord3 = new Coordinate3D(480, 480, 1);
            Coordinate3D coord4 = new Coordinate3D(430, 480, 1);

            //rear square
            Coordinate3D coord11 = new Coordinate3D(450, 450, 2);
            Coordinate3D coord21 = new Coordinate3D(520, 450, 2);
            Coordinate3D coord31 = new Coordinate3D(520, 520, 2);
            Coordinate3D coord41 = new Coordinate3D(450, 520, 2);

            //draw front square
            SimpleDrawer.DrawLine(simpleImage, coord1, coord2, screenZ);
            SimpleDrawer.DrawLine(simpleImage, coord2, coord3, screenZ);
            SimpleDrawer.DrawLine(simpleImage, coord3, coord4, screenZ);
            SimpleDrawer.DrawLine(simpleImage, coord4, coord1, screenZ);

            //draw rear square

            SimpleDrawer.DrawLine(simpleImage, coord11, coord21, screenZ);
            SimpleDrawer.DrawLine(simpleImage, coord21, coord31, screenZ);
            SimpleDrawer.DrawLine(simpleImage, coord31, coord41, screenZ);
            SimpleDrawer.DrawLine(simpleImage, coord41, coord11, screenZ);

            //link front to rear

            SimpleDrawer.DrawLine(simpleImage, coord1, coord11, screenZ);
            SimpleDrawer.DrawLine(simpleImage, coord2, coord21, screenZ);
            SimpleDrawer.DrawLine(simpleImage, coord3, coord31, screenZ);
            SimpleDrawer.DrawLine(simpleImage, coord4, coord41, screenZ);

            simpleMap.Save(simpleFileName, ImageFormat.Jpeg);

            //view point stuff
            //note that the blue square is the back face of the cube

            //some change

            string advancedFileName = "advanced.jpg";
            if (File.Exists(advancedFileName)) File.Delete(advancedFileName);

            Bitmap advancedMap = new Bitmap(1000, 1000);

            Graphics advancedImage = Graphics.FromImage(advancedMap);

            Coordinate3D viewPoint = new Coordinate3D(0,0, 30);

            AdvancedDrawer drawer = new AdvancedDrawer(screenZ, viewPoint, advancedImage);

            advancedImage.FillPolygon(Brushes.Black, new Point[]{
                new Point(0,1000),
                new Point(1000,1000),
                new Point(1000,0),
                new Point(0,0),
            });

            Coordinate3D middleX = new Coordinate3D(500, 0, screenZ);
            Coordinate3D middleY = new Coordinate3D(0, 500, screenZ);

            drawer.DrawLine(new Coordinate3D(-500, 0, screenZ), new Coordinate3D(500, 0, screenZ));
            drawer.DrawLine(new Coordinate3D(0,-500, screenZ), new Coordinate3D(0, 500, screenZ));

            //draw rear square

            //AdvancedDrawer.DrawLine(advancedImage, coord11, coord21, viewPoint, screenZ);
            //AdvancedDrawer.DrawLine(advancedImage, coord21, coord31, viewPoint, screenZ);
            //AdvancedDrawer.DrawLine(advancedImage, coord31, coord41, viewPoint, screenZ);
            //AdvancedDrawer.DrawLine(advancedImage, coord41, coord11, viewPoint, screenZ);

            //ICityBuilder builder = new RandomCubeBuilder(50, 600, 40, 600, 40, 600, 1, 1);

            //            IEnumerable<IShape> shapes = builder.CreateCity(null);

            Cube cb = new Cube(new Coordinate3D(0, 0, 50), 50, 50, 50);
            IEnumerable<IShape> shapes = new IShape[] { cb };

            shapes.ForEach(y => y.Faces.ForEach(x =>
            {
                drawer.DrawFilledPolygon(x.Brush, x.ToArray());
            }));

            advancedMap.Save(advancedFileName);
        }