예제 #1
0
        public override void Draw(DeviceContext context, int index)
        {
            base.Draw(context, index);

            _rotatingBlockVB.SetToDevice(context, 0);
            _rotatingBlockIB.SetToDevice(context, 0);

            _cubeShader.Begin(context);
            _cubeShader.CBPerFrame.Values.View                  = Matrix.Transpose(_view);
            _cubeShader.CBPerFrame.Values.Projection            = Matrix.Transpose(_engine.Projection2D);
            _cubeShader.CBPerFrame.Values.DiffuseLightDirection = new Vector3(0.8f, 0.9f, 0.9f);
            _cubeShader.CBPerFrame.IsDirty = true;

            _cubeShader.CBPerDraw.Values.World = Matrix.Transpose(_loadingCube.World);
            _cubeShader.CBPerDraw.Values.Color = _loadingCube.CubeColor;
            _cubeShader.CBPerDraw.IsDirty      = true;
            _cubeShader.Apply(context);
            context.DrawIndexed(_rotatingBlockIB.IndicesCount, 0, 0);
        }
예제 #2
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);
        }