コード例 #1
0
        public static XMVector Inverse(XMVector q)
        {
            XMVector zero = XMVector.Zero;

            XMVector l         = XMVector4.LengthSquare(q);
            XMVector conjugate = XMQuaternion.Conjugate(q);

            XMVector control = XMVector.LessOrEqual(l, XMGlobalConstants.Epsilon);

            XMVector result = XMVector.Divide(conjugate, l);

            result = XMVector.Select(result, zero, control);

            return(result);
        }
コード例 #2
0
        public static XMVector ClampLengthV(XMVector v, XMVector lengthMin, XMVector lengthMax)
        {
            Debug.Assert(lengthMin.Y == lengthMin.X && lengthMin.Z == lengthMin.X && lengthMin.W == lengthMin.X, "Reviewed");
            Debug.Assert(lengthMax.Y == lengthMax.X && lengthMax.Z == lengthMax.X && lengthMax.W == lengthMax.X, "Reviewed");
            Debug.Assert(XMVector4.GreaterOrEqual(lengthMin, XMGlobalConstants.Zero), "Reviewed");
            Debug.Assert(XMVector4.GreaterOrEqual(lengthMax, XMGlobalConstants.Zero), "Reviewed");
            Debug.Assert(XMVector4.GreaterOrEqual(lengthMax, lengthMin), "Reviewed");

            XMVector lengthSq         = XMVector4.LengthSquare(v);
            XMVector zero             = XMVector.Zero;
            XMVector reciprocalLength = lengthSq.ReciprocalSqrt();

            XMVector infiniteLength = XMVector.EqualInt(lengthSq, XMGlobalConstants.Infinity);
            XMVector zeroLength     = XMVector.Equal(lengthSq, zero);

            XMVector normal = XMVector.Multiply(v, reciprocalLength);
            XMVector length = XMVector.Multiply(lengthSq, reciprocalLength);

            XMVector select = XMVector.EqualInt(infiniteLength, zeroLength);

            length = XMVector.Select(lengthSq, length, select);
            normal = XMVector.Select(lengthSq, normal, select);

            XMVector controlMax = XMVector.Greater(length, lengthMax);
            XMVector controlMin = XMVector.Less(length, lengthMin);

            XMVector clampLength = XMVector.Select(length, lengthMax, controlMax);

            clampLength = XMVector.Select(clampLength, lengthMin, controlMin);

            XMVector result = XMVector.Multiply(normal, clampLength);

            // Preserve the original vector (with no precision loss) if the length falls within the given range
            XMVector control = XMVector.EqualInt(controlMax, controlMin);

            result = XMVector.Select(result, v, control);

            return(result);
        }
コード例 #3
0
 public static XMVector Length(XMVector v)
 {
     return(XMVector4
            .LengthSquare(v)
            .Sqrt());
 }
コード例 #4
0
 public static XMVector ReciprocalLength(XMVector v)
 {
     return(XMVector4
            .LengthSquare(v)
            .ReciprocalSqrt());
 }
コード例 #5
0
 public static XMVector LengthSquare(XMVector q)
 {
     return(XMVector4.LengthSquare(q));
 }