Esempio n. 1
0
        public RenderApplication(
            Enviroment enviroment,
            int winWidth,
            int winHeight,
            List <Camera> cameras,
            List <IFragmentShader> fragmentShaders)
        {
            this.buffers           = new Queue <FastBitmap>();
            this.rasterizerService = new RasterizerService(fragmentShaders);
            Width      = winHeight;
            Height     = winHeight;
            Enviroment = enviroment;
            Cameras    = cameras;
            RenderForm = new Form1()
            {
                BackColor = Color.Black,
                Width     = winWidth,
                Height    = winHeight
            };
            Controller            = new CameraController();
            RenderForm.KeyDown   += (args, e) => Controller.KeyDown(e);
            RenderForm.KeyUp     += (args, e) => Controller.KeyUp(e);
            RenderForm.MouseMove += (args, e) => Controller.HanleMouse(e);
            Timer          = new Timer();
            Timer.Interval = 100;
            Timer.Tick    += async(args, e) =>
            {
                if (Monitor.IsEntered(prepareLocker))
                {
                    return;
                }

                Monitor.Enter(prepareLocker);

                FastBitmap buffer = new FastBitmap(1, 1);
                try
                {
                    buffer = await this.rasterizerService.GetSnapshot(this.Enviroment, this.CurrentCamera);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
                if (buffer.Width != 1)
                {
                    RenderForm.BackgroundImage = new Bitmap(buffer.Bitmap, RenderForm.Size);
                }
                Monitor.Exit(prepareLocker);
            };
        }
Esempio n. 2
0
        public static void StartWeaponScene()
        {
            var enviroment   = new Enviroment(10000);
            var originCam    = new Camera(new Vector3(0, 0, -500), 100, (float)(Math.PI / 2), 800, 600);
            var shadowMapCam = new Camera(new Vector3(0, 0, -500), 100, (float)(Math.PI / 2), 800, 600);
            var model        = ObjParser.FromObjFile(@"C:\Users\Dato\Desktop\DevilRender\Models\Cyborg_Weapon.obj",
                                                     @"C:\Users\Dato\Desktop\DevilRender\Models\Cyborg-Weapon textures.png");
            var sm = new ShadowMappingShader(2, shadowMapCam, enviroment);
            var ps = new PhongModelShader(new Light(new Vector3(0, 0, -1000), 2));

            model.Scale(1000f);
            model.Rotate(1.57f, Axis.Y);
            enviroment.AddPrimitive(model);

            //var devilRender = new RenderApplication(
            //    enviroment,
            //    800,
            //    600,
            //    new List<Camera>
            //    {
            //        originCam,
            //        shadowMapCam
            //    },
            //    new List<IFragmentShader>() {sm, ps});
            //devilRender.Start();

            var r = new RasterizerService(new List <IFragmentShader> {
                sm, ps
            });

            while (true)
            {
                var sw = new Stopwatch();
                sw.Start();
                r.GetSnapshot(enviroment, originCam).Wait();
                sw.Stop();
                Console.WriteLine($"{sw.ElapsedMilliseconds}");
            }
        }