예제 #1
0
        public void CanGetRayDirection()
        {
            // Arrange
            var pos = new Vector(0, 0, 0);
            var dir = new Vector(0, 0, 1);
            var screen = new Screen(400, 300);
            var camera = new Camera(pos, dir, screen);

            // Act
            var ray = camera.GetRayDirection(100, 100);

            // Assert
            Assert.Less(Math.Abs((-1.0 / 8.0) - ray.X), 0.005);
            Assert.Less(Math.Abs((1.0 / 12.0) - ray.Y), 0.005);
            Assert.Less(Math.Abs((1.0) - ray.Z), 0.02);
        }
예제 #2
0
        public void CanConstructNewCamera()
        {
            // Arrange
            var pos = new Vector(0, 0, 0);
            var dir = new Vector(0, 0, 1);
            var screen = new Screen(100, 100);

            // Act
            var camera = new Camera(pos, dir, screen);

            // Assert
            Assert.AreEqual(pos, camera.Position);

            // Forward is a unit vector pointing in 'lookAt' from 'position'
            Assert.IsTrue(camera.Forward.Equals(new Vector(0, 0, 1)));

            // Right
            Assert.IsTrue(camera.Right.Equals(new Vector(1,0,0)));

            // Up
            Assert.IsTrue(camera.Up.Equals(new Vector(0,1,0)));
        }
예제 #3
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 :-)");

            // Lets ray trace something
            string raytraceFileName = "raytrace.jpg";
            if (File.Exists(raytraceFileName)) File.Delete(raytraceFileName);

            int width = 600;
            int height = 600;
            var bitmap = new System.Drawing.Bitmap(width, height);

            RayTracer rayTracer = new RayTracer((int x, int y, System.Drawing.Color color) =>
            {
                bitmap.SetPixel(x, y, color);
            });

            var screen = new Screen(width, height);
            var MyScene = new Scene()
            {
                Elements = new List<SceneObject>() {
                                new Plane()
                                {
                                    Norm = new Vector(0, 1, 0),
                                    Point = new Vector(0, -0.5, 0),
                                    Surface = Surfaces.CheckerBoard
                                }
                                //,new Polygon(new List<Vector>(){ new Vector(0,0,0), new Vector(0,1,0), new Vector(1,1,0), new Vector(1,0,0)}, new Vector(0,0,1))
                                //{
                                //    Surface = Surfaces.White
                                //}
                                //,new Polygon(new List<Vector>(){ new Vector(0,0,0), new Vector(0,1,0), new Vector(0,1,1), new Vector(0,0,1)}, new Vector(1,0,0))
                                //{
                                //    Surface = Surfaces.White
                                //}
                                //,new Polygon(new List<Vector>(){ new Vector(0,0,0), new Vector(0,0,1), new Vector(1,0,1), new Vector(1,0,0)}, new Vector(0,1,0))
                                //{
                                //    Surface = Surfaces.White
                                //}
                                //,new Sphere() {
                                //    Center = new Vector(0,1,0),
                                //    Radius = 1,
                                //    Surface = Surfaces.Shiny
                                //},
                                //new Sphere() {
                                //    Center = new Vector(-1,.5,1.5),
                                //    Radius = .5,
                                //    Surface = Surfaces.Shiny
                                //}

                                // FOR TESTING
                                //,new Line(){
                                //    Point = new Vector(0,0,0),
                                //    Direction = new Vector(1,0,0),
                                //    Surface = Surfaces.Green
                                //}
                                //,new Line(){
                                //    Point = new Vector(0,0,0),
                                //    Direction = new Vector(0,1,0),
                                //    Surface = Surfaces.Green
                                //}
                                //,new Line(){
                                //    Point = new Vector(0,0,0),
                                //    Direction = new Vector(0,0,1),
                                //    Surface = Surfaces.Green
                                //}
                                //,new Line(){
                                //    Point = new Vector(1,0,0),
                                //    Direction = new Vector(0,0,1),
                                //    Surface = Surfaces.Green
                                //}

                },
                Lights = new List<Light>() {
                                //new Light() {
                                //    Position = new Vector(-2,2.5,0),
                                //    Color = new Color(.49,.07,.07)
                                //},
                                //new Light() {
                                //    Position = new Vector(1.5,2.5,1.5),
                                //    Color = new Color(.07,.07,.49)
                                //},
                                //new Light() {
                                //    Position = new Vector(1.5,2.5,-1.5),
                                //    Color = new Color(.07,.49,.071)
                                //},
                                //new Light() {
                                //    Position = new Vector(8,5,-6),
                                //    Color = new Color(1,0,0)
                                //},
                                new Light() {
                                    Position = new Vector(8,4,8),
                                    Color = new Color(1,1,1)
                                }},
                Camera = new Camera(new Vector(6, 3, 6), new Vector(0, 0, 0), screen)
                //Camera = new Camera(new Vector(-3, 2, -4), new Vector(-1,0.5,0))
            };

            MyScene.AddModel(new Cube(1, new Vector(0, 0, 0)));

            rayTracer.Render(MyScene);

            bitmap.Save(raytraceFileName);
        }