XMQuaternionBaryCentric

Returns a point in barycentric coordinates, using the specified quaternions.

Syntax

XMVECTOR XMQuaternionBaryCentric(
         XMVECTOR Q0,
         XMVECTOR Q1,
         XMVECTOR Q2,
         float f,
         float g
)  

Parameters

Q0
Type: XMVECTOR 

First quaternion in the triangle.

Q1
Type: XMVECTOR 

Second quaternion in the triangle.

Q2
Type: XMVECTOR 

Third quaternion in the triangle.

f
Type: float 

Weighting factor. See the remarks.

g
Type: float 

Weighting factor. See the remarks.

Return value

Type: XMVECTOR 

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 quanterions 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;
}  

Requirements

Header: Declared in directxmath.h.