Quaternions.cs 981 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. namespace FirstGearGames.Utilities.Maths
  3. {
  4. public static class Quaternions
  5. {
  6. /// <summary>
  7. /// Returns if a rotational value matches another. This method is preferred over Equals or == since those variations allow larger differences before returning false.
  8. /// </summary>
  9. /// <param name="r"></param>
  10. /// <param name="target"></param>
  11. /// <param name="distance"></param>
  12. /// <returns></returns>
  13. public static bool Matches(this Quaternion r, Quaternion target, float? distance = null)
  14. {
  15. if (distance == null)
  16. {
  17. return (r.w == target.w && r.x == target.x && r.y == target.y && r.z == target.z);
  18. }
  19. else
  20. {
  21. float a = Vector3.SqrMagnitude(r.eulerAngles - target.eulerAngles);
  22. return (a <= (distance * distance));
  23. }
  24. }
  25. }
  26. }