Esempio n. 1
0
        public override void Draw(TimeSpan elapsed, ViewportWrapper viewport, GraphicsDevice device)
        {
            if (viewport is BirdsEyeViewport)
            {
                return;
            }
            if (!IsInView(viewport, 700))
            {
                return;
            }
            var world = Matrix.CreateRotationY(MathHelper.ToRadians(0)) * Matrix.CreateScale(0.35f) * Matrix.CreateTranslation(new Vector3(X, -16f, -Y));

            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World      = world;
                    effect.View       = viewport.View;
                    effect.Projection = viewport.Projection;
                    _defaultLigthing.Apply(effect);
                }

                mesh.Draw();
            }
        }
Esempio n. 2
0
        protected bool IsInView(ViewportWrapper viewport, float distance)
        {
            float cameraY = -viewport.CameraPosition.Z;

            if (viewport is BirdsEyeViewport)
            {
                return(Y > cameraY - 200 && Y < cameraY + 200);
            }

            return(Y > cameraY - 10 && Y < cameraY + 400);
        }
Esempio n. 3
0
        public override void Draw(TimeSpan elapsed, ViewportWrapper viewport, GraphicsDevice device)
        {
            var firstQuad = (int)(viewport.CameraPosition.Z / QoadHeight) * QoadHeight;

            bool birdsEye  = viewport is BirdsEyeViewport;
            var  start     = birdsEye ? -20 : 0;
            var  quadCount = birdsEye ? 40 : 20;

            for (int i = start; i < quadCount; i++)
            {
                var world = Matrix.CreateTranslation(new Vector3(0, 0, firstQuad + -i * QoadHeight));
                DrawQuad(world, viewport.View, viewport.Projection, device);
            }
        }
Esempio n. 4
0
        private void DrawModel(ViewportWrapper viewport, Matrix world)
        {
            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World      = world;
                    effect.View       = viewport.View;
                    effect.Projection = viewport.Projection;
                    effect.EnableDefaultLighting();
                    _defaultLigthing.Apply(effect);
                }

                mesh.Draw();
            }
        }
Esempio n. 5
0
        public virtual void Draw(TimeSpan elapsed, ViewportWrapper viewport, GraphicsDevice device)
        {
            if (!IsInView(viewport, GameConstants.RenderingAreaY))
            {
                return;
            }

            var world = TransformModelToWorld();

            DrawModel(viewport, world);

            if (!ShadowDisabled &&
                viewport.ShadowEffectEnabled &&
                IsInView(viewport, GameConstants.ShadowRenderingAreaY))
            {
                DrawShadow(viewport, device, world);
            }
        }
Esempio n. 6
0
        private void DrawShadow(ViewportWrapper viewport, GraphicsDevice device, Matrix world)
        {
            if (viewport is BirdsEyeViewport)
            {
                return;
            }
            // Draw shadow, using the stencil buffer to prevent drawing overlapping polygons

            // Clear stencil buffer to zero.
            device.Clear(ClearOptions.Stencil, Color.Black, 0.5f, 0);

            device.DepthStencilState = new DepthStencilState
            {
                StencilEnable = true,
                // Draw on screen if 0 is the stencil buffer value
                ReferenceStencil = 0,
                StencilFunction  = CompareFunction.Equal,
                // Increment the stencil buffer if we draw
                StencilPass = StencilOperation.Increment,
            };

            device.BlendState = new BlendState
            {
                AlphaSourceBlend      = Blend.SourceColor,
                AlphaDestinationBlend = Blend.InverseSourceColor,
                ColorDestinationBlend = Blend.DestinationColor,
            };

            // Create a Plane using three points on the Quad
            var basicEffect = new BasicEffect(device);

            basicEffect.EnableDefaultLighting();
            basicEffect.Alpha        = 0.5f;
            basicEffect.DiffuseColor = Vector3.Up;
            var shadowLightDir = basicEffect.DirectionalLight0.Direction;

            // Use plane based on model to create a shadow matrix, and make the shadow slightly
            // The shadow is based on the strongest light
            Quad quad   = new Quad(new Vector3(X, 0.01f, -Y), Vector3.Up, Vector3.Backward, Width + 10, Height + 10);
            var  plane  = new Plane(quad.UpperLeft, quad.UpperRight, quad.LowerLeft);
            var  shadow = Matrix.CreateShadow(shadowLightDir, plane) *
                          Matrix.CreateTranslation(quad.Normal / 80);

            // Draw the shadow without lighting
            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.AmbientLightColor = Vector3.Zero;
                    effect.EnableDefaultLighting();
                    effect.Alpha = 0.5f;
                    effect.DirectionalLight0.Enabled = false;
                    effect.DirectionalLight1.Enabled = false;
                    effect.DirectionalLight2.Enabled = false;
                    effect.View       = viewport.View;
                    effect.Projection = viewport.Projection;
                    effect.World      = world * shadow;
                }
                mesh.Draw();
            }

            // Return render states to normal, turn stencilling off
            device.DepthStencilState = new DepthStencilState
            {
                StencilEnable = false
            };

            device.BlendState = new BlendState();
        }
Esempio n. 7
0
 private void Draw(GameTime gameTime, ViewportWrapper viewport)
 {
     _gameObjects.ForEach(go => go.Draw(gameTime.ElapsedGameTime, viewport, GraphicsDevice));
 }
Esempio n. 8
0
        public override void Draw(TimeSpan elapsed, ViewportWrapper viewport, GraphicsDevice device)
        {
            var world = Matrix.CreateTranslation(new Vector3(0, 0.01f, -Y));

            DrawQuad(world, viewport.View, viewport.Projection, device);
        }