Ejemplo n.º 1
0
        /// <summary>
        /// Render all lines added this frame
        /// </summary>
        public void Render(LineManager3DLines nLines)
        {
            nLines.UpdateVertexBuffer();
            // Need to build vertex buffer?


            // Render lines if we got any lines to render
            if (nLines.NumOfPrimitives > 0)
            {
                try
                {
                    //engine.ActiveCamera.CameraInfo.WorldMatrix = Matrix.Identity;
                    //BaseGame.AlphaBlending = true;
                    shader.WorldViewProjection = game.Camera.ViewProjection;

                    game.GraphicsDevice.RenderState.AlphaBlendEnable  = true;
                    game.GraphicsDevice.RenderState.DepthBufferEnable = true;
                    game.GraphicsDevice.VertexDeclaration             = decl;
                    shader.RenderMultipass(
                        delegate
                    {
                        game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, nLines.LineVertices, 0, nLines.NumOfPrimitives);
                    });
                } // try
                catch (Exception ex)
                {
                    /*Log.Write(
                     *  "LineManager3D.Render failed. numOfPrimitives=" + numOfPrimitives +
                     *  ", numOfLines=" + numOfLines + ". Error: " + ex.ToString() );*/
                    throw ex;
                } // catch (ex)
            }     // if (numOfVertices)
        }         // Render()
Ejemplo n.º 2
0
        /// <summary>
        /// Init LineManager
        /// TODO: this class should be adapted so that it can be fully created even when the device isn't fully initialized.
        /// </summary>
        public LineManager3D(IXNAGame nGame)
        {
            game = nGame;

            /*if ( HoofdObject.XNAGame.Graphics.GraphicsDevice  == null )
             *  throw new NullReferenceException(
             *      "XNA device is not initialized, can't init line manager." );*/

            lines = new LineManager3DLines();

            //shader = BasicShader.LoadFromFXFile( game, game.EngineFiles.LineRenderingShader );
            shader = BasicShader.LoadFromFXFile(game, game.EngineFiles.GetLineRenderingShaderStream(), null);
            shader.SetTechnique("LineRendering3D");

            decl        = new VertexDeclaration(game.GraphicsDevice, VertexPositionColor.VertexElements);
            WorldMatrix = Matrix.Identity;
        } // LineManager()