IDCompositionAnimation::AddCubic 方法 (dcompanimation.h)
將三次方多項式區段新增至動畫函式。
語法
HRESULT AddCubic(
[in] double beginOffset,
[in] float constantCoefficient,
[in] float linearCoefficient,
[in] float quadraticCoefficient,
[in] float cubicCoefficient
);
參數
[in] beginOffset
類型: double
從動畫函式的開頭到此區段應該生效的點,以秒為單位的位移。
[in] constantCoefficient
類型: float
多項式的常數係數。
[in] linearCoefficient
類型: float
多項式的線性係數。
[in] quadraticCoefficient
類型: float
多項式的二次係數。
[in] cubicCoefficient
類型: float
多項式的立方係數。
傳回值
類型: HRESULT
如果函式成功,它會傳回S_OK。 否則,它會傳回 HRESULT 錯誤碼。 如需錯誤碼的清單,請參閱 DirectComposition 錯誤 碼。
備註
立方體區段會沿著立方多項式轉換時間。 針對指定的時間輸入 (t) ,輸出值是由下列方程式所指定。
x (t) = atー+ btー + ct + d
如果任一參數為 NaN、正無限大或負無限大,這個方法就會失敗。
因為動畫區段必須依遞增順序新增,所以如果 beginOffset 參數小於或等於上一個區段的 beginOffset 參數,則此方法會失敗。如果有的話。
此動畫區段會維持有效狀態,直到動畫函式中下一個區段的開始時間為止。 如果動畫函式不包含更多區段,此區段會無限期地維持作用中。
如果 constantCoefficient 以外的所有係數都是零,則此區段的值會隨著時間維持不變,而且動畫不會在區段的持續時間造成重新組合。
範例
下列範例會建立具有兩個立方多項式區段的動畫函式。
HRESULT DoAnimatedRotation(IDCompositionDevice *pDevice,
IDCompositionRotateTransform *pRotateTransform,
IDCompositionVisual *pVisual,
float animationTime)
{
HRESULT hr = S_OK;
IDCompositionAnimation *pAnimation = nullptr;
// Create an animation object.
hr = pDevice->CreateAnimation(&pAnimation);
if (SUCCEEDED(hr))
{
// Create the animation function by adding cubic polynomial segments.
// For a given time input (t), the output value is
// a*t^3 + b* t^2 + c*t + d.
//
// The following segment will rotate the visual clockwise.
pAnimation->AddCubic(
0.0, // Begin offset
0.0, // Constant coefficient - d
(360.0f * 1.0f) / animationTime, // Linear coefficient - c
0.0, // Quadratic coefficient - b
0.0); // Cubic coefficient - a
// The following segment will rotate the visual counterclockwise.
pAnimation->AddCubic(
animationTime,
0.0,
-(360.0f * 1.0f) / animationTime,
0.0,
0.0);
// Set the end of the animation.
pAnimation->End(
2 * animationTime, // End offset
0.0); // End value
// Apply the animation to the Angle property of the
// rotate transform.
hr = pRotateTransform->SetAngle(pAnimation);
}
if (SUCCEEDED(hr))
{
// Apply the rotate transform object to a visual.
hr = pVisual->SetTransform(pRotateTransform);
}
if (SUCCEEDED(hr))
{
// Commit the changes to the composition.
hr = pDevice->Commit();
}
SafeRelease(&pAnimation);
return hr;
}
需求
最低支援的用戶端 | Windows 8 [僅限傳統型應用程式] |
最低支援的伺服器 | Windows Server 2012 [僅限傳統型應用程式] |
目標平台 | Windows |
標頭 | dcompanimation.h |
程式庫 | Dcomp.lib |
Dll | Dcomp.dll |