XMQuaternionBaryCentric function (directxmath.h)
Returns a point in barycentric coordinates, using the specified quaternions.
Syntax
XMVECTOR XM_CALLCONV XMQuaternionBaryCentric(
[in] FXMVECTOR Q0,
[in] FXMVECTOR Q1,
[in] FXMVECTOR Q2,
[in] float f,
[in] float g
) noexcept;
Parameters
[in] Q0
First quaternion in the triangle.
[in] Q1
Second quaternion in the triangle.
[in] Q2
Third quaternion in the triangle.
[in] f
Weighting factor. See the remarks.
[in] g
Weighting factor. See the remarks.
Return value
Returns a quaternion in barycentric coordinates.
Remarks
The following pseudocode demonstrates the operation of the function.
XMVECTOR Result;
XMVECTOR QA, QB;
float s = f + g;
if (s != 0.0f)
{
QA = XMQuaternionSlerp(Q0, Q1, s);
QB = XMQuaternionSlerp(Q0, Q2, s);
Result = XMQuaternionSlerp(QA, QB, g / s);
}
else
{
Result.x = Q0.x;
Result.y = Q0.y;
Result.z = Q0.z;
Result.w = Q0.w;
}
return Result;
Note that Barycentric coordinates work for 'flat' surfaces but not for 'curved' ones. This function is therefore a bit of a work-around. An alternative method for blending 3 quaternions is given by the following code:
inline XMVECTOR XMQuaternionBlend(FXMVECTOR Q0, FXMVECTOR Q1, FXMVECTOR Q2, float w1, float w2)
{
// Note if you choose one of the three weights to be zero, you get a blend of two
// quaternions. This does not give you slerp of those quaternions.
float w0 = 1.0f - w1 - w2;
XMVECTOR Result = XMVector4Normalize(
XMVectorScale(Q0, w0) +
XMVectorScale(Q1, w1) +
XMVectorScale(Q2, w2));
return Result;
}
Platform Requirements
Microsoft Visual Studio 2010 or Microsoft Visual Studio 2012 with the Windows SDK for Windows 8. Supported for Win32 desktop apps, Windows Store apps, and Windows Phone 8 apps.Requirements
Requirement | Value |
---|---|
Target Platform | Windows |
Header | directxmath.h |