Exemplo n.º 1
0
        protected override void Initialize()
        {
            graphics.GraphicsProfile = GraphicsProfile.HiDef;
            UpdateAntiAlias();
            UpdateVSync();
            graphics.ApplyChanges();

            IsMouseVisible = false;

            spriteBatch = new SpriteBatch(GraphicsDevice);

            camera      = new FirstPersonCamera(this);
            rightCamera = new FirstPersonCamera(this);
            leftCamera  = new FirstPersonCamera(this);
            skycamera   = new FirstPersonCamera(this);

            UpdateEffects();

            for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
            {
                GamePadState state = GamePad.GetState(i);
                if (state.IsConnected)
                {
                    activeGamePad = i;
                    break;
                }
            }

            Samplers.Refresh();
            Samplers.InitRasterizers();

            SwitchDisplayMode();

            base.Initialize();
        }
Exemplo n.º 2
0
 public void Copy(GameTime gameTime, FirstPersonCamera c)
 {
     leftRightRot = c.leftRightRot;
     upDownRot    = c.upDownRot;
     Position     = c.Position;
     Target       = c.Target;
     Update(gameTime);
 }
Exemplo n.º 3
0
        protected override void Initialize()
        {
            graphics.PreferMultiSampling            = true;
            graphics.GraphicsProfile                = GraphicsProfile.HiDef;
            graphics.SynchronizeWithVerticalRetrace = true;
            IsFixedTimeStep = true;
            graphics.ApplyChanges();
            graphics.GraphicsDevice.PresentationParameters.MultiSampleCount = 4;


            Samplers.Refresh();

            GoWindowed();

            IsMouseVisible = false;

            effect = new BasicEffect(graphics.GraphicsDevice);
            effect.VertexColorEnabled = true;
            effect.TextureEnabled     = true;
            effect.DiffuseColor       = new Vector3(2f, 2f, 2f);

            instanceEffect = new BasicEffect(graphics.GraphicsDevice);
            instanceEffect.VertexColorEnabled = true;
            instanceEffect.TextureEnabled     = false;

            spriteBatch = new SpriteBatch(GraphicsDevice);

            camera    = new FirstPersonCamera(this);
            lowcamera = new FirstPersonCamera(this);
            skycamera = new FirstPersonCamera(this);

            DisableLodCamera();

            for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
            {
                GamePadState state = GamePad.GetState(i);
                if (state.IsConnected)
                {
                    activeGamePad = i;
                    break;
                }
            }

            Samplers.InitRasterizers();

            base.Initialize();
        }
Exemplo n.º 4
0
        public void Render(GraphicsDeviceManager graphics, BasicEffect effect, FirstPersonCamera camera)
        {
            effect.World      = Matrix.CreateScale(Scale) * Matrix.CreateTranslation(Position);
            effect.View       = camera.ViewMatrix;
            effect.Projection = camera.ProjectionMatrix;

            if (Game1.instmodels.ContainsKey(ModelName))
            {
                Game1.instmodels[ModelName].Render(graphics, effect);
            }
            else if (Game1.instTris.ContainsKey(ModelName))
            {
                Game1.instTris[ModelName].Render(graphics, effect);
            }
            else
            {
                Console.WriteLine(ModelName + " not loaded");
            }
        }
Exemplo n.º 5
0
        public void Draw(GraphicsDeviceManager graphics, BasicEffect effect, AlphaTestEffect alpha, FirstPersonCamera camera)
        {
            effect.World      = Matrix.CreateScale(Scale) * Matrix.CreateFromYawPitchRoll(Rotation.X, Rotation.Y, Rotation.Z) * Matrix.CreateTranslation(Position);
            effect.View       = camera.ViewMatrix;
            effect.Projection = camera.ProjectionMatrix;

            if (Game1.instmodels.ContainsKey(ModelName))
            {
                Game1.instmodels[ModelName].Draw(graphics, effect, alpha);
            }
            else if (Game1.instTris.ContainsKey(ModelName))
            {
                Game1.instTris[ModelName].Draw(graphics, effect, alpha);
            }
            else
            {
                Console.WriteLine(ModelName + " not loaded");
            }
        }
