Function directx_math::XMVectorSelect [−][src]
pub fn XMVectorSelect(
V1: FXMVECTOR,
V2: FXMVECTOR,
Control: FXMVECTOR
) -> XMVECTOR
Performs a per-component selection between two input vectors and returns the resulting vector.
Parameters
V1
First vector to compare.
V2
Second vector to compare.
Control
Vector mask used to select a vector component from either V1
or V2
. If a component of Control is zero,
the returned vector’s corresponding component will be the first vector’s component. If a component of
Control is 0xFF, the returned vector’s corresponding component will be the second vector’s component.
For full details on how the vector mask works, see the “Remarks”. Typically, the vector used for Control
will be either the output of a vector comparison function (such as XMVectorEqual, XMVectorLess, or XMVectorGreater)
or it will be the output of XMVectorSelectControl.
Return value
Returns the result of the per-component selection.
Remarks
If any given bit of Control is set, the corresponding bit from V2
is used, otherwise, the corresponding
bit from V1
is used. The following pseudocode demonstrates the operation of the function:
XMVECTOR Result;
Result.u[0] = (V1.u[0] & ~Control.u[0]) | (V2.u[0] & Control.u[0]);
Result.u[1] = (V1.u[1] & ~Control.u[1]) | (V2.u[1] & Control.u[1]);
Result.u[2] = (V1.u[2] & ~Control.u[2]) | (V2.u[2] & Control.u[2]);
Result.u[3] = (V1.u[3] & ~Control.u[3]) | (V2.u[3] & Control.u[3]);
return Result;
Manual construction of a control vector is not necessary. There are two simple ways of constructing an appropriate control vector:
-
Using the XMVectorSelectControlfunction to construct a control vector. See Using XMVectorSelect and XMVectorSelectControl for a demonstration of how this function can be used.
-
The control vector can be constructed using the
XM_SELECT_[0,1]
constant (see DirectXMath Library Constants). As an example, in pseudo-code, an instance of Control with the elements:
Control = { XM_SELECT_0, XM_SELECT_1, XM_SELECT_0, XM_SELECT_1 }
would return a vector Result with the following components of V1
and V2
Result = { V1.X, V2.Y, V1.Z, V2.W }
Reference
https://docs.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-XMVectorSelect