//void DrawGroud(Ground ground)
        //{
        //    foreach (var mesh in ground.Model.Meshes)
        //    {
        //        foreach (BasicEffect effect in mesh.Effects)
        //        {
        //            effect.EnableDefaultLighting();
        //            effect.PreferPerPixelLighting = true;

        //            effect.World = ground.WorldMatrix;
        //            effect.View = player.Camera.View;
        //            effect.Projection = player.Camera.Projection;
        //        }
        //        mesh.Draw();
        //    }
        //}

        public void Draw()
        {
            if (gameManager.IsGameRunning)
            {
                screenManager.Graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
                screenManager.Graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                screenManager.Graphics.GraphicsDevice.RasterizerState   = new RasterizerState()
                {
                    MultiSampleAntiAlias = true
                };
                screenManager.Graphics.GraphicsDevice.SamplerStates[0] = new SamplerState()
                {
                    Filter = TextureFilter.Anisotropic
                };
                if (gameManager.Type == LabiryntType.Prim)
                {
                    labirynth.VertexMap.Where(m => frustum.Contains(m.BoundingBox) != ContainmentType.Disjoint).ToList().ForEach(i => i.Draw(player.Camera.View, player.Camera.Projection, basicEffect));
                }
                else if (gameManager.Type == LabiryntType.Recursive)
                {
                    labirynth.ModelMap.ForEach(i => i.Draw(player.Camera.View, player.Camera.Projection));
                }

                skyBox.Draw(player.Camera.View, player.Camera.Projection);
                finishPoint.Draw(player.Camera.View, player.Camera.Projection, basicEffect);
                ground.Draw(player.Camera.View, player.Camera.Projection, basicEffect);
                keys.ForEach(i => i.Draw(player.Camera.View, player.Camera.Projection, basicEffect));
                minimap.Draw(new Vector2(player.position.X, player.position.Z));
                //DrawGroud(ground);
            }
        }
Example #2
0
        /// <summary>
        /// Reference page contains code sample.
        /// </summary>
        /// <param name="gameTime">Time passed since the last call to Draw.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            this.SetUpBlendState();
            this.SetUpRasterizerState();

            // Input
            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // Objects
            skyBox.Draw(camera);
            terrain.Draw(camera);
            grass.Draw(gameTime, camera);

            // Draw string (Mouse position and FPS)
            spriteBatch.Begin();
            var text = new StringBuilder("");
            float frameRate = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds;
            text.AppendFormat("FPS: {0}", frameRate).AppendLine();
            spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
Example #3
0
 // Draw all 3D-objects
 public void Draw(Matrix View, Matrix Projection, Vector3 CameraPosition)
 {
     _background.Draw(View, Projection, CameraPosition);
     _grid.Draw(View, Projection, CameraPosition);
     _snake.Draw(View, Projection, CameraPosition);
     _blob.Draw(View, Projection, CameraPosition);
 }
Example #4
0
        public override void Draw(GameTime gameTime)
        {
            Vector4 shipColor = new Vector4(0.5f + ((float)bulletManager.justShot / 15f), 0.5f, 0.5f, 1);

            Game1.texNorm.Parameters["shipColor"].SetValue(shipColor);

            Game1.texNorm.Parameters["shipLight"].SetValue(35 + bulletManager.justShot * 2);

            Game1.texNorm.Parameters["shipPos"].SetValue(Player.get().Position);
            Game1.texNorm.Parameters["vpMatrix"].SetValue(theCamera.ViewMatrix * theCamera.ProjectionMatrix);
            Game1.texNorm.Parameters["wallLight"].SetValue(200);
            Game1.texNorm.Parameters["wallColor"].SetValue(Color.Orange.ToVector4());

            asteroidManager.Draw(gameTime);
            skybox.Draw(gameTime);
            tunnel.Draw(gameTime);
            player.Draw(gameTime);
            bulletManager.Draw(gameTime);
            pgen.Draw(gameTime);
            // Draw all game components
            base.Draw(gameTime);

            if (gameOver)
            {
                // TO DO: Draw the "gameover" text
                String TextToDraw = "Game Over!";
                spriteBatch.DrawString(gameOverFont, TextToDraw,
                                       new Vector2((Game.Window.ClientBounds.Width - 250) / 2, (Game.Window.ClientBounds.Height - 250) / 2),
                                       Color.Yellow);
            }
        }
Example #5
0
        public void Render(IRenderArgs args)
        {
            if (_destroyed)
            {
                return;
            }

            args.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            args.GraphicsDevice.SamplerStates[0]  = SamplerState.PointWrap;

            SkyBox.Draw(args);

            ChunkManager.Draw(args,
                              RenderStage.OpaqueFullCube,
                              RenderStage.Opaque);

            EntityManager.Render(args);

            ChunkManager.Draw(args,
                              RenderStage.Transparent,
                              RenderStage.Translucent,
                              RenderStage.Animated,
                              RenderStage.Liquid);

            Player.Render(args);
        }
