Example #1
0
        private void InitCamera()
        {
            GraphicsDevice device      = graphics.GraphicsDevice;
            float          aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height;

            camera.Position            = new Vector3(0.0f, 0.0f, 3.0f);
            camera.Acceleration        = new Vector3(100.0f, 100.0f, 100.0f);
            camera.Velocity            = new Vector3(300.0f, 300.0f, 300.0f);
            camera.OrbitMinZoom        = 1.5f;
            camera.OrbitMaxZoom        = 5.0f;
            camera.OrbitOffsetDistance = camera.OrbitMinZoom;
            camera.LookAt(new Vector3(0, 0, 0));
            ChangeCameraBehavior(Camera.Behavior.Spectator);
        }
Example #2
0
        public override void OnStart()
        {
            base.OnStart();

            Vertex[] vertices = new Vertex[]
            {
                new Vertex
                {
                    Location = new System.Numerics.Vector3(-0.5f, -0.5f, 0),
                    Color    = Color.Gold,
                    UV       = Vector2.Zero,
                },
                new Vertex
                {
                    Location = new System.Numerics.Vector3(0.5f, -0.5f, 0),
                    Color    = Color.Red,
                    UV       = Vector2.Zero,
                },
                new Vertex
                {
                    Location = new System.Numerics.Vector3(0.5f, 0.5f, 0),
                    Color    = Color.Blue,
                    UV       = Vector2.Zero,
                },
                new Vertex
                {
                    Location = new System.Numerics.Vector3(-0.5f, 0.5f, 0),
                    Color    = Color.Green,
                    UV       = Vector2.Zero,
                },
            };

            ushort[] ind = new ushort[]
            {
                0, 1, 2,
                2, 3, 0,
            };

            CameraComp = new CameraComponent(null);
            CameraComp.Register();
            CameraComp.MakeActive();

            const bool TestPerspective = false;

            if (TestPerspective)
            {
                CameraComp.Mode     = CameraComponent.ProjectionMode.Perspective;
                CameraComp.Location = new Vector3(200, 100, 500);
                CameraComp.LookAt(Vector3.Zero);
            }
            else
            {
                CameraComp.Mode = CameraComponent.ProjectionMode.Orthographic;
            }


            IVertexBuffer VertexBuffer = Renderer.RendererResourceFactory.CreateVertexBuffer();

            VertexBuffer.SetVertexData(vertices, ind);

            Command = Renderer.RendererResourceFactory.CreateRenderCommand()
                      .WithDebugName("Sample Game Render")
                      .WithMaterial(Renderer.DefaultMaterialPtr.Get <Material>())
                      .WithVertexBuffer(VertexBuffer);


            SampleRenderable renderable = new SampleRenderable(Command);

            Renderer.AddRenderable(renderable);
        }
