Пример #1
0
        public static void DrawWaterSurfaceGrid(
            WaterSurface waterSurface,
            Camera camera,
            ShadowMap shadow,
            int nisse,
            int surfaceSize,
            int surfaceScale)
        {
            const int waterW = 64;
            const int waterH = 64;
            const int worldW = 32;
            const int worldH = 32;

            var boundingFrustum = camera.BoundingFrustum;

            waterSurface.Effect.SetShadowMapping(shadow);

            var gridStartX = (int) camera.Position.X/waterW - worldW/2;
            var gridStartY = (int) camera.Position.Z/waterH - worldH/2;

            Array.Clear(RenderedWaterPlanes, 0, RenderedWaterPlanes.Length);

            var drawDetails = camera.Position.Y < -1; // fix the sea water some time
            if (drawDetails)
                for (var y = 0; y <= worldH; y++)
                    for (var x = 0; x <= worldW; x++)
                    {
                        var pos1 = new Vector3((gridStartX + x) * waterW, 0, (gridStartY + y) * waterH);
                        var pos2 = pos1 + new Vector3(waterW, 1, waterH);
                        var bb = new BoundingBox(pos1, pos2);
                        if (boundingFrustum.Contains(bb) == ContainmentType.Disjoint)
                            continue;

                        waterSurface.Draw(
                            camera,
                            pos1,
                            Vector3.Distance(camera.Position, pos1 - new Vector3(-32, 0, -32)),
                            x % 8,
                            y % 8,
                            1 << surfaceScale);
                    }

            var raise = 0.5f + camera.Position.Y/500;
            var q = (int)camera.ZFar & ~(waterW - 1);
            var pos = new Vector3(gridStartX * waterW - q, raise, gridStartY * waterH - q);
            waterSurface.Draw(camera, pos, -1, 0, 0, 1 << surfaceScale);
        }