QVM: Quaternions, Vectors, Matrices

Swizzling

Boost QVM allows accessing vector elements by swizzling, exposing vector views of different dimensions, and/or views with reordered elements. The example below rotates v around the X axis, and stores the resulting vector back in v but with the X and Y elements swapped:

float3 v = {0,0,7};
YXZ(v) = rotx_mat<3>(3.14159f) * v;

A special case of swizzling provides next-dimension-view of a vector object, adding either 0 or 1 as its last component. Assuming float3 is a 3D vector type, and float4 is a 4D vector type, the following statements are valid:

float3 v = {0,0,7};
float4 point = XYZ1(v); //{0,0,7,1}
float4 vector = XYZ0(v); //{0,0,7,0}

It is also valid for swizzling to address vector elements more than once:

float3 v = {0,0,7};
float4 v1 = ZZZZ(v); //{7,7,7,7}

Boost QVM defines all permutations of X, Y, Z, W for 1D, 2D, 3D and 4D swizzling, plus each dimension defines variants with 0 or 1 used at any position (if 0 or 1 appear at the first position, the swizzling function name begins with underscore, e.g. _1XY).


Tutorial navigation: Quaternions, Vectors, Matrices | C Arrays | Views | Swizzling | Interoperability 
 
See also: Boost QVM