XMVectorLerp 函式 (directxmath.h)

執行兩個向量之間的線性插補。

語法

XMVECTOR XM_CALLCONV XMVectorLerp(
  [in] FXMVECTOR V0,
  [in] FXMVECTOR V1,
  [in] float     t
) noexcept;

參數

[in] V0

要從中插補的第一個向量。

[in] V1

要從中插補的第二個向量。

[in] t

插補控制因數。

傳回值

傳回包含內插補點的向量。

備註

下列虛擬程式代碼示範函式的作業:

XMVECTOR Result;

Result.x = V0.x + t * (V1.x - V0.x);
Result.y = V0.y + t * (V1.y - V0.y);
Result.z = V0.z + t * (V1.z - V0.z);
Result.w = V0.w + t * (V1.w - V0.w);

return Result;

請注意,使用這個函式來執行三次插補,而不是線性插補,相當簡單,如下所示:


XMVECTOR SmoothStep( XMVECTOR V0, XMVECTOR V1, float t )
{
    t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t);  // Clamp value to 0 to 1
    t = t*t*(3.f - 2.f*t);
    return XMVectorLerp( V0, V1, t );
}

平臺需求

Microsoft Visual Studio 2010 或 Microsoft Visual Studio 2012 與 Windows SDK for Windows 8。 支援 Win32 傳統型應用程式、Windows 市集應用程式和 Windows Phone 8 個應用程式。

規格需求

需求
目標平台 Windows
標頭 directxmath.h (包含 DirectXMath.h)

另請參閱

幾何向量函式

XMVectorLerpV