Function directx_math::XMVectorSwizzle[][src]

pub fn XMVectorSwizzle(
    V: FXMVECTOR,
    E0: u32,
    E1: u32,
    E2: u32,
    E3: u32
) -> XMVECTOR

Swizzles a vector.

Parameters

V Vector to swizzle.

E0 Index that describes which component of V to place in the x-component of the swizzled vector. A value of 0 selects the x-component, 1 selects the y-component, 2 selects the z-component, and 3 selects the w-component.

E1 Index that describes which component of V to place in the y-component of the swizzled vector. A value of 0 selects the x-component, 1 selects the y-component, 2 selects the z-component, and 3 selects the w-component.

E2 Index that describes which component of V to place in the z-component of the swizzled vector. A value of 0 selects the x-component, 1 selects the y-component, 2 selects the z-component, and 3 selects the w-component.

E3 Index that describes which component of V to place in the w-component of the swizzled vector. A value of 0 selects the x-component, 1 selects the y-component, 2 selects the z-component, and 3 selects the w-component.

Return value

Returns the swizzled XMVECTOR.

Remarks

The following code demonstrates how this function might be used.

let v = XMVectorSet(10.0, 20.0, 30.0, 40.0);
let result = XMVectorSwizzle(v, 3, 3, 0, 2);

The swizzled vector (result) will be <40.0, 40.0, 10.0, 30.0>.

XM_SWIZZLE_X, XM_SWIZZLE_Y, XM_SWIZZLE_Z, and XM_SWIZZLE_W are constants which evaluate to 0, 1, 2, and 3 respectively for use with XMVectorSwizzle. This is identical to XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_0Z, and XM_PERMUTE_0W.

For the case of constant indices (E0, E1, E2, E3), it is much more efficent to use the template form of XMVectorSwizzle:

let v = XMVectorSet(10.0, 20.0, 30.0, 40.0);
let result = <(SwizzleW, SwizzleW, SwizzleX, SwizzleZ)>::XMVectorSwizzle(v);

Reference

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