예제 #1
0
        /// <summary>
        ///     Se llama cada vez que hay que refrescar la pantalla.
        ///     Escribir aquí todo el código referido al renderizado.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            //Finalmente invocamos al draw del modelo.
            RasterizerState originalRasterizerState = Graphics.GraphicsDevice.RasterizerState;
            RasterizerState rasterizerState         = new RasterizerState();

            rasterizerState.CullMode = CullMode.None;
            Graphics.GraphicsDevice.RasterizerState = rasterizerState;

            skybox.Draw(View, Projection, position);

            Graphics.GraphicsDevice.RasterizerState = originalRasterizerState;



            VenusModel.Draw(World *
                            Matrix.CreateScale(.05f) *
                            Matrix.CreateRotationY(VenusRotation) *
                            Matrix.CreateTranslation(-5f, -2f, -10), View, Projection);

            // SpaceShipModel.Draw(World * Matrix.CreateScale(.8f) * Matrix.CreateRotationY(RotationY), View, Projection);

            SpaceShipModelMK1.Draw(World * //Matrix.CreateTranslation(0,-15f,0) *
                                   Matrix.CreateScale(.15f) *
                                   Matrix.CreateFromYawPitchRoll(Rotation.X, Rotation.Y, Rotation.Z) *
                                   // Rotation *
                                   Matrix.CreateTranslation(position)
                                   , View, Projection);

            SpaceShipModelMK2.Draw(World *
                                   Matrix.CreateScale(.08f) *
                                   Matrix.CreateRotationY(VenusRotation) *
                                   Matrix.CreateTranslation(4f, -2f, -10), View, Projection);

            SpaceShipModelMK3.Draw(World *
                                   Matrix.CreateScale(.08f) *
                                   Matrix.CreateRotationY(-VenusRotation) *
                                   Matrix.CreateTranslation(3f, 2f, -10), View, Projection);

            base.Draw(gameTime);
        }
예제 #2
0
        /// <summary>
        ///     Se llama cada vez que hay que refrescar la pantalla.
        ///     Escribir aquí todo el código referido al renderizado.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);



            if (State == GameState.Playing)
            {
                #region Pass 1

                // Use the default blend and depth configuration
                GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                GraphicsDevice.BlendState        = BlendState.Opaque;

                // Set the main render target, here we'll draw the base scene
                GraphicsDevice.SetRenderTarget(MainSceneRenderTarget);
                GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1f, 0);

                DrawCheckpoints();
                DrawSkybox();

                // Assign the basic effect and draw
                foreach (var modelMesh in SpaceShipModelMK1.Meshes)
                {
                    foreach (var part in modelMesh.MeshParts)
                    {
                        part.Effect = SpaceShipEffect;
                    }
                }
                SpaceShipModelMK1.Draw(
                    Matrix.CreateScale(0.005f) *
                    Matrix.CreateFromQuaternion(_spaceshipRotation) *
                    Matrix.CreateTranslation(_spaceshipPosition)
                    , View, Projection);

                EM.Draw(View, Projection);
                EM.DrawEnemigoVigilante(View, Projection, _spaceshipPosition, _spaceshipRotation, _cameraPosition, _cameraDirection, Graphics);

                _trench.Draw(View, Projection, _lightDirection, Graphics);

                _laserManager.DrawLasers(View, Projection, _cameraPosition, _cameraDirection, Graphics);

                DrawHUD();
                GraphicsDevice.DepthStencilState = DepthStencilState.Default;

                #endregion

                DrawShadows(SpaceShipModelMK1, Matrix.CreateScale(0.005f) *
                            Matrix.CreateFromQuaternion(_spaceshipRotation) *
                            Matrix.CreateTranslation(_spaceshipPosition), SpaceShipEffect);

                #region Pass 2

                // Set the render target as our bloomRenderTarget, we are drawing the bloom color into this texture
                GraphicsDevice.SetRenderTarget(FirstPassBloomRenderTarget);
                GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1f, 0);

                BloomEffect.CurrentTechnique = BloomEffect.Techniques["BloomPass"];
                BloomEffect.Parameters["baseTexture"].SetValue(SpaceShipEffect.Texture);

                // We get the base transform for each mesh
                var modelMeshesBaseTransforms = new Matrix[SpaceShipModelMK1.Bones.Count];
                SpaceShipModelMK1.CopyAbsoluteBoneTransformsTo(modelMeshesBaseTransforms);
                foreach (var modelMesh in SpaceShipModelMK1.Meshes)
                {
                    foreach (var part in modelMesh.MeshParts)
                    {
                        part.Effect = BloomEffect;
                    }

                    // We set the main matrices for each mesh to draw
                    var worldMatrix = modelMeshesBaseTransforms[modelMesh.ParentBone.Index];

                    // WorldViewProjection is used to transform from model space to clip space
                    BloomEffect.Parameters["WorldViewProjection"].SetValue(worldMatrix * Matrix.CreateScale(0.005f) *
                                                                           Matrix.CreateFromQuaternion(_spaceshipRotation) *
                                                                           Matrix.CreateTranslation(_spaceshipPosition) * View * Projection);

                    // Once we set these matrices we draw
                    modelMesh.Draw();
                }

                #endregion

                #region Multipass Bloom

                BlurEffect.CurrentTechnique = BlurEffect.Techniques["Blur"];

                var bloomTexture           = FirstPassBloomRenderTarget;
                var finalBloomRenderTarget = SecondPassBloomRenderTarget;

                for (var index = 0; index < PassCount; index++)
                {
                    GraphicsDevice.SetRenderTarget(finalBloomRenderTarget);
                    GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1f, 0);

                    BlurEffect.Parameters["baseTexture"].SetValue(bloomTexture);
                    FullScreenQuad.Draw(BlurEffect);

                    if (index != PassCount - 1)
                    {
                        var auxiliar = bloomTexture;
                        bloomTexture           = finalBloomRenderTarget;
                        finalBloomRenderTarget = auxiliar;
                    }
                }

                #endregion

                #region Final Pass

                GraphicsDevice.DepthStencilState = DepthStencilState.None;

                GraphicsDevice.SetRenderTarget(null);
                GraphicsDevice.Clear(Color.Black);

                BloomEffect.CurrentTechnique = BloomEffect.Techniques["Integrate"];
                BloomEffect.Parameters["baseTexture"].SetValue(MainSceneRenderTarget);
                BloomEffect.Parameters["bloomTexture"].SetValue(finalBloomRenderTarget);
                FullScreenQuad.Draw(BloomEffect);

                #endregion
            }
            else
            if (State == GameState.Win)
            {
                SpriteBatch.Begin(samplerState: GraphicsDevice.SamplerStates[0],
                                  rasterizerState: GraphicsDevice.RasterizerState);
                SpriteBatch.Draw(Victory,
                                 new Rectangle(200, 100, 600, 600),
                                 Color.White);
                SpriteBatch.End();
            }
            else
            if (State == GameState.GameOver)
            {
                SpriteBatch.Begin(samplerState: GraphicsDevice.SamplerStates[0],
                                  rasterizerState: GraphicsDevice.RasterizerState);
                SpriteBatch.Draw(GameOver,
                                 new Rectangle(200, 100, 600, 600), Color.White);
                SpriteBatch.End();
            }

            base.Draw(gameTime);
        }