public override void VTSUpdate(double interpolationHd, float interpolationLd, float elapsedTime)
        {
            if (_player == null)
            {
                return;
            }

            // update model color, get the cube where model is
            var result = _chunkContainer.GetCube(_player.Position);

            if (result.IsValid && result.Cube.Id == WorldConfiguration.CubeId.Air)
            {
                // we take the max color
                var sunPart     = (float)result.Cube.EmissiveColor.A / 255;
                var sunColor    = _skyDome.SunColor * sunPart;
                var resultColor = Color3.Max(result.Cube.EmissiveColor.ToColor3(), sunColor);

                _lightColor.Value = resultColor;

                if (_lightColor.ValueInterp != _lightColor.Value)
                {
                    Color3.Lerp(ref _lightColor.ValueInterp, ref _lightColor.Value, elapsedTime * 10.0f, out _lightColor.ValueInterp);
                }
            }

            // play animation
            if (_animation)
            {
                const float speed = 21f;
                if (elapsedTime == 0.0f)
                {
                    elapsedTime = 0.0001f;
                }
                Quaternion finalRotation = Quaternion.RotationYawPitchRoll(0, MathHelper.PiOver2, 0);
                Vector3    finalOffset   = new Vector3(0, 0, 2);

                if (_animationStated)
                {
                    Quaternion.Slerp(ref _animationRotation, ref finalRotation, (float)elapsedTime * speed, out _animationRotation);
                    Vector3.Lerp(ref _animationOffset, ref finalOffset, (float)elapsedTime * speed, out _animationOffset);

                    if (_animationRotation.EqualsEpsilon(finalRotation, 0.1f))
                    {
                        _animationStated = false;
                    }
                }
                else
                {
                    var identity   = Quaternion.Identity;
                    var nullOffset = new Vector3();
                    Quaternion.Slerp(ref _animationRotation, ref identity, (float)elapsedTime * speed, out _animationRotation);
                    Vector3.Lerp(ref _animationOffset, ref nullOffset, (float)elapsedTime * speed, out _animationOffset);
                }

                if (_animationRotation == Quaternion.Identity)
                {
                    _animation = false;
                }
            }
        }
Esempio n. 2
0
        private void DrawStaticEntities(DeviceContext context, VisualChunk chunk)
        {
            //For Each different entity Model
            foreach (var pair in chunk.AllPairs())
            {
                // For each instance of the model - update data
                foreach (var staticEntity in pair.Value)
                {
                    //The staticEntity.Color is affected at entity creation time in the LightingManager.PropagateLightInsideStaticEntities(...)
                    var sunPart     = (float)staticEntity.BlockLight.A / 255;
                    var sunColor    = Skydome.SunColor * sunPart;
                    var resultColor = Color3.Max(staticEntity.BlockLight.ToColor3(), sunColor);
                    staticEntity.VoxelEntity.ModelInstance.LightColor    = resultColor;
                    staticEntity.VoxelEntity.ModelInstance.SunLightLevel = sunPart;
                    if (!DrawStaticInstanced)
                    {
                        if (IsEntityVisible(staticEntity.Entity.Position))
                        {
                            var sw = Stopwatch.StartNew();
                            staticEntity.VisualVoxelModel.Draw(context, _voxelModelEffect, staticEntity.VoxelEntity.ModelInstance);
                            sw.Stop();
                            _staticEntityDrawTime += sw.Elapsed.TotalMilliseconds;
                            _staticEntityDrawCalls++;
                        }
                    }
                }

                if (DrawStaticInstanced)
                {
                    if (pair.Value.Count == 0)
                    {
                        continue;
                    }
                    var entity = pair.Value.First();
                    var sw     = Stopwatch.StartNew();
                    entity.VisualVoxelModel.DrawInstanced(context, _voxelModelInstancedEffect, pair.Value.Where(ve => IsEntityVisible(ve.Entity.Position)).Select(ve => ve.VoxelEntity.ModelInstance).ToList());
                    sw.Stop();
                    _staticEntityDrawTime += sw.Elapsed.TotalMilliseconds;
                    _staticEntityDrawCalls++;
                }
            }
        }
        public override void VTSUpdate(double interpolationHd, float interpolationLd, float elapsedTime)
        {
            foreach (var entity in _dynamicEntitiesDico.Values)
            {
                entity.Interpolation(interpolationHd, interpolationLd, elapsedTime);

                // update model color, get the cube where model is
                var result = _chunkContainer.GetCube(entity.WorldPosition.ValueInterp);
                if (result.IsValid && result.Cube.Id == WorldConfiguration.CubeId.Air)
                {
                    // we take the max color
                    var sunPart     = (float)result.Cube.EmissiveColor.A / 255;
                    var sunColor    = _skyDome.SunColor * sunPart;
                    var resultColor = Color3.Max(result.Cube.EmissiveColor.ToColor3(), sunColor);

                    entity.ModelLight.Value = resultColor;

                    if (entity.ModelLight.ValueInterp != entity.ModelLight.Value)
                    {
                        Color3.Lerp(ref entity.ModelLight.ValueInterp, ref entity.ModelLight.Value, elapsedTime * 10.0f, out entity.ModelLight.ValueInterp);
                    }
                }
            }
        }