Exemplo n.º 1
0
        public virtual LightColour GetLight(double x, double y)
        {
            int x0 = (int)Math.Floor(x - X);
            int y0 = (int)Math.Floor(y - Y);

            if (x0 == x && y0 == y)
            {
                return(myLighting[x0, y0]);
            }

            int x1 = x0 + 1;
            int y1 = y0 + 1;

            x -= x0;
            y -= y0;

            LightColour x0y0a = myLighting[x0, y0];
            LightColour x1y0a = myLighting[x1, y0];
            LightColour x1y1a = myLighting[x1, y1];
            LightColour x0y1a = myLighting[x0, y1];

            float r = (float)((x0y0a.R * (1 - x) + x1y0a.R * x) * (1 - y) + (x0y1a.R * (1 - x) + x1y1a.R * x) * y);
            float g = (float)((x0y0a.G * (1 - x) + x1y0a.G * x) * (1 - y) + (x0y1a.G * (1 - x) + x1y1a.G * x) * y);
            float b = (float)((x0y0a.B * (1 - x) + x1y0a.B * x) * (1 - y) + (x0y1a.B * (1 - x) + x1y1a.B * x) * y);

            return(new LightColour(r, g, b));
        }
Exemplo n.º 2
0
        public void FillLighting(LightColour colour)
        {
            for (int x = 0; x < Width + 1; ++x)
            {
                for (int y = 0; y < Height + 1; ++y)
                {
                    myLighting[x, y] = colour;
                }
            }

            UpdateLighting();
        }
Exemplo n.º 3
0
        protected virtual float[] GetRawLightData()
        {
            float[] data = new float[myLightCount * 20];

            int i = 0;

            for (int x = 0; x < Width; ++x)
            {
                for (int y = 0; y < Height; ++y)
                {
                    if (myTiles[x, y].IsVisible)
                    {
                        float rx = (X + x) * 16.0f;
                        float ry = (Y + y) * 16.0f;

                        float yInc = 16.0f;

                        if (SmoothLighting)
                        {
                            if (myTiles[x, y].UseHalfLighting)
                            {
                                data[i++] = rx;
                                data[i++] = ry + 8.0f;
                                data[i++] = myLighting[x, y + 1].R;
                                data[i++] = myLighting[x, y + 1].G;
                                data[i++] = myLighting[x, y + 1].B;

                                data[i++] = rx + 16.0f;
                                data[i++] = ry + 8.0f;
                                data[i++] = myLighting[x + 1, y + 1].R;
                                data[i++] = myLighting[x + 1, y + 1].G;
                                data[i++] = myLighting[x + 1, y + 1].B;

                                data[i++] = rx + 16.0f;
                                data[i++] = ry + 16.0f;
                                data[i++] = myLighting[x + 1, y + 1].R;
                                data[i++] = myLighting[x + 1, y + 1].G;
                                data[i++] = myLighting[x + 1, y + 1].B;

                                data[i++] = rx;
                                data[i++] = ry + 16.0f;
                                data[i++] = myLighting[x, y + 1].R;
                                data[i++] = myLighting[x, y + 1].G;
                                data[i++] = myLighting[x, y + 1].B;

                                yInc = 8.0f;
                            }

                            data[i++] = rx;
                            data[i++] = ry;
                            data[i++] = myLighting[x, y].R;
                            data[i++] = myLighting[x, y].G;
                            data[i++] = myLighting[x, y].B;

                            data[i++] = rx + 16.0f;
                            data[i++] = ry;
                            data[i++] = myLighting[x + 1, y].R;
                            data[i++] = myLighting[x + 1, y].G;
                            data[i++] = myLighting[x + 1, y].B;

                            data[i++] = rx + 16.0f;
                            data[i++] = ry + yInc;
                            data[i++] = myLighting[x + 1, y + 1].R;
                            data[i++] = myLighting[x + 1, y + 1].G;
                            data[i++] = myLighting[x + 1, y + 1].B;

                            data[i++] = rx;
                            data[i++] = ry + yInc;
                            data[i++] = myLighting[x, y + 1].R;
                            data[i++] = myLighting[x, y + 1].G;
                            data[i++] = myLighting[x, y + 1].B;
                        }
                        else
                        {
                            LightColour light = GetLight(x + 0.5, y + 0.5);

                            float r = light.R;
                            float g = light.G;
                            float b = light.B;

                            data[i++] = rx;
                            data[i++] = ry;
                            data[i++] = r;
                            data[i++] = g;
                            data[i++] = b;

                            data[i++] = rx + 16.0f;
                            data[i++] = ry;
                            data[i++] = r;
                            data[i++] = g;
                            data[i++] = b;

                            data[i++] = rx + 16.0f;
                            data[i++] = ry + 16.0f;
                            data[i++] = r;
                            data[i++] = g;
                            data[i++] = b;

                            data[i++] = rx;
                            data[i++] = ry + 16.0f;
                            data[i++] = r;
                            data[i++] = g;
                            data[i++] = b;
                        }
                    }
                }
            }

            return(data);
        }