Пример #1
0
        /// <summary>
        /// If length of this vector is greater then specified value, then downscales this vector to
        /// make its length match given value.
        /// </summary>
        /// <param name="maxLength"> Maximal length this vector should have. </param>
        public void ClampLength(float maxLength)
        {
            float sqrLength = this.LengthSquared;

            if (sqrLength > (maxLength * maxLength))
            {
                var scale = maxLength * MathHelpers.ReciprocalSquareRoot(sqrLength);
                this.X *= scale;
                this.Y *= scale;
                this.Z *= scale;
            }
        }
Пример #2
0
        /// <summary>
        /// Normalizes this quaternion or just sets it to identity if its too small.
        /// </summary>
        /// <see cref="Quaternion.Identity"/>
        public void NormalizeSafe()
        {
            float d = this.W * this.W + this.V.X * this.V.X + this.V.Y * this.V.Y + this.V.Z * this.V.Z;

            if (d > 1e-8f)
            {
                d       = MathHelpers.ReciprocalSquareRoot(d);
                this.W *= d; this.V.X *= d; this.V.Y *= d; this.V.Z *= d;
            }
            else
            {
                this.SetIdentity();
            }
        }
Пример #3
0
        /// <summary>
        /// Normalizes this quaternion.
        /// </summary>
        public void Normalize()
        {
            float d = MathHelpers.ReciprocalSquareRoot(this.W * this.W + this.V.X * this.V.X + this.V.Y * this.V.Y + this.V.Z * this.V.Z);

            this.W *= d; this.V.X *= d; this.V.Y *= d; this.V.Z *= d;
        }
Пример #4
0
        /// <summary>
        /// Normalizes this vector.
        /// </summary>
        public void Normalize()
        {
            float fInvLen = MathHelpers.ReciprocalSquareRoot(this.X * this.X + this.Y * this.Y + this.Z * this.Z);

            this.X *= fInvLen; this.Y *= fInvLen; this.Z *= fInvLen;
        }