XMVectorSwizzle (XMVECTOR, uint32_t, uint32_t, uint32_t, uint32_t)

Swizzles a vector.

Syntax

XMVECTOR XMVectorSwizzle(
         XMVECTOR V,
         uint32_t E0,
         uint32_t E1,
         uint32_t E2,
         uint32_t E3
)  

Parameters

V
Type: XMVECTOR 

Vector to swizzle.

E0
Type: uint32_t 

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
Type: uint32_t 

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
Type: uint32_t 

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
Type: uint32_t 

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

Type: XMVECTOR 

Returns the swizzled XMVECTOR.

Remarks

The following code demonstrates how this function might be used.

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

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

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 efficient to use the template form of XMVectorSwizzle:

template<uint32_t SwizzleX, uint32_t SwizzleY, uint32_t SwizzleZ, uint32_t SwizzleW>
    XMVECTOR XMVectorSwizzle(FXMVECTOR V)

Example: XMVectorSwizzle< 3, 3, 0, 2>(v);  

Requirements

Header: Declared in directxmath.h.