Ejemplo n.º 1
0
 public void Kill(WaterSurface water, ShadowMap shadow)
 {
     foreach (var island in Children)
     {
         water.ReflectedObjects.Remove(island);
         shadow.ShadowCastingObjects.Remove(island);
         island.Dispose();
     }
     Children.Clear();
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public Archipelag(
            VisionContent vContent,
            VProgram vprogram,
            WaterSurface water,
            ShadowMap shadow)
            : base((IVEffect)null)
        {
            var codeIslands = CodeIsland.Create(vContent, this, vprogram.VAssemblies);
            foreach (var codeIsland in codeIslands)
            {
                water.ReflectedObjects.Add(codeIsland);
                shadow.ShadowCastingObjects.Add(codeIsland);
                Children.Add(codeIsland);
            }

            _bannerSign = new BannerSign(vContent, codeIslands);
            _arcs = new Arcs(vContent, this);
        }
Ejemplo n.º 4
0
        protected override void LoadContent()
        {
            base.LoadContent();

            _spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice));

            _vContent = new VisionContent(_graphicsDeviceManager.GraphicsDevice, Content);
            _arial16Font = Content.Load<SpriteFont>("Fonts/Arial16");

            _basicEffect = new VBasicEffect(_graphicsDeviceManager.GraphicsDevice);
            _basicEffect.EnableDefaultLighting();

            _ball = new SpherePrimitive<VertexPositionNormalTexture>(GraphicsDevice, (p, n, t, tx) => new VertexPositionNormalTexture(p, n, tx), 1);
            var x = _vContent.LoadEffect("effects/simpletextureeffect");
            x.Texture = _vContent.Load<Texture2D>("terraintextures/sand");
            _ballInstance = new VDrawableInstance(x, _ball, Matrix.Translation(10, 2, 10));

            Sky = new SkySphere(_vContent, _vContent.Load<TextureCube>(@"Textures\clouds"));
            _movingShip = new MovingShip(new ShipModel(_vContent));

            _water = WaterFactory.Create(_vContent);
            _water.ReflectedObjects.Add(_movingShip._shipModel);
            _water.ReflectedObjects.Add(_ballInstance);
            _water.ReflectedObjects.Add(Sky);

            _camera = new Camera(
                _vContent.ClientSize,
                new KeyboardManager(this),
                new MouseManager(this),
                null, //new PointerManager(this),
                new Vector3(0, 15, 0),
                new Vector3(-10, 15, 0));

            _rasterizerState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription
            {
                FillMode = FillMode.Solid,
                CullMode = CullMode.Back,
                IsFrontCounterClockwise = false,
                DepthBias = 0,
                SlopeScaledDepthBias = 0.0f,
                DepthBiasClamp = 0.0f,
                IsDepthClipEnabled = true,
                IsScissorEnabled = false,
                IsMultisampleEnabled = false,
                IsAntialiasedLineEnabled = false
            });

            _shadow = new ShadowMap(_vContent, 1024, 1024);
            //_shadow.ShadowCastingObjects.Add(_sailingShip);
            //_shadow.ShadowCastingObjects.Add(reimersTerrain);
            //_shadow.ShadowCastingObjects.Add(generatedTerrain);
            //_shadow.ShadowCastingObjects.Add(bridge);

            //_archipelag = new Archipelag(_vContent, _water, _shadow);

            _data.VContent = _vContent;
            _data.Camera = _camera;
            _data.Water = _water;
            _data.Shadow = _shadow;

            _q = new CxBillboard(_vContent, Matrix.Identity, _vContent.Load<Texture2D>("billboards/wheat_billboard"), 20, 10, 0.5f);
            _q.AddPositionsWithSameNormal(Vector3.Up,
                Vector3.Zero,
                Vector3.Left*10.5f, Vector3.Up,
                Vector3.Right*10.4f, Vector3.Up,
                Vector3.ForwardRH*3.45f, Vector3.Up,
                Vector3.BackwardRH*2.9f, Vector3.Up);
            _q.CreateVertices();
        }