예제 #1
0
 private void Draw()
 {
     d3dDeviceContext.ClearRenderTargetView(renderTargetView, new SharpDX.Color(32, 103, 178));
     d3dDeviceContext.InputAssembler.SetVertexBuffers(0, new SharpDX.Direct3D11.VertexBufferBinding(triangleVertexBuffer, SharpDX.Utilities.SizeOf <SharpDX.Vector3>(), 0));
     d3dDeviceContext.InputAssembler.SetIndexBuffer(idexBuffer, SharpDX.DXGI.Format.R32_UInt, 0);
     d3dDeviceContext.PixelShader.SetConstantBuffer(0, constBuffer);
     d3dDeviceContext.DrawIndexed(indexes.Count(), 0, 0);
     swapChain.Present(1, SharpDX.DXGI.PresentFlags.None);
 }
예제 #2
0
        public override void Draw(SharpDX.Direct3D11.DeviceContext context, int index)
        {
            RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled);

            if (_bufferDirty)
            {
                _vb.SetData(context, _letreeVertexCollection.ToArray());
                _ib.SetData(context, _letreeIndexCollection.ToArray());

                _bufferDirty = false;
            }

            _shader.Begin(context);
            _shader.CBPerFrame.Values.ViewProjection = Matrix.Transpose(_cameraManager.ActiveCamera.ViewProjection3D);
            _shader.CBPerFrame.IsDirty = true;

            _shader.CBPerDraw.Values.World = Matrix.Transpose(Matrix.RotationQuaternion(rotationQ.ValueInterp));
            _shader.CBPerDraw.IsDirty      = true;
            _shader.Apply(context);

            _vb.SetToDevice(context, 0);
            _ib.SetToDevice(context, 0);

            context.DrawIndexed(_ib.IndicesCount, 0, 0);

            //Draw text
            _spriteRenderer.Begin(false, context);

            Vector2   positionText = new Vector2(0, 0);
            ByteColor color        = Color.White;

            string info = "[R] Toggle rotation; [T] New generation";

            info += Environment.NewLine + "Blocks quantity : " + _letreeIndexCollection.Count / 36;
            info += Environment.NewLine + "Tree size : " + (MaxtreeSize.X - MintreeSize.X + 1).ToString("X : 00 ") + (MaxtreeSize.Y - MintreeSize.Y + 1).ToString("Y : 00 ") + (MaxtreeSize.Z - MintreeSize.Z + 1).ToString("Z : 00 ");
            if (_newTemplate != null)
            {
                info += Environment.NewLine + "Axiome : " + _newTemplate.Axiom;
            }

            _spriteRenderer.DrawText(_font, info, ref positionText, ref color, -1, -1, SpriteRenderer.TextFontPosition.RelativeToFontUp);

            _spriteRenderer.End(context);
        }
예제 #3
0
        public override void Draw(SharpDX.Direct3D11.DeviceContext context, int index)
        {
            var playerManager = _playerManager as GodEntityManager;

            if (playerManager == null)
            {
                throw new InvalidOperationException("Use this component only with GodEntityManager or disable it");
            }

            RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthReadEnabled);

            _cubeShader.Begin(context);
            _cubeShader.CBPerFrame.Values.View       = Matrix.Transpose(_cameraManager.ActiveCamera.View);
            _cubeShader.CBPerFrame.Values.Projection = Matrix.Transpose(_cameraManager.ActiveCamera.Projection);
            _cubeShader.CBPerFrame.IsDirty           = true;

            _staticBlockVB.SetToDevice(context, 0);
            _staticBlockIB.SetToDevice(context, 0);

            _cubeShader.CBPerDraw.Values.Color = new Color4(0, 0, 1f, 0.2f);

            var range = playerManager.HoverRange;

            var select = playerManager.Selection;

            var hoverBlocks = range.HasValue && select?range.Value.ToList() : null;

            foreach (var digDes in playerManager.Faction.Designations.OfType <DigDesignation>())
            {
                if (hoverBlocks != null && hoverBlocks.Contains(digDes.BlockPosition))
                {
                    hoverBlocks.Remove(digDes.BlockPosition);
                }

                if (!select && range.HasValue && range.Value.Contains(digDes.BlockPosition))
                {
                    continue;
                }

                var cube = _cubesHolder.GetCube(digDes.BlockPosition);

                if (cube.IsValid && cube.Cube.Id != WorldConfiguration.CubeId.Air)
                {
                    _cubeShader.CBPerDraw.Values.World = Matrix.Transpose(Matrix.Scaling(1.01f) * Matrix.Translation(digDes.BlockPosition + new Vector3(0.5f)));
                    _cubeShader.CBPerDraw.IsDirty      = true;
                    _cubeShader.Apply(context);
                    context.DrawIndexed(_staticBlockIB.IndicesCount, 0, 0);
                }
            }

            if (hoverBlocks != null)
            {
                foreach (var hoverBlock in hoverBlocks)
                {
                    var cube = _cubesHolder.GetCube(hoverBlock);

                    if (cube.IsValid && cube.Cube.Id != WorldConfiguration.CubeId.Air)
                    {
                        _cubeShader.CBPerDraw.Values.World = Matrix.Transpose(Matrix.Scaling(1.01f) * Matrix.Translation(hoverBlock + new Vector3(0.5f)));
                        _cubeShader.CBPerDraw.IsDirty      = true;
                        _cubeShader.Apply(context);
                        context.DrawIndexed(_staticBlockIB.IndicesCount, 0, 0);
                    }
                }
            }

            base.Draw(context, index);
        }