Esempio n. 1
0
        private IEnumerator AnimateCamera(Vector3 position, Quaternion rotation, Vector3 pivot)
        {
            var angle             = rotation.AngleTo(_rotation);
            var totalTimeAngle    = (0.1f * angle) / 90;
            var totalTimeDistance = (pivot - _pivot).Length() * 0.003;

            var totalTime = (float)Math.Max(totalTimeAngle, totalTimeDistance);

            Debug.WriteLine($"time angle: {totalTimeAngle} time dist {totalTimeDistance}");
            var time               = 0.0f;
            var originalPivot      = _pivot;
            var originalRotation   = _rotation;
            var targetRotation     = rotation;
            var distanceFromOrigin = (_position - _pivot).Length();

            while (time < totalTime)
            {
                var lerpFactor = time / totalTime;

                var newPivot    = Vector3.Lerp(originalPivot, pivot, lerpFactor);
                var newRotation = Quaternion.Slerp(originalRotation, targetRotation, lerpFactor);

                var newUnitPosition = Vector3.Transform(-Vector3.UnitZ, newRotation);
                var newPosition     = newPivot + newUnitPosition * distanceFromOrigin;

                MoveCamera(newPosition, newRotation, newPivot);

                time += (float)_coroutines.DeltaTime;

                yield return(null);
            }
            MoveCamera(position, rotation, pivot);
        }
Esempio n. 2
0
        private void InterpolateKeys(double animationTime, AnimationLayer layer, ref Quaternion rotation, ref Vector3 translation, ref Vector3 scale, PRSKey prsKey, PRSKey nextPrsKey)
        {
            var nextTime = (nextPrsKey.Time < prsKey.Time
                ? (nextPrsKey.Time + Animation.Duration)
                : nextPrsKey.Time);

            var blend = ( float )(animationTime / nextTime);

            if (prsKey.HasRotation)
            {
                rotation = Quaternion.Slerp(prsKey.Rotation, nextPrsKey.Rotation, blend);
            }

            if (prsKey.HasPosition)
            {
                translation = Vector3.Lerp(prsKey.Position * layer.PositionScale,
                                           nextPrsKey.Position * layer.PositionScale,
                                           blend);
            }

            if (prsKey.HasScale)
            {
                scale = Vector3.Lerp(prsKey.Scale * layer.ScaleScale,
                                     nextPrsKey.Scale * layer.ScaleScale,
                                     blend);
            }
        }