Пример #1
0
        // draw 3D scene
        public override void Draw3D(GraphicsDevice gd)
        {
            if (gd == null)
            {
                throw new ArgumentNullException("gd");
            }

            // clear background
            gd.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1, 0);

            // draw background animation
            screenManager.DrawBackground(gd);

            // screen aspect
            float aspect = (float)gd.Viewport.Width / (float)gd.Viewport.Height;

            // camera position
            Vector3 cameraPosition = new Vector3(0, 240, -800);

            // view and projection matrices
            Matrix view       = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            Matrix projection =
                Matrix.CreatePerspectiveFieldOfView(0.25f, aspect, 1, 1000);
            Matrix viewProjection = view * projection;

            // rotation matrix
            Matrix rotation = Matrix.CreateRotationY(0.5f * elapsedTime);
            // translation matrix
            Matrix translation = Matrix.CreateTranslation(0, -40, 0);

            // draw ship model
            gameManager.DrawModel(gd, shipModel, RenderTechnique.NormalMapping,
                                  cameraPosition, rotation, viewProjection, lights);

            // draw pad model
            gameManager.DrawModel(gd, padModel, RenderTechnique.NormalMapping,
                                  cameraPosition, translation, viewProjection, lights);

            // set additive blend with no glow (zero on alpha)
            gd.DepthStencilState = DepthStencilState.DepthRead;
            gd.BlendState        = BlendState.AlphaBlend;

            // disable glow (zero in alpha)
            //gd.RenderState.SeparateAlphaBlendEnabled = true;
            //gd.RenderState.AlphaBlendOperation = BlendFunction.Add;
            //gd.RenderState.AlphaSourceBlend = Blend.Zero;
            //gd.RenderState.AlphaDestinationBlend = Blend.Zero;

            // draw pad halo model
            gameManager.DrawModel(gd, padHaloModel, RenderTechnique.PlainMapping,
                                  cameraPosition, translation, viewProjection, null);

            // restore blend modes
            gd.BlendState        = BlendState.Opaque;
            gd.DepthStencilState = DepthStencilState.Default;
        }
Пример #2
0
        public override void Draw3D(GraphicsDevice gd)
        {
            if (gd == null)
            {
                throw new ArgumentNullException("gd");
            }

            // clear background
            gd.Clear(Color.Black);

            // draw background animation
            screenManager.DrawBackground(gd);
        }
