public override void Init()
        {
            Content.ContentPath = "Data";

            scene      = new Scene();
            scene.View = this;

            scene.Camera = new LookatCartesianCamera()
            {
                Lookat      = new Vector3(size.Width / 2f, size.Height / 2f, 0),
                Position    = new Vector3(10, 10, 10),
                FOV         = 0.5f,
                ZFar        = 100,
                AspectRatio = AspectRatio
            };

            viewport = new Graphics.GraphicsDevice.Viewport(Device9.Viewport);

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera       = (LookatCartesianCamera)scene.Camera,
                InputHandler = new InteractiveSceneManager {
                    Scene = scene
                },
            };

            renderer = new Graphics.Renderer.Renderer(Device9)
            {
                Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings {
                    WaterEnable = false
                }
            };
            //renderer = new Graphics.DummyRenderer.Renderer { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false } };
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = renderer,
                Scene    = scene
            };
            sceneRendererConnector.Initialize();

            motionSimulation = new Common.Motion.Simulation();

            scene.EntityAdded   += new Action <Entity>(scene_EntityAdded);
            scene.EntityRemoved += new Action <Entity>(scene_EntityRemoved);

            var sim = (Common.Motion.Simulation)motionSimulation;

            npcs = new List <Common.IMotion.INPC>();
            Vector2 startingPosition = new Vector2(size.Width / 2f, size.Height / 2f);

            CreateGround(true);
            scene.Add(controlledUnit = CreateUnit(startingPosition));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(2, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(-4, 2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(4, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(7, -1)), new Vector3(1, 1, 1.5f)));
            //scene.Add(CreateNPC(startingPosition + new Vector2(3, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(3, -1)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-5, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-2, 1)));
            Vector2 unitGroupStartingPosition = startingPosition + new Vector2(3, 3);

            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    scene.Add(CreateNPC(unitGroupStartingPosition + new Vector2(x, y)));
                }
            }

            BulletCreation = (() =>
            {
                scene.Add(CreateBullet(controlledUnit.Translation + Vector3.UnitZ,
                                       bulletSpeed,
                                       controlledUnit.MotionObject.Rotation.Angle,
                                       bulletAcceleration));
            });

            foreach (var npc in npcs)
            {
                npc.Pursue(controlledUnit.MotionObject, 1f);
            }
        }
示例#2
0
 private Common.Bounding.Frustum FrustumWithMargin(Camera camera, Graphics.GraphicsDevice.Viewport viewport)
 {
     return(camera.FrustumFromRectangle(viewport, new Point(-enLargement, -enLargement),
                                        new Point((int)viewport.Width + enLargement, (int)viewport.Height + enLargement)));
 }
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene = new Scene();
            scene.View = this;

            scene.Camera = new LookatCartesianCamera()
            {
                Lookat = new Vector3(size.Width / 2f, size.Height / 2f, 0),
                Position = new Vector3(10, 10, 10),
                FOV = 0.5f,
                ZFar = 100,
                AspectRatio = AspectRatio
            };

            viewport = new Graphics.GraphicsDevice.Viewport(Device9.Viewport);

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = new InteractiveSceneManager { Scene = scene },
            };

            renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false } };
            //renderer = new Graphics.DummyRenderer.Renderer { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false } };
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = renderer,
                Scene = scene
            };
            sceneRendererConnector.Initialize();

            motionSimulation = new Common.Motion.Simulation();

            scene.EntityAdded += new Action<Entity>(scene_EntityAdded);
            scene.EntityRemoved += new Action<Entity>(scene_EntityRemoved);

            var sim = (Common.Motion.Simulation)motionSimulation;

            npcs = new List<Common.IMotion.INPC>();
            Vector2 startingPosition = new Vector2(size.Width / 2f, size.Height / 2f);
            CreateGround(true);
            scene.Add(controlledUnit = CreateUnit(startingPosition));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(2, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(-4, 2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(4, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(7, -1)), new Vector3(1, 1, 1.5f)));
            //scene.Add(CreateNPC(startingPosition + new Vector2(3, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(3, -1)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-5, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-2, 1)));
            Vector2 unitGroupStartingPosition = startingPosition + new Vector2(3, 3);
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    scene.Add(CreateNPC(unitGroupStartingPosition + new Vector2(x, y)));
                }
            }

            BulletCreation = (() =>
            {
                scene.Add(CreateBullet(controlledUnit.Translation + Vector3.UnitZ,
                    bulletSpeed,
                    controlledUnit.MotionObject.Rotation.Angle,
                    bulletAcceleration));
            });

            foreach (var npc in npcs)
                npc.Pursue(controlledUnit.MotionObject, 1f);
        }