public void DrawEnemy2(Matrix view, Matrix projection, Vector3 playerpos, Quaternion playerRotation, Vector3 cameraPosition, Vector3 cameraDirection, GraphicsDeviceManager graphics) { enemySpaceship2.Draw(Enemy2World * Matrix.CreateScale(.005f) * Matrix.CreateFromQuaternion(playerRotation) * Matrix.CreateTranslation(playerpos.X, playerpos.Y, playerpos.Z + 1) , view, projection); _laserManager.DrawLasers(view, projection, cameraPosition, cameraDirection, graphics); }
/// <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); }