Function directx_math::XMQuaternionBaryCentric[][src]

pub fn XMQuaternionBaryCentric(
    Q0: FXMVECTOR,
    Q1: FXMVECTOR,
    Q2: FXMVECTOR,
    f: f32,
    g: f32
) -> XMVECTOR

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

Parameters

Q0 First quaternion in the triangle.

Q1 Second quaternion in the triangle.

Q2 Third quaternion in the triangle.

f Weighting factor. See the remarks.

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

Reference

https://docs.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-XMQuaternionBaryCentric