public static string RenderPikachu()
        {
            var    world = new World();
            IShape floor = new Plane
            {
                Material = new Material(new CheckerPattern(Color.Black, Color.White).Scale(5))
            };

            world.Add(floor);

            ObjFileReader smoothPikachuObj = new ObjFileReader("pikachu.obj", true);
            var           smoothPikachu    = smoothPikachuObj.ObjToGroup();

            smoothPikachu.Rotate(ry: Math.PI).Translate(tx: 0.5);
            world.Add(smoothPikachu);

            ObjFileReader pikachuObj = new ObjFileReader("pikachu.obj", false);
            var           pikachu    = pikachuObj.ObjToGroup();

            pikachu.Rotate(ry: Math.PI).Translate(tx: -4);
            world.Add(pikachu);

            var point = Helper.CreatePoint(10, 10, -10) / 2;

            world.Lights.Add(new PointLight(Helper.CreatePoint(100, 100, -100), Color.White));
            var camera = new Camera(600, 400, Math.PI / 3, Helper.ViewTransform(point, Helper.CreatePoint(0, 3, 0), Helper.CreateVector(0, 1, 0)));

            camera.RowRendered += Program.OnRowRendered;
            var    canvas = camera.Render(world);
            string file   = Path.Combine(Path.GetTempPath(), "pikachu.ppm");

            canvas.SavePPM(file);
            return(file);
        }
        public static string RenderTeapot()
        {
            var    world = new World();
            IShape floor = new Plane
            {
                Material = new Material(new CheckerPattern(Color.Black, Color.White))
            };

            world.Add(floor);

            ObjFileReader teapotObj = new ObjFileReader("teapot.obj");
            var           teapot    = teapotObj.ObjToGroup();

            world.Add(teapot);

            var point = Helper.CreatePoint(7, 5, -10);

            world.Lights.Add(new PointLight(Helper.CreatePoint(15, 15, -15), Color.White));
            var camera = new Camera(600, 400, Math.PI / 3, Helper.ViewTransform(point, Helper.CreatePoint(0, 0, 0), Helper.CreateVector(0, 1, 0)));

            camera.RowRendered += Program.OnRowRendered;
            var    canvas = camera.Render(world);
            string file   = Path.Combine(Path.GetTempPath(), "teapot.ppm");

            canvas.SavePPM(file);
            return(file);
        }
Пример #3
0
        public override void InitWorld()
        {
            IShape floor = new Plane
            {
                Material = new Material(new CheckerPattern(Color.Black, Color.White).Scale(5))
            };

            Add(floor);

            var           assembly         = typeof(PikachuScene).GetTypeInfo().Assembly;
            Stream        resource         = assembly.GetManifestResourceStream("ray_tracer_demos.Basic.Pikachu.obj");
            ObjFileReader smoothPikachuObj = new ObjFileReader(resource, true);
            var           smoothPikachu    = smoothPikachuObj.ObjToGroup();

            smoothPikachu.Rotate(ry: Math.PI).Translate(tx: 0.5);
            Add(smoothPikachu);

            resource = assembly.GetManifestResourceStream("ray_tracer_demos.Basic.Pikachu.obj");
            ObjFileReader pikachuObj = new ObjFileReader(resource, false);
            var           pikachu    = pikachuObj.ObjToGroup();

            pikachu.Rotate(ry: Math.PI).Translate(tx: -4);
            Add(pikachu);

            var point = Helper.CreatePoint(10, 10, -10) / 2;

            Light(100, 100, -100);
        }
Пример #4
0
        public override void InitWorld()
        {
            IShape floor = new Plane
            {
                Material = new Material(new CheckerPattern(Color.Black, Color.White))
            };

            Add(floor);

            var           assembly  = typeof(TeapotScene).GetTypeInfo().Assembly;
            Stream        resource  = assembly.GetManifestResourceStream("ray_tracer_demos.Basic.teapot.obj");
            ObjFileReader teapotObj = new ObjFileReader(resource, false);
            var           teapot    = teapotObj.ObjToGroup();

            Add(teapot);
            Light(15, 15, -15);
        }