示例#1
0
        static void Main(string[] args)
        {
            GameWorld world     = new GameWorld();
            Sphere    sphere1   = new Sphere(new Vector3(-1.7, 0, 4.5), 0.5f);
            Sphere    sphere2   = new Sphere(new Vector3(-1, -0.3, 5.3), 0.5f);
            Sphere    sphere3   = new Sphere(new Vector3(0, 0, 6), 0.5f);
            Sphere    sphere4   = new Sphere(new Vector3(1, -0.5, 5.5f), 0.5f);
            Sphere    sphereBig = new Sphere(new Vector3(0, -100, 6f), 99.5f);

            world.AddSphere(sphere1);
            world.AddSphere(sphere2);
            world.AddSphere(sphere3);
            world.AddSphere(sphere4);
            world.AddSphere(sphereBig);

            PPMMap map = new PPMMap(960, 540);

            for (int row = 0; row < map.Height; row++)
            {
                for (int col = 0; col < map.Width; col++)
                {
                    Ray ray = Camera.GetRay((double)col / map.Width, (double)row / map.Height);
                    map.SetColor(col, row, GetColor(world, ray));
                }
            }
            map.Save("raytracing.ppm");
            Console.WriteLine("done.");
            Console.ReadKey();
        }