Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class QuaternionExtensions {
- //-----------------------------------------------------------------------------------------
- // Public Methods:
- //-----------------------------------------------------------------------------------------
- /// <summary>Returns a <c>Quaternion</c> with the same orientation but with a magnitude of 1.</summary>
- public static Quaternion Normalise(this Quaternion self) {
- // work out the magnitude, and if it's too small, return identity.
- float magnitude = Mathf.Sqrt(Quaternion.Dot(self, self));
- if (magnitude < Mathf.Epsilon) return Quaternion.identity;
- return new Quaternion(self.x / magnitude, self.y / magnitude, self.z / magnitude, self.w / magnitude);
- }
- }
Add Comment
Please, Sign In to add comment