Пример #3
0
        public override void Draw3D(GraphicsDevice gd)
        {
            if (gd == null)
            {
                throw new ArgumentNullException("gd");
            }

            // clear backgournd
            gd.Clear(Color.Black);

            // draw background animation
            screenManager.DrawBackground(gd);

            // screen aspect
            float aspect = (float)gd.Viewport.Width / (float)gd.Viewport.Height;

            // camera position
            Vector3 cameraPosition = new Vector3(0, 240, -800);

            // view and projection matrices
            Matrix view       = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            Matrix projection =
                Matrix.CreatePerspectiveFieldOfView(0.25f, aspect, 1, 1000);
            Matrix viewProjection = view * projection;

            // translation matrix
            Matrix transform = Matrix.CreateTranslation(0, -40, 0);

            // if single player mode
            if (gameManager.GameMode == GameMode.SinglePlayer)
            {
                // draw ship model
                gameManager.DrawModel(gd, shipModels[selection[0]],
                                      RenderTechnique.NormalMapping,
                                      cameraPosition, rotation[0], viewProjection, lights);
                // draw pad model
                gameManager.DrawModel(gd, padModel,
                                      RenderTechnique.NormalMapping,
                                      cameraPosition, transform, viewProjection, lights);

                // set additive blend
                gd.DepthStencilState = DepthStencilState.DepthRead;
                gd.BlendState        = BlendState.Additive;


                // disable glow (zero in alpha)
                //gd.RenderState.SeparateAlphaBlendEnabled = true;
                //gd.RenderState.AlphaBlendOperation = BlendFunction.Add;
                //gd.RenderState.AlphaSourceBlend = Blend.Zero;
                //gd.RenderState.AlphaDestinationBlend = Blend.Zero;

                // draw pad halo model
                gameManager.DrawModel(gd, padHaloModel, RenderTechnique.PlainMapping,
                                      cameraPosition, transform, viewProjection, null);

                // enable glow (alpha not zero)
                //gd.RenderState.SeparateAlphaBlendEnabled = false;
                gd.BlendState = BlendState.AlphaBlend;

                // if not confirmed, draw animated selection circle
                if (confirmed[0] == false)
                {
                    transform = Matrix.CreateRotationY(elapsedTime);
                    float scale = 1.0f + 0.03f * (float)Math.Cos(elapsedTime * 7);
                    transform     = transform * Matrix.CreateScale(scale);
                    transform.M42 = -10;
                    gameManager.DrawModel(gd, padSelectModel,
                                          RenderTechnique.PlainMapping, cameraPosition, transform,
                                          viewProjection, null);
                }

                // restore blend modes
                gd.DepthStencilState = DepthStencilState.Default;
                gd.BlendState        = BlendState.Opaque;
            }
            else // if multi player mode
            {
                Matrix transform1 = rotation[0] * Matrix.CreateTranslation(90, 0, 0);
                Matrix transform2 = rotation[1] * Matrix.CreateTranslation(-90, 0, 0);

                // draw ship model for player 1
                gameManager.DrawModel(gd, shipModels[selection[0]],
                                      RenderTechnique.NormalMapping,
                                      cameraPosition, transform1, viewProjection, lights);
                // draw ship model for player 2
                gameManager.DrawModel(gd, shipModels[selection[1]],
                                      RenderTechnique.NormalMapping,
                                      cameraPosition, transform2, viewProjection, lights);

                // draw pad model for player 1
                transform.M41 = 90;
                gameManager.DrawModel(gd, padModel, RenderTechnique.NormalMapping,
                                      cameraPosition, transform, viewProjection, lights);

                // draw pad model for player 2
                transform.M41 = -90;
                gameManager.DrawModel(gd, padModel, RenderTechnique.NormalMapping,
                                      cameraPosition, transform, viewProjection, lights);

                // set additive blend
                gd.DepthStencilState = DepthStencilState.DepthRead;
                gd.BlendState        = BlendState.Additive;

                // disable glow (zero in alpha)
                //gd.RenderState.SeparateAlphaBlendEnabled = true;
                //gd.RenderState.AlphaBlendOperation = BlendFunction.Add;
                //gd.RenderState.AlphaSourceBlend = Blend.Zero;
                //gd.RenderState.AlphaDestinationBlend = Blend.Zero;

                // draw pad halo model for player 1
                transform.M41 = 90;
                gameManager.DrawModel(gd, padHaloModel, RenderTechnique.NormalMapping,
                                      cameraPosition, transform, viewProjection, null);

                // draw pad halo model for player 2
                transform.M41 = -90;
                gameManager.DrawModel(gd, padHaloModel, RenderTechnique.NormalMapping,
                                      cameraPosition, transform, viewProjection, null);

                // enable glow (alpha not zero)
                //gd.RenderState.SeparateAlphaBlendEnabled = false;
                gd.BlendState = BlendState.AlphaBlend;


                // if not confirmed, draw animated selection circle for player 1
                if (confirmed[0] == false)
                {
                    transform = Matrix.CreateRotationY(elapsedTime);
                    float scale = 0.9f + 0.03f * (float)Math.Cos(elapsedTime * 7);
                    transform     = transform * Matrix.CreateScale(scale);
                    transform.M41 = 90;
                    transform.M42 = -10;
                    gameManager.DrawModel(gd, padSelectModel,
                                          RenderTechnique.PlainMapping, cameraPosition, transform,
                                          viewProjection, null);
                }

                // if not confirmed, draw animated selection circle for player 2
                if (confirmed[1] == false)
                {
                    transform = Matrix.CreateRotationY(elapsedTime);
                    float scale = 0.9f + 0.03f * (float)Math.Cos(elapsedTime * 7);
                    transform     = transform * Matrix.CreateScale(scale);
                    transform.M41 = -90;
                    transform.M42 = -10;
                    gameManager.DrawModel(gd, padSelectModel,
                                          RenderTechnique.PlainMapping, cameraPosition, transform,
                                          viewProjection, null);
                }

                // restore blend modes
                gd.DepthStencilState = DepthStencilState.Default;
                gd.BlendState        = BlendState.Opaque;
            }
        }