Example #3
0
        /// <summary>
        /// Load your graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            world.Load(content);

            // Setup terrain.
            terrain = new Terrain(GraphicsDevice, content);
            terrain.Create(128, 20, 0.0f, 2048.0f, Terrain.HeightMapGenerationMethod.FromBitMap, AIParams.CONFIG_TERREIN_HEIGHT_PARAMETER);

            //terrain.AddRegion(-1000.0f, 2048.0f, @"Textures\region_grass_thin");

            terrain.AddRegion(-120.0f, -10.0f, @"Textures\region_soil_dry2");
            terrain.AddRegion(-10.0f, 500.0f, @"Textures\region_grass_thin");
            terrain.AddRegion(400.0f, 800.0f, @"Textures\region_rock1");
            //terrain.AddRegion(700.0f, 2048.0f, @"Textures\region_rock2");

            //terrain.AddRegion(-120.0f, 70.0f, @"Textures\region_soil_dry2");
            //terrain.AddRegion(20.0f, 700.0f, @"Textures\region_grass_thin");
            //terrain.AddRegion(700.0f, 1000.0f, @"Textures\region_rock1");
            //terrain.AddRegion(1001.0f, 2048.0f, @"Textures\region_rock2");

            terrain.SunlightDirection = Vector3.Down;
            terrain.SunlightColor     = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            terrain.TerrainAmbient    = new Vector4(0.3f, 0.3f, 0.3f, 1.0f);
            terrain.TerrainDiffuse    = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);

            // Setup camera.
            camera.CurrentBehavior = Camera.Behavior.FreeView;
            camera.Velocity        = new Vector3(Settings.CAMERA_VELOCITY);
            camera.Acceleration    = new Vector3(Settings.CAMERA_ACCELERATION);
            camera.Perspective(80, (float)_windowWidth / (float)_windowHeight, 0.1f, terrain.TerrainBoundingSphere.Radius * 4.0f);
            Vector3 cameraPos = new Vector3();

            cameraPos.X = terrain.TerrainCenter.X;
            cameraPos.Z = terrain.TerrainCenter.Z;
            cameraPos.Y = terrain.TerrainHeightMap.HeightAt(cameraPos.X, cameraPos.Z) * 1.5f + 2000;
            camera.LookAt(cameraPos, new Vector3(terrain.TerrainCenter.X + 1, terrain.TerrainHeightMap.HeightAt(cameraPos.X, cameraPos.Z), terrain.TerrainCenter.Z + 1), Vector3.Up);

            worldMatrix = Matrix.CreateWorld(cameraPos, Vector3.Forward, Vector3.Up);

            // good for the tests
            int ntroops   = AIParams.CONFIG_NUMBER_AIOBJECTS_IN_TEAM;
            int nsnipers  = (int)Math.Ceiling((double)ntroops / 9.0);
            int nsupports = (int)Math.Ceiling((double)ntroops / 7.0);

            ntroops = ntroops - nsnipers - nsupports - 1;
            _aicontainer.CreateTeam(AITeamType.Alpha, Color.Red, ntroops, nsnipers, nsupports, terrain.TerrainCenter, true);
            _aicontainer.CreateTeam(AITeamType.Bravo, Color.Blue, ntroops, nsnipers, nsupports, new Vector3(200), true);
            _aicontainer.CreateTeam(AITeamType.Charlie, Color.White, ntroops, nsnipers, nsupports, new Vector3(terrain.TerrainSize - 200), true);

            //aicontainer.CreateTeam(AITeamType.Alpha, Color.Red, 0, 0, 0, terrain.TerrainCenter, false);
            //aicontainer.CreateTeam(AITeamType.Bravo, Color.Blue, 0, 0, 0, new Vector3(200), false);
            //aicontainer.CreateTeam(AITeamType.Charlie, Color.White, 0, 0, 0, new Vector3(terrain.TerrainSize - 200), false);

            _aicontainer.AddMulitpleAIStatics(
                AIParams.CONFIG_NUMBER_COVERS,
                AIParams.CONFIG_NUMBER_MEDS,
                AIParams.CONFIG_NUMBER_BONUSES
                );

            // have to be done after building the teams and adding objects to the world
            _aicontainer.InitializeAI();
            // Load ai objects
            _aicontainer.LoadContent(content);
            _aicontainer.SpreadObjects();

            //aicontainer.SelectTeam(AITeamType.Alpha);
            //aicontainer.SelectedTeam.ToFormation(AIFormation.Row);
            //aicontainer.SelectedTeam.KeepFormation = false;

            //aicontainer.SelectTeam(AITeamType.Bravo);
            //aicontainer.SelectedTeam.ToFormation(AIFormation.Arrow);
            //aicontainer.SelectedTeam.KeepFormation = false;

            //aicontainer.SelectTeam(AITeamType.Charlie);
            //aicontainer.SelectedTeam.ToFormation(AIFormation.Spread);
            //aicontainer.SelectedTeam.KeepFormation = false;

            AIGame.Console.Show();
        }