Defines | |
| #define | VEC2_SWIZZLE(v, c0, c1) (common::VEC2((v).c0, (v).c1)) |
| #define | VEC3_SWIZZLE(v, c0, c1, c2) (common::VEC3((v).c0, (v).c1, (v).c2)) |
| #define | VEC4_SWIZZLE(v, c0, c1, c2, c3) (common::VEC4((v).c0, (v).c1, (v).c2, (v).c3)) |
Here are macros for convinient building vectors from arbitrary components of other vector, just like in HLSL and other shader languages.
For example, in HLSL you can extend float2 to float4 with repeating (x,y) components two times with code like this:
float2 v2 = float2(1, 2); float4 v4 = v2.xyxy;
In C++ with CommonLib, you can do it like this:
common::VEC2 v2 = common::VEC2(1.f, 2.f); common::VEC4 v4 = common::VEC4(v2.x, v2.y, v2.x, v2.y);
But the more convenient way is to use VEC4_SWIZZLE macro:
common::VEC2 v2 = common::VEC2(1.f, 2.f); common::VEC4 v4 = VEC4_SWIZZLE(v2,x,y,x,y);
Source vector can be of any size (VEC2, VEC3, VEC4), as long as you reference only existing components (x, y, z, w).
Type of destination vector is determined by using particular macro (e.g. VEC3_SWIZZLE returns VEC3).
You can use expression of any type as source value, as long as it can be indexed with dot operator. E.g.:
MATRIX m = ...; VEC4 mDiagonal = VEC4_SWIZZLE(m,_11,_22,_33,_44); BOX box = ...; VEC2 boxRangeX = VEC2_SWIZZLE(box,Min.x,Max.x);
| #define VEC2_SWIZZLE | ( | v, | |||
| c0, | |||||
| c1 | ) | (common::VEC2((v).c0, (v).c1)) |
| #define VEC3_SWIZZLE | ( | v, | |||
| c0, | |||||
| c1, | |||||
| c2 | ) | (common::VEC3((v).c0, (v).c1, (v).c2)) |
| #define VEC4_SWIZZLE | ( | v, | |||
| c0, | |||||
| c1, | |||||
| c2, | |||||
| c3 | ) | (common::VEC4((v).c0, (v).c1, (v).c2, (v).c3)) |
1.6.1