Example #1
0
        /// <summary>
        /// update cameras.
        /// </summary>
        public void Update(GameTime gameTime)
        {
            // Update the current camera
            ViewCamera viewCamera = CurrentCamera;

            for (int i = 0; i < viewCamera.Count; i++)
            {
                CameraBase camera = viewCamera.GetCamera(i);
                camera.Update(gameTime);
            }

            // Update scene models in the render context
            renderContext.Update(gameTime);
        }
        /// <summary>
        /// draws every scene node which is attached to the scene node.
        /// Draws in order of 3D scene node, 2D scene node, and overlay text.
        /// When there are more than one view cameras that have registered
        /// to the 3D scene, Viewport is applied to the 3D scene node,
        /// which is drawn as many as the number of the view camera.
        /// When render event handler has been registered, it is called
        /// before or after drawing.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            //  Set to render information
            renderTracer.Device      = FrameworkCore.Game.GraphicsDevice;
            renderTracer.GameTime    = gameTime;
            renderTracer.SpriteBatch = SpriteBatch;
            renderTracer.Fog         = FrameworkCore.Viewer.BasicFog;
            renderTracer.Lighting    = FrameworkCore.Viewer.BasicLighting;

            ClearBackBuffer();

            if (RenderingPreDrawScene != null)
            {
                RenderingPreDrawScene(this, EventArgs.Empty);
            }

            //  3D Render
            {
                if (RenderingPreDraw3D != null)
                {
                    RenderingPreDraw3D(this, EventArgs.Empty);
                }

                //  process multiple camera
                for (int i = 0; i < FrameworkCore.CurrentCamera.Count; i++)
                {
                    ViewCamera viewCamera = FrameworkCore.Viewer.CurrentCamera;
                    CameraBase camera     = viewCamera.GetCamera(i);

                    renderTracer.View       = camera.ViewMatrix;
                    renderTracer.ViewInvert = Matrix.Invert(camera.ViewMatrix);
                    renderTracer.Projection = camera.ProjectionMatrix;

                    // Update frustum
                    UpdateFrustum(camera.ViewMatrix, camera.ProjectionMatrix);
                    renderTracer.Frustum = this.Frustum;

                    //  Set to each viewport
                    ApplyViewport(viewCamera.GetViewport(i));

                    //  Render the 3D scene
                    Draw3D(renderTracer);
                }

                //  restore to default viewport
                ApplyViewport(FrameworkCore.DefaultViewport);

                if (RenderingPostDraw3D != null)
                {
                    RenderingPostDraw3D(this, EventArgs.Empty);
                }
            }

            //  2D Render
            {
                if (RenderingPreDraw2D != null)
                {
                    RenderingPreDraw2D(this, EventArgs.Empty);
                }

                //  Render the 2D scene
                Draw2D(renderTracer);

                if (RenderingPostDraw2D != null)
                {
                    RenderingPostDraw2D(this, EventArgs.Empty);
                }
            }

            if (RenderingPostDrawScene != null)
            {
                RenderingPostDrawScene(this, EventArgs.Empty);
            }

            // Display overlaped texts or others
            DrawOverlayText(gameTime);

            // Draw other components
            base.Draw(gameTime);
        }