Exemple #1
0
        internal void Draw(VertexDeclaration vertexDeclaration, RenderSettings settings, IEnumerable<IDecorator> decorators)
        {
            _device.VertexDeclaration = vertexDeclaration;

            foreach (IDecorator decorator in decorators)
                decorator.OnBeginDrawMesh(this, settings);

            _device.SetStreamSource(0, _vertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
            _device.Indices = _indexBuffer;

            _effect.LightDirection = settings.Parameters.LightDirection;
            _effect.View = settings.ViewMatrix;
            _effect.Projection = settings.ProjectionMatrix;

            int passes = _effect.Begin();
            for (int i = 0; i < passes; i++)
            {
                _effect.BeginPass(i);

                _device.DrawIndexedPrimitives(
                    PrimitiveType.TriangleList, 0, 0, _numVertices,
                    0, _primitiveCount);

                _effect.EndPass();
            }
            _effect.End();

            foreach (IDecorator decorator in decorators)
                decorator.OnEndDrawMesh(this, settings);
        }
Exemple #2
0
        internal void Draw(RenderSettings settings)
        {
            IEnumerable<IDecorator> activeDecorators = GetActiveDecorators(settings);
            foreach (IDecorator decorator in activeDecorators)
                decorator.OnBeginDrawModel(this, settings, activeDecorators);

            DrawInternal(settings, activeDecorators);

            foreach (IDecorator decorator in activeDecorators)
                decorator.OnEndDrawModel(this, settings);
        }
Exemple #3
0
        public void Render(RenderParameters parameters)
        {
            RenderSettings renderSettings = new RenderSettings();
            renderSettings.ProjectionMatrix = _projection;
            renderSettings.ViewMatrix = Matrix3D.Invert(_cameraTransform.Value) * _view;
            renderSettings.Parameters = parameters;

            IoC.Get<IStatusBar>().Message = "Camera Location: " + renderSettings.ViewMatrix.Translation;

            _device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new ColorF(0.3f, 0.3f, 0.3f).ToColorBGRA(), 1.0f, 0);
            _device.BeginScene();

            _model.Draw(renderSettings);

            _device.EndScene();
        }
Exemple #4
0
        internal void DrawInternal(RenderSettings settings, IEnumerable<IDecorator> decorators)
        {
            _device.SetRenderState(RenderState.ZEnable, true);
            _device.SetRenderState(RenderState.ZWriteEnable, true);

            // Draw opaque objects first.
            foreach (ModelMesh modelMesh in Meshes.Where(m => m.Opaque))
                modelMesh.Draw(_vertexDeclaration, settings, decorators);

            _device.SetRenderState(RenderState.ZWriteEnable, false);

            // Draw transparent objects. TODO: Sort by distance from camera and draw from back to front.
            _device.SetRenderState(RenderState.AlphaBlendEnable, true);
            _device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
            _device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
            foreach (ModelMesh modelMesh in Meshes.Where(m => !m.Opaque))
                modelMesh.Draw(_vertexDeclaration, settings, decorators);
            _device.SetRenderState(RenderState.AlphaBlendEnable, false);

            _device.SetRenderState(RenderState.ZWriteEnable, true);
        }
Exemple #5
0
 private IEnumerable<IDecorator> GetActiveDecorators(RenderSettings settings)
 {
     return _decorators.Where(d => d.IsActive(settings));
 }