Función XMVector4Normalize (directxmath.h)

Devuelve la versión normalizada de un vector 4D.

Sintaxis

XMVECTOR XM_CALLCONV XMVector4Normalize(
  [in] FXMVECTOR V
) noexcept;

Parámetros

[in] V

Vector 4D.

Valor devuelto

Devuelve la versión normalizada de V.

Comentarios

Para un vector de longitud 0, esta función devuelve un vector cero. Para un vector con longitud infinita, devuelve un vector de QNaN.

Tenga en cuenta que para la mayoría de las aplicaciones gráficas, asegurarse de que los vectores tienen longitudes bien definidas que no causan problemas para la normalización es una práctica común. Sin embargo, si necesita una normalización sólida que funcione para todas las entradas de punto flotante, puede usar el código siguiente en su lugar:


inline XMVECTOR XMVector4NormalizeRobust( FXMVECTOR V )
{
    // Compute the maximum absolute value component.
    XMVECTOR vAbs = XMVectorAbs(V);
    XMVECTOR max0 = XMVectorSplatX(vAbs);
    XMVECTOR max1 = XMVectorSplatY(vAbs);
    XMVECTOR max2 = XMVectorSplatZ(vAbs);
    XMVECTOR max3 = XMVectorSplatW(vAbs);
    max0 = XMVectorMax(max0, max1);
    max2 = XMVectorMax(max2, max3);
    max0 = XMVectorMax(max0, max2);

    // Divide by the maximum absolute component.
    XMVECTOR normalized = XMVectorDivide(V, max0);

    // Set to zero when the original length is zero.
    XMVECTOR mask = XMVectorNotEqual(g_XMZero, max0);
    normalized = XMVectorAndInt(normalized, mask);

    // (sqrLength, sqrLength, sqrLength, sqrLength)
    XMVECTOR t0 = XMVector4Dot(normalized, normalized);

    // (length, length, length, length)
    XMVECTOR length = XMVectorSqrt(t0);

    // Divide by the length to normalize.
    normalized = XMVectorDivide(normalized, length);

    // Set to zero when the original length is zero or infinity.  In the
    // latter case, this is considered to be an unexpected condition.
    normalized = XMVectorAndInt(normalized, mask);
    return normalized;
}
    

Requisitos de la plataforma

Microsoft Visual Studio 2010 o Microsoft Visual Studio 2012 con Windows SDK para Windows 8. Compatible con aplicaciones de escritorio Win32, aplicaciones de la Tienda Windows y Windows Phone 8 aplicaciones.

Requisitos

Requisito Value
Plataforma de destino Windows
Encabezado directxmath.h (incluir DirectXMath.h)

Consulte también

Funciones geométricas vectoriales 4D de la biblioteca DirectXMath

XMVector4NormalizeEst