Inheritance: GameComponent
Beispiel #1
0
        public MyGame(MapControl3D mainHost)
        {
            //SharpDX.Configuration.EnableObjectTracking = true;

            this.Camera = new Camera();
            this.Camera.LookAt(new Vector3(4, 0, 0), new Vector3(0, 0, 0), Vector3.UnitZ);

            this.CameraMoveService = new CameraMoveService(this.Camera);
            base.Updatables.Add(this.CameraMoveService);

            this.ViewGridAdjusterService = new ViewGridAdjusterService(this, mainHost);
            base.Updatables.Add(this.ViewGridAdjusterService);

            this.ViewGridProvider = new ViewGridProvider(this);

            this.CameraKeyHandler = new CameraKeyHandler(this, mainHost);
            base.Updatables.Add(this.CameraKeyHandler);

            m_fpsCounter = new FPSCounter(this);
            base.Updatables.Add(m_fpsCounter);

            this.CursorService = new CursorService(this, mainHost);


            var mainView = new GameSurfaceView(this.GraphicsDevice)
            {
                Camera = this.Camera,
            };

            var axesView = new GameSurfaceView(this.GraphicsDevice)
            {
                Camera = this.Camera,
            };

            var surface = ToDispose(new GameSurface(this.GraphicsDevice, mainHost));

            surface.Views.Add(mainView);
            surface.Views.Add(axesView);

            surface.SizeChanged += (w, h) =>
            {
                var vp = new ViewportF(0, 0, w, h);
                mainView.ViewPort = vp;
                mainView.Camera.SetAspect(vp.AspectRatio);

                axesView.ViewPort = new ViewportF(0, 0, 50, 50);
            };

            base.Surfaces.Add(surface);

            this.MousePositionService = new MousePositionService(this, mainHost, mainView);
            base.Updatables.Add(this.MousePositionService);

            this.SelectionService = new Client.SelectionService(this, mainHost, this.Camera);

            this.TerrainRenderer = ToDispose(new TerrainRenderer(this, this.Camera, this.ViewGridProvider));
            base.Updatables.Add(this.TerrainRenderer);
            mainView.Drawables.Add(this.TerrainRenderer);

            m_symbolRenderer = ToDispose(new SymbolRenderer(this, this.ViewGridProvider));
            base.Updatables.Add(m_symbolRenderer);
            mainView.Drawables.Add(m_symbolRenderer);

            m_selectionRenderer = ToDispose(new SelectionRenderer(this));
            base.Updatables.Add(m_selectionRenderer);
            mainView.Drawables.Add(m_selectionRenderer);

            m_designationRenderer = ToDispose(new DesignationRenderer(this));
            base.Updatables.Add(m_designationRenderer);
            mainView.Drawables.Add(m_designationRenderer);

            m_debugAxesRenderer = ToDispose(new DebugAxesRenderer(this));
            base.Updatables.Add(m_debugAxesRenderer);
            axesView.Drawables.Add(m_debugAxesRenderer);

#if OUTLINERENDERER
            m_outlineRenderer = ToDispose(new ChunkOutlineRenderer(this, this.TerrainRenderer.ChunkManager));
            base.Updatables.Add(m_outlineRenderer);
            mainView.Drawables.Add(m_outlineRenderer);
#endif

#if TESTCUBERENDERER
            m_testCubeRenderer = ToDispose(new TestCubeRenderer(this));
            base.Updatables.Add(m_testCubeRenderer);
            mainView.Drawables.Add(m_testCubeRenderer);
#endif

            this.RasterizerState = this.GraphicsDevice.RasterizerStates.CullBack;
        }
Beispiel #2
0
        public MyGame(MapControl3D mainHost)
        {
            //SharpDX.Configuration.EnableObjectTracking = true;

            this.Camera = new Camera();
            this.Camera.LookAt(new Vector3(4, 0, 0), new Vector3(0, 0, 0), Vector3.UnitZ);

            this.CameraMoveService = new CameraMoveService(this.Camera);
            base.Updatables.Add(this.CameraMoveService);

            this.ViewGridAdjusterService = new ViewGridAdjusterService(this, mainHost);
            base.Updatables.Add(this.ViewGridAdjusterService);

            this.ViewGridProvider = new ViewGridProvider(this);

            this.CameraKeyHandler = new CameraKeyHandler(this, mainHost);
            base.Updatables.Add(this.CameraKeyHandler);

            m_fpsCounter = new FPSCounter(this);
            base.Updatables.Add(m_fpsCounter);

            this.CursorService = new CursorService(this, mainHost);

            var mainView = new GameSurfaceView(this.GraphicsDevice)
            {
                Camera = this.Camera,
            };

            var axesView = new GameSurfaceView(this.GraphicsDevice)
            {
                Camera = this.Camera,
            };

            var surface = ToDispose(new GameSurface(this.GraphicsDevice, mainHost));

            surface.Views.Add(mainView);
            surface.Views.Add(axesView);

            surface.SizeChanged += (w, h) =>
            {
                var vp = new ViewportF(0, 0, w, h);
                mainView.ViewPort = vp;
                mainView.Camera.SetAspect(vp.AspectRatio);

                axesView.ViewPort = new ViewportF(0, 0, 50, 50);
            };

            base.Surfaces.Add(surface);

            this.MousePositionService = new MousePositionService(this, mainHost, mainView);
            base.Updatables.Add(this.MousePositionService);

            this.SelectionService = new Client.SelectionService(this, mainHost, this.Camera);

            this.TerrainRenderer = ToDispose(new TerrainRenderer(this, this.Camera, this.ViewGridProvider));
            base.Updatables.Add(this.TerrainRenderer);
            mainView.Drawables.Add(this.TerrainRenderer);

            m_symbolRenderer = ToDispose(new SymbolRenderer(this, this.ViewGridProvider));
            base.Updatables.Add(m_symbolRenderer);
            mainView.Drawables.Add(m_symbolRenderer);

            m_selectionRenderer = ToDispose(new SelectionRenderer(this));
            base.Updatables.Add(m_selectionRenderer);
            mainView.Drawables.Add(m_selectionRenderer);

            m_designationRenderer = ToDispose(new DesignationRenderer(this));
            base.Updatables.Add(m_designationRenderer);
            mainView.Drawables.Add(m_designationRenderer);

            m_debugAxesRenderer = ToDispose(new DebugAxesRenderer(this));
            base.Updatables.Add(m_debugAxesRenderer);
            axesView.Drawables.Add(m_debugAxesRenderer);

            #if OUTLINERENDERER
            m_outlineRenderer = ToDispose(new ChunkOutlineRenderer(this, this.TerrainRenderer.ChunkManager));
            base.Updatables.Add(m_outlineRenderer);
            mainView.Drawables.Add(m_outlineRenderer);
            #endif

            #if TESTCUBERENDERER
            m_testCubeRenderer = ToDispose(new TestCubeRenderer(this));
            base.Updatables.Add(m_testCubeRenderer);
            mainView.Drawables.Add(m_testCubeRenderer);
            #endif

            this.RasterizerState = this.GraphicsDevice.RasterizerStates.CullBack;
        }