Пример #1
0
        /// <summary>
        /// Enumerates all possible entities for picking
        /// </summary>
        /// <returns></returns>
        private IEnumerable <VisualVoxelEntity> PossibleEntities()
        {
            foreach (var containers in DynamicEntityManager.DynamicEntities)
            {
                if (_worldChunks.IsEntityVisible(containers.Entity.Position))
                {
                    yield return(containers);
                }
            }

            foreach (var visibleChunk in _worldChunks.VisibleChunks().Where(c => c.DistanceFromPlayer < 32))
            {
                foreach (var visualEntity in visibleChunk.AllEntities())
                {
                    if (_worldChunks.IsEntityVisible(visualEntity.Entity.Position))
                    {
                        yield return(visualEntity);
                    }
                }
            }
        }
Пример #2
0
        public override void Draw(DeviceContext context, int index)
        {
            RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Enabled, DXStates.DepthStencils.DepthReadEnabled);

            foreach (var chunk in _worldChunks.GetChunks(WorldChunks.GetChunksFilter.VisibleWithinStaticObjectRange))
            {
                if (chunk.DistanceFromPlayer > _worldChunks.StaticEntityViewRange)
                {
                    break;                                                                //Limit the crack drawing to the same zone as the static entity visualization
                }
                foreach (var pair in chunk.BlockData.GetTags().Where(p => p.Value is DamageTag && _worldChunks.IsEntityVisible(p.Key)))
                {
                    var tag = (DamageTag)pair.Value;

                    var pos = BlockHelper.ConvertToGlobal(chunk.Position, pair.Key);

                    var list = new List <Vector3I>(new[] { new Vector3I(1, 0, 0), new Vector3I(-1, 0, 0), new Vector3I(0, 1, 0), new Vector3I(0, -1, 0), new Vector3I(0, 0, 1), new Vector3I(0, 0, -1) });

                    var result = list.Select(v => v + pos).Select(v => _cubesHolder.GetCube(v).Cube.EmissiveColor.ToColor4()).Aggregate((s, c) => s + c);
                    result.Red   /= 6;
                    result.Green /= 6;
                    result.Blue  /= 6;
                    result.Alpha /= 6;

                    result.Red   = Math.Max(result.Red, result.Alpha * _skyDome.SunColor.Red);
                    result.Green = Math.Max(result.Green, result.Alpha * _skyDome.SunColor.Green);
                    result.Blue  = Math.Max(result.Blue, result.Alpha * _skyDome.SunColor.Blue);

                    _cubeEffect.Begin(context);
                    _cubeEffect.CBPerDraw.Values.TextureIndex   = 5 - 5 * tag.Strength / tag.TotalStrength;
                    _cubeEffect.CBPerDraw.Values.World          = Matrix.Transpose(Matrix.Scaling(1.01f) * Matrix.Translation(pos + new Vector3(0.5f)));
                    _cubeEffect.CBPerDraw.Values.ViewProjection = Matrix.Transpose(_cameraManager.ActiveCamera.ViewProjection3D);
                    _cubeEffect.CBPerDraw.Values.LightColor     = new Color3(result.ToVector3()); // Color3.White;
                    _cubeEffect.CBPerDraw.IsDirty = true;
                    _cubeEffect.Apply(context);

                    _cubeVb.SetToDevice(context, 0);
                    _cubeIb.SetToDevice(context, 0);

                    context.DrawIndexed(_cubeIb.IndicesCount, 0, 0);
                }
            }

            base.Draw(context, index);
        }