Example #6
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            if (this.AssestsAreReady)
            {
                skyBox.Draw(camManager.ActiveCamera.ViewMatrix, camManager.ActiveCamera.ProjectionMatrix);
                map.Draw(graphics.GraphicsDevice, camManager.ActiveCamera.ViewMatrix, camManager.ActiveCamera.ProjectionMatrix);
                projectileManager.DrawAllBullets(camManager.ActiveCamera.ViewMatrix, camManager.ActiveCamera.ProjectionMatrix);
                playerManager.DrawAllPlayers(gameTime, camManager.ActiveCamera.ViewMatrix, camManager.ActiveCamera.ProjectionMatrix);
                weaponManager.Draw(camManager.ActiveCamera.ViewMatrix, camManager.ActiveCamera.ProjectionMatrix);
                DrawUIComponents();
            }

            base.Draw(gameTime);
        }
Example #7
0
        protected override void Draw(GameTime gameTime)
        {
            // Aca deberiamos poner toda la logia de renderizado del juego.
            GraphicsDevice.Clear(Color.Black);
            //Box.Draw(FloorWorld, Camera.View, Camera.Projection);
            createStage();
            Efecto.Parameters["View"].SetValue(Camera.View);
            Efecto.Parameters["Projection"].SetValue(Camera.Projection);

            GraphicsDevice.RasterizerState = new RasterizerState {
                CullMode = CullMode.None
            };

            Skybox.Draw(Camera.View, Camera.Projection, Camera.Position);


            float tiempoTranscurrido = (float)gameTime.TotalGameTime.TotalSeconds;

            //ObstaculoCubo.Draw(tiempoTranscurrido, Camera.View, Projection);
            SpheresWorld.ForEach(sphereWorld => Sphere.Draw(sphereWorld, Camera.View, Camera.Projection));

            SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.Opaque,
                              SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);
            SpriteBatch.DrawString(SpriteFont, PositionE.ToString(), new Vector2(GraphicsDevice.Viewport.Width - 400, 0), Color.White);
            SpriteBatch.DrawString(SpriteFont, "\"R\" para REINICIAR", new Vector2(10, 0), Color.White);
            var sphereBody  = Simulation.Bodies.GetBodyReference(SphereHandles[0]);
            var stringSalto = "SALTO";

            if (puedoSaltar)
            {
                SpriteBatch.DrawString(SpriteFont, stringSalto,
                                       new Vector2(0, 30), Color.CornflowerBlue);
            }
            else
            {
                SpriteBatch.DrawString(SpriteFont, stringSalto, new Vector2(0, 30), Color.DarkGray);
            }
            SpriteBatch.End();
        }
Example #8
0
        public void Render()
        {
            if (_skybox != null)
            {
                _skybox.Draw();
            }

            BoundingFrustum frustum = new BoundingFrustum(GameEngine.Camera.View * GameEngine.Camera.Projection);

            _actors.Render(Matrix.Identity, frustum);

            foreach (Opponent opponent in Opponents)
            {
                if (frustum.Intersects(opponent.GetBoundingSphere()))
                {
                    opponent.Driver.InPlayersView = true;
                    opponent.Vehicle.Render();
                }
                else
                {
                    opponent.Vehicle.SkidMarkBuffer.Render();  //always render skids
                    opponent.Driver.InPlayersView = false;
                }
                opponent.Driver.DistanceFromPlayer = Vector3.Distance(PlayerVehicle.Position, opponent.Vehicle.Position);
            }

            Peds.Render();

            RaceTime.Render();
            MessageRenderer.Instance.Render();
            //GameEngine.DebugRenderer.AddAxis(Matrix.CreateTranslation(ConfigFile.GridPosition), 10);

            if (_map.Show)
            {
                _map.Render();
                return;
            }
        }
