Ejemplo n.º 1
0
        internal void Update(RtsCameraController camera, GameTime gameTime)
        {
            var currentTimeFraction = (float)((gameTime.TotalGameTime - _startTime).TotalSeconds / _duration.TotalSeconds);

            currentTimeFraction = Math.Min(currentTimeFraction, 1);

            var pos          = currentTimeFraction * (_points.Count - 1);
            var integralPart = (int)Math.Truncate(pos);
            var decimalPart  = pos - integralPart;

            // TODO: Not sure how right this is
            // Near the end of the path 2-3 points are the same, so the movement becomes more linear?
            var point1 = integralPart;
            var point2 = Math.Min(point1 + 1, _points.Count - 1);
            var point0 = Math.Max(point1 - 1, 0);
            var point3 = Math.Min(point2 + 1, _points.Count - 1);

            camera.TerrainPosition = Interpolation.CatmullRom(
                _points[point0],
                _points[point1],
                _points[point2],
                _points[point3],
                decimalPart);

            if (_lookToward != null)
            {
                var lookDirection = Vector3.Normalize(_lookToward.Value - camera.TerrainPosition);
                camera.SetLookDirection(lookDirection);
            }
            else if (_endDirection != null)
            {
                var lookDirection = Vector3.Normalize(Vector3Utility.Slerp(_startDirection, _endDirection.Value, currentTimeFraction));

                camera.SetLookDirection(lookDirection);
            }

            if (_endPitch != null)
            {
                var pitch = MathUtility.Lerp(_startPitch, _endPitch.Value, currentTimeFraction);

                camera.Pitch = pitch;
            }

            if (_endZoom != null)
            {
                var zoom = MathUtility.Lerp(_startZoom, _endZoom.Value, currentTimeFraction);

                camera.Zoom = zoom;
            }

            if (gameTime.TotalGameTime > _endTime)
            {
                Finished = true;
            }
        }