Condividi tramite


Funzione XMVector3Normalize (directxmath.h)

Restituisce la versione normalizzata di un vettore 3D.

Sintassi

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

Parametri

[in] V

Vettore 3D.

Valore restituito

Restituisce la versione normalizzata di V.

Commenti

Per un vettore di lunghezza 0, questa funzione restituisce un vettore zero. Per un vettore con lunghezza infinita, restituisce un vettore di QNaN.

Si noti che per la maggior parte delle applicazioni grafiche verificare che i vettori abbiano lunghezze ben definite che non causano problemi per la normalizzazione è una pratica comune. Tuttavia, se è necessaria una normalizzazione affidabile che funziona per tutti gli input a virgola mobile, è possibile usare invece il codice seguente:


inline XMVECTOR XMVector3NormalizeRobust( FXMVECTOR V )
{
    // Compute the maximum absolute value component.
    XMVECTOR vAbs = XMVectorAbs(V);
    XMVECTOR max0 = XMVectorSplatX(vAbs);
    XMVECTOR max1 = XMVectorSplatY(vAbs);
    XMVECTOR max2 = XMVectorSplatZ(vAbs);
    max0 = XMVectorMax(max0, max1);
    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);

    XMVECTOR t0 = XMVector3LengthSq(normalized);
    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;
}
    

Requisiti della piattaforma

Microsoft Visual Studio 2010 o Microsoft Visual Studio 2012 con Windows SDK per Windows 8. Supportato per app desktop Win32, app di Windows Store e Windows Phone 8 app.

Requisiti

   
Piattaforma di destinazione Windows
Intestazione directxmath.h (include DirectXMath.h)

Vedi anche

Funzioni geometriche vettoriali DirectXMath library 3D

XMVector3NormalizeEst