Example #9
0
 public void DrawSkyBox()
 {
     _skyBox.Draw(_camera);
 }
        /// <summary>Performs draw logic specific to the subsystem.</summary>
        /// <param name="t">The total game time, in seconds.</param>
        /// <param name="dt">The elapsed time since last call, in seconds.</param>
        public override void Draw(float t, float dt)
        {
            Game1.Inst.GraphicsDevice.Clear(Color.CornflowerBlue);
            base.Draw(t, dt);

            // Ritar denna först pga att den stänger av z-axeln när den ritar.
            skyBox.Draw(t, dt, bEffect);
            foreach (var entity in Scene.GetEntities <CHeightmap>())
            {
                var heightmap = entity.GetComponent <CHeightmap>();

                Game1.Inst.GraphicsDevice.SetVertexBuffer(heightmap.VertexBuffer);
                Game1.Inst.GraphicsDevice.Indices = heightmap.IndexBuffer;

                bEffect.EnableDefaultLighting();
                bEffect.LightingEnabled    = true;
                bEffect.VertexColorEnabled = false;
                //bEffect.DiffuseColor = Color.Cyan.ToVector3();

                bEffect.World          = heightmap.Transform;
                bEffect.View           = Camera.ViewMatrix();
                bEffect.Projection     = Camera.Projection;
                bEffect.TextureEnabled = true;
                bEffect.Texture        = groundTexture;

                foreach (var pass in bEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    Game1.Inst.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, heightmap.NumTriangles);
                }
            }
            foreach (var entity in Scene.GetEntities <CModel>())
            {
                var model   = entity.GetComponent <CModel>();
                var control = entity.GetComponent <CControls>();
                var b       = entity.GetComponent <CBody>();
                var he1     = (float)Math.Cos(t * 1.0f * 3.141592653) * 0.045f;
                var he2     = (float)Math.Cos(t * 0.35f * 3.141592653) * 0.42f;

                var tilt2 = Matrix.Identity;
                if (control.Controls.ContainsKey("Turn"))
                {
                    turnDelta += (control.Controls["Turn"] - turnDelta) * dt;
                    tilt2      = Matrix.CreateRotationZ(-turnDelta * 0.18f * 0.65f * b.Velocity.Length());
                }
                var r = new Vector3(b.Velocity.Z, 0, -b.Velocity.X);
                r.Normalize();
                var a    = b.Velocity.Length() * 0.05f * 0.65f;
                var tilt = Matrix.CreateFromAxisAngle(r, a);

                var quat     = Quaternion.CreateFromYawPitchRoll(-b.Heading - 0.5f * 3.141592653589f, b.Pitch, 0.0f);
                var modelRot = Matrix.CreateFromQuaternion(quat);


                Matrix T;
                if (r.Length() > 0.0001f)
                {
                    T = tilt2 * modelRot * tilt * Matrix.CreateTranslation(b.Position.X, b.Position.Y + he1 + he2, b.Position.Z);
                }
                else
                {
                    T = tilt2 * modelRot * Matrix.CreateTranslation(b.Position.X, b.Position.Y + he1 + he2, b.Position.Z);
                }
                var m = model.Transform * T;
                ((LookAtCamera)Camera).Target = new Vector3(m.M41, m.M42 * 0.0f, m.M43);

                viewVector = Vector3.Transform((Vector3)((LookAtCamera)Camera).Target - Camera.Position, Matrix.CreateRotationY(0));
                viewVector.Normalize();

                Matrix[] transforms = new Matrix[model.Model.Bones.Count];
                model.Model.CopyAbsoluteBoneTransformsTo(transforms);
                var temp = transforms[3];
                transforms[1] *= Matrix.CreateRotationY(t * 20f);
                transforms[3] *= Matrix.CreateTranslation(-transforms[3].M41, -transforms[3].M42, -transforms[3].M43);
                transforms[3] *= Matrix.CreateRotationX(t * -20f);
                transforms[3] *= Matrix.CreateTranslation(temp.M41, temp.M42, temp.M43);

                foreach (ModelMesh mesh in model.Model.Meshes)
                {
                    foreach (ModelMeshPart part in mesh.MeshParts)
                    {
                        part.Effect = shader;
                        Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * (transforms[mesh.ParentBone.Index] * m)));
                        shader.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);
                        shader.Parameters["World"].SetValue((transforms[mesh.ParentBone.Index] * m));
                        shader.Parameters["View"].SetValue(Camera.ViewMatrix());
                        shader.Parameters["Projection"].SetValue(Camera.Projection);
                        shader.Parameters["AmbientColor"].SetValue(new Vector4(1f));
                        shader.Parameters["AmbientIntensity"].SetValue(0.1f);
                        shader.Parameters["DiffuseLightDirection"].SetValue(new Vector3(1f, 1f, 0));
                        shader.Parameters["DiffuseColor"].SetValue(new Vector4(0, 1, 1, 1));
                        shader.Parameters["DiffuseIntensity"].SetValue(1.0f);

                        shader.Parameters["ViewVector"].SetValue(viewVector);

                        shader.Parameters["Shininess"].SetValue(200f);
                        shader.Parameters["SpecularColor"].SetValue(new Vector4(1, 1, 1, 1));
                        shader.Parameters["SpecularIntensity"].SetValue(1f);


                        shader.Parameters["Transparency"].SetValue(0.5f);
                    }
                    mesh.Draw();
                }

                /*foreach (var mesh in model.Model.Meshes) {
                 *  foreach (BasicEffect effect in mesh.Effects) {
                 *      effect.TextureEnabled = true;
                 *      effect.Texture = pagaFaceTexture;
                 *      effect.EmissiveColor = Vector3.One * 0.5f; // Make face brighter :-)
                 *      effect.EnableDefaultLighting();
                 *      effect.World = transforms[mesh.ParentBone.Index] * m;
                 *      effect.View = Camera.ViewMatrix();
                 *      effect.Projection = Camera.Projection;
                 *  }
                 *
                 *  mesh.Draw();
                 * }*/
            }
        }