Exemplo n.º 1
0
        private void InitializeGraphicsScreen()
        {
            Debug.Assert(GraphicsScreens.Count == 0, "Reset graphics screens before calling InitializeGraphicsScreen().");

            var services        = Document.Editor.Services;
            var graphicsService = services.GetInstance <IGraphicsService>().ThrowIfMissing();

            // Initialize graphics screens.
            var graphicsScreen = UseDeferredLighting
                                 ? (GraphicsScreen) new DeferredGraphicsScreen(services)
                                 : new BasicGraphicsScreen(services);

            GraphicsScreens.Add(graphicsScreen);
            GraphicsScreens.Add(new DebugGraphicsScreen(services));

            // Add default lighting.
            var scene = UseDeferredLighting
                        ? ((DeferredGraphicsScreen)graphicsScreen).Scene
                        : ((BasicGraphicsScreen)graphicsScreen).Scene;

            GameHelper.AddLights(scene);

            // Add a ground plane (useful for orientation and to check model shadows).
            if (_groundModelNode == null)
            {
                var content = services.GetInstance <ContentManager>().ThrowIfMissing();
                _groundModelNode = content.Load <ModelNode>("DigitalRune.Editor.Game/Models/Misc/GroundPlane/GroundPlane").Clone();
            }
            _groundModelNode.IsEnabled = ShowGroundPlane;
            scene.Children.Add(_groundModelNode);

            // Add camera.
            if (CameraNode == null)
            {
                var projection = new PerspectiveProjection();
                projection.SetFieldOfView(
                    ConstantsF.PiOver4,
                    graphicsService.GraphicsDevice.Viewport.AspectRatio,
                    0.1f,
                    10000.0f);
                CameraNode = new CameraNode(new Camera(projection))
                {
                    Name = "CameraPerspective",
                };
            }

            if (UseDeferredLighting)
            {
                ((DeferredGraphicsScreen)graphicsScreen).ActiveCameraNode = CameraNode;
            }
            else
            {
                ((BasicGraphicsScreen)graphicsScreen).CameraNode = CameraNode;
            }
        }