Guest User

Untitled

a guest
Dec 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. public static class QuaternionExtensions {
  2.  
  3. //-----------------------------------------------------------------------------------------
  4. // Public Methods:
  5. //-----------------------------------------------------------------------------------------
  6.  
  7. /// <summary>Returns a <c>Quaternion</c> with the same orientation but with a magnitude of 1.</summary>
  8. public static Quaternion Normalise(this Quaternion self) {
  9.  
  10. // work out the magnitude, and if it's too small, return identity.
  11. float magnitude = Mathf.Sqrt(Quaternion.Dot(self, self));
  12. if (magnitude < Mathf.Epsilon) return Quaternion.identity;
  13.  
  14. return new Quaternion(self.x / magnitude, self.y / magnitude, self.z / magnitude, self.w / magnitude);
  15. }
  16. }
Add Comment
Please, Sign In to add comment