Example #1
0
        private RGBA[,] Draw()
        {
            var camera    = _cameraProvider.Get();
            var config    = _configProvider.Get();
            var matrix    = new RGBA[config.Height, config.Width];
            var lightning = _lightningProvider.Get();

            Console.WriteLine("Started render");
            Parallel.For(0, config.Width, x =>
            {
                Parallel.For(0, config.Height, y =>
                {
                    var ray             = _rayProvider.Get(x, y);
                    var lastHitDistance = float.MaxValue;
                    var allHit          = _objContainer.GetObjectsByRay(ray);

                    Parallel.ForEach(allHit, obj =>
                    {
                        if (obj.HitBy(ray, camera.Position))
                        {
                            var hitDistance = (camera.Position - obj.MidPoint).Length;

                            if (lastHitDistance > hitDistance)
                            {
                                lastHitDistance = hitDistance;
                                matrix[y, x]    = lightning.Illuminate(obj);
                            }
                        }
                    });
                });
            });
            Console.WriteLine("Finished render");

            return(matrix);
        }