Ejemplo n.º 1
0
        public override void Render(TargetBase render)
        {
            base.Render(render);
            var context = render.DeviceManager.ContextDirect3D;

            var width = render.RenderTargetSize.Width;
            var height = render.RenderTargetSize.Height;

            // Prepare matrices
            var view = SharpDX.Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY);
            var proj = SharpDX.Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)(width / height), 0.1f, 100.0f);
            var viewProj = SharpDX.Matrix.Multiply(view, proj);

            var time = (float)(this.clock.ElapsedMilliseconds / 1000.0);

            // Set targets (This is mandatory in the loop)
            context.OutputMerger.SetTargets(render.DepthStencilView, render.RenderTargetView);

            // Clear the views
            context.ClearDepthStencilView(render.DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);
            if (this.EnableClear)
            {
                context.ClearRenderTargetView(render.RenderTargetView, Color.Black);
            }

            if (this.ShowCube)
            {
                // Calculate WorldViewProj
                var worldViewProj = SharpDX.Matrix.Scaling((float)this.Scale) * SharpDX.Matrix.RotationX((float)this.RotationSpeed * time)
                                    * SharpDX.Matrix.RotationY((float)this.RotationSpeed * time * 2.0f) * SharpDX.Matrix.RotationZ((float)this.RotationSpeed * time * .7f)
                                    * viewProj;
                worldViewProj.Transpose();

                // Setup the pipeline
                context.InputAssembler.SetVertexBuffers(0, this.vertexBufferBinding);
                context.InputAssembler.InputLayout = this.layout;
                context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                context.VertexShader.SetConstantBuffer(0, this.constantBuffer);
                context.VertexShader.Set(this.vertexShader);
                context.PixelShader.Set(this.pixelShader);

                // Update Constant Buffer
                context.UpdateSubresource(ref worldViewProj, this.constantBuffer, 0);

                // Draw the cube
                context.Draw(36, 0);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Renders the model.
 /// </summary>
 /// <param name="render">The render.</param>
 private void Render(TargetBase render)
 {
     foreach (Element3D e in this.Items)
     {
         e.Render(render);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Renders the element.
 /// </summary>
 /// <param name="render">The render.</param>
 public virtual void Render(TargetBase render)
 {
 }