Beispiel #1
0
        private void CastLight(LightSource light, int x, int y, int radius, int row, float startSlope, float endSlope, int xx, int xy, int yx, int yy)
        {
            if (startSlope < endSlope)
                return;

            float nextStartSlope = startSlope;
            for (int i = row; i < radius; ++i)
            {
                bool blocked = false;
                for (int dx = -i, dy = -i; dx <= 0; ++dx)
                {
                    float lSlope = (dx - 0.5f) / (dy + 0.5f);
                    float rSlope = (dx + 0.5f) / (dy - 0.5f);

                    if (startSlope < rSlope)
                        continue;
                    else if (endSlope > lSlope)
                        break;

                    int sax = dx * xx + dy * xy;
                    int say = dx * yx + dy * yy;

                    if ((sax < 0 && Math.Abs(sax) > x) || (say < 0 && Math.Abs(say) > y))
                        continue;

                    int ax = x + sax;
                    int ay = y + say;
                    if(ax >= Width || ay >= Height)
                        continue;

                    int rad2 = radius * radius;
                    //we lit the cell
                    if ((dx * dx + dy * dy) < rad2 && (Math.Abs(ax-x) + Math.Abs(ay-y) <= radius/1.1))
                    {
                        int squaredDist = (x - ax) * (x - ax) + (y - ay) * (y - ay);
                        double intensityCoef1 = 1.0 / (1.0 + squaredDist/LightingMap.LightScaleDropoff);
                        double intensityCoef2 = intensityCoef1 - 1.0 / (1.0 + radius * radius);
                        double intensityCoef3 = intensityCoef2 / (1.0 - 1.0 / (1.0 + radius * radius));
                        LightCell(ax, ay, (byte)Math.Max((intensityCoef3 * light.Intensity/LightingMap.IntensityScaleFactor), GetLightLevel(ax, ay)));
                    }

                    if (blocked)
                    {
                        if (cells[ax, ay].IsObscuring)
                        {
                            nextStartSlope = rSlope;
                            continue;
                        }
                        else
                        {
                            blocked = false;
                            startSlope = nextStartSlope;
                        }
                    }
                    else if (cells[ax, ay].IsObscuring)
                    {
                        blocked = true;
                        nextStartSlope = rSlope;
                        CastLight(light, x, y, radius, i + 1, startSlope, lSlope, xx, xy, yx, yy);
                    }
                }
                if (blocked)
                    break;
            }
        }
Beispiel #2
0
 public void AddLightSource(LightSource l)
 {
     l.Intensity = 80;
     lightSources.Add(l);
 }
Beispiel #3
0
 public void AddLightSource(LightSource Lantern)
 {
     lightingMap.AddLightSource(Lantern);
 }