Exemplo n.º 6
0
        //public static bool twoSided = false;

        private void DrawLevel(FirstPersonCamera cam = null)
        {
            if (RenderEnabled)
            {
                //if (loading != null && gameLoaded)
                //{
                //if we have a sky and sky is enabled
                if (sky != null && settings.Sky)
                {
                    effect.View       = skycamera.ViewMatrix;
                    effect.Projection = skycamera.ProjectionMatrix;

                    effect.DiffuseColor /= 2;
                    sky.DrawSky(graphics, effect, null);
                    effect.DiffuseColor *= 2;

                    alphaTestEffect.DiffuseColor = effect.DiffuseColor;

                    //clear z buffer
                    GraphicsDevice.Clear(ClearOptions.DepthBuffer, Color.Green, 1, 0);
                }

                effect.View       = (cam != null ? cam.ViewMatrix : camera.ViewMatrix);
                effect.Projection = (cam != null ? cam.ProjectionMatrix : camera.ProjectionMatrix);

                alphaTestEffect.View       = effect.View;
                alphaTestEffect.Projection = effect.Projection;


                if (settings.Models || settings.BotsPath)
                {
                    Samplers.SetToDevice(graphics, EngineRasterizer.DoubleSided);

                    if (settings.Models)
                    {
                        foreach (var v in instanced)
                        {
                            v.Draw(graphics, instanceEffect, null, (cam != null ? cam : camera));
                        }

                        //render karts
                        foreach (Kart k in karts)
                        {
                            k.Draw(graphics, instanceEffect, null, (cam != null ? cam : camera));
                        }
                    }

                    if (settings.BotsPath)
                    {
                        foreach (var v in paths)
                        {
                            v.Draw(graphics, instanceEffect, null, (cam != null ? cam : camera));
                        }
                    }

                    Samplers.SetToDevice(graphics, EngineRasterizer.Default);
                }

                Samplers.SetToDevice(graphics, EngineRasterizer.Default);

                //render depending on lod
                foreach (MGLevel qb in (settings.UseLowLod ? MeshLow : MeshHigh))
                {
                    qb.Draw(graphics, effect, alphaTestEffect);
                }


                if (settings.VisData)
                {
                    //GraphicsDevice.Clear(ClearOptions.DepthBuffer, Color.Green, 1, 0);

                    //texture enabled makes visdata invisible
                    effect.TextureEnabled = false;

                    foreach (var x in bbox)
                    {
                        foreach (var pass in effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, x, 0, x.Length / 2);
                        }
                    }

                    if (settings.VisDataLeaves)
                    {
                        foreach (var x in bbox2)
                        {
                            foreach (var pass in effect.CurrentTechnique.Passes)
                            {
                                pass.Apply();
                                graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, x, 0, x.Length / 2);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        //public static bool twoSided = false;

        private void DrawLevel(FirstPersonCamera cam = null)
        {
            if (!RenderEnabled)
            {
                return;
            }

            if (cam == null)
            {
                cam = eng.Cameras[CameraType.DefaultCamera];
            }

            //if we have a sky and sky is enabled
            if (eng.sky != null && eng.Settings.ShowSky)
            {
                effect.View       = eng.Cameras[CameraType.SkyCamera].ViewMatrix;
                effect.Projection = eng.Cameras[CameraType.SkyCamera].ProjectionMatrix;

                effect.DiffuseColor /= 2;
                eng.sky.DrawSky(graphics, effect, null);
                effect.DiffuseColor *= 2;

                alphaTestEffect.DiffuseColor = effect.DiffuseColor;

                //clear z buffer
                GraphicsDevice.Clear(ClearOptions.DepthBuffer, Color.Green, 1, 0);
            }

            effect.View       = cam.ViewMatrix;
            effect.Projection = cam.ProjectionMatrix;

            alphaTestEffect.View       = effect.View;
            alphaTestEffect.Projection = effect.Projection;

            //render ctr models from external folder
            foreach (var v in eng.external)
            {
                v.Draw(graphics, instanceEffect, null, cam);
            }


            if (eng.Settings.ShowModels || eng.Settings.ShowBotsPath)
            {
                if (eng.Settings.ShowModels)
                {
                    //render all instanced models
                    foreach (var v in eng.instanced)
                    {
                        v.Draw(graphics, instanceEffect, null, cam);
                    }

                    //render karts
                    foreach (Kart k in karts)
                    {
                        k.Draw(graphics, instanceEffect, null, cam);
                    }
                }

                if (eng.Settings.ShowBotsPath)
                {
                    //render bot paths
                    foreach (var v in eng.paths)
                    {
                        v.Draw(graphics, instanceEffect, null, cam);
                    }
                }
            }

            //Samplers.SetToDevice(graphics, EngineRasterizer.Default);

            //render level mesh depending on lod
            foreach (MGLevel qb in (eng.Settings.UseLowLod ? eng.MeshLow : eng.MeshHigh))
            {
                qb.Draw(graphics, effect, alphaTestEffect);
            }


            if (eng.Settings.VisData)
            {
                //texture enabled makes visdata invisible
                effect.TextureEnabled = false;

                foreach (var x in eng.bbox)
                {
                    x.Draw(graphics, effect);
                }

                if (eng.Settings.VisDataLeaves)
                {
                    foreach (var key in eng.bbox2.Keys)
                    {
                        foreach (var x in eng.bbox2[key])
                        {
                            x.Draw(graphics, effect);
                        }
                    }
                }
            }
        }