< Summary

Class:GDX.Mathematics.Rotate
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Mathematics/Rotate.cs
Covered lines:0
Uncovered lines:7
Coverable lines:7
Total lines:40
Line coverage:0% (0 of 7)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:1
Method coverage:0% (0 of 1)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Towards(...)0%2100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Mathematics/Rotate.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System.Runtime.CompilerServices;
 6using Unity.Mathematics;
 7using UnityEngine;
 8
 9namespace GDX.Mathematics
 10{
 11    /// <summary>
 12    ///     A set of functionality to extend on Unity's rotation based methods.
 13    /// </summary>
 14    [VisualScriptingCompatible(8)]
 15    public static class Rotate
 16    {
 17#if !UNITY_DOTSRUNTIME
 18        /// <summary>
 19        ///     Create a quaternion based on a rotation from <paramref name="targetQuaternion" /> to
 20        ///     <paramref name="otherQuaternion" />.
 21        /// </summary>
 22        /// <param name="targetQuaternion">The source <see cref="Quaternion" />.</param>
 23        /// <param name="otherQuaternion">The destination <see cref="Quaternion" />.</param>
 24        /// <param name="rotationRate">How fast should the rotation occur.</param>
 25        /// <param name="elapsedTime">How long has elapsed since the rotation started.</param>
 26        /// <returns>A rotational value.</returns>
 27        /// <exception cref="UnsupportedRuntimeException">Not supported on DOTS Runtime.</exception>
 28        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 29        public static Quaternion Towards(Quaternion targetQuaternion, Quaternion otherQuaternion, float rotationRate,
 30            float elapsedTime)
 031        {
 032            float rotatedAmount = rotationRate * elapsedTime;
 033            Quaternion rotationDelta = Quaternion.Inverse(targetQuaternion) * otherQuaternion;
 034            rotationDelta.ToAngleAxis(out float rotatedAngle, out Vector3 axis);
 035            rotatedAngle = math.min(rotatedAngle, rotatedAmount);
 036            return targetQuaternion * Quaternion.AngleAxis(rotatedAngle, axis);
 037        }
 38#endif // !UNITY_DOTSRUNTIME
 39    }
 40}