Ejemplo n.º 1
0
        public void Render()
        {
            var halfWidth  = _width / 2;
            var halfHeight = _height / 2;

            // cast a ray against each pixel on the canvas
            for (var y = -halfHeight; y < halfHeight; y++)
            {
                for (var x = -halfWidth; x < halfWidth; x++)
                {
                    List <Hit> hits = CastRay(x, y);
                    // Check if we did hit something
                    if (hits.Count == 0)
                    {
                        continue;
                    }

                    Color lightColor = CalculateLight(hits[0]);
                    _canvas.SetPixel(x + _width / 2, y + _height / 2, lightColor);
                }
            }

            // Save the result into a bitmap
            PPM.SaveCanvas(_canvas, "RtTest");
        }