# HG changeset patch # User John Tsiombikas # Date 1437833967 -10800 # Node ID 2ce58d5309f0795a7d26b5f9555b46f1b229d3b7 # Parent d30e24132b6eeb4a570b5e526c75f87bd5a5df0e swizzling diff -r d30e24132b6e -r 2ce58d5309f0 src/gmath/swizzle.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gmath/swizzle.h Sat Jul 25 17:19:27 2015 +0300 @@ -0,0 +1,135 @@ +// the only function of this file is to hide the swizzle-macro eyesore + +// swizzle macros for Vector2 +#define GPH_VEC2_SWIZZLE \ + GPH_SWIZZLE2(Vector2, x, x) GPH_SWIZZLE2(Vector2, x, y) \ + GPH_SWIZZLE2(Vector2, y, x) GPH_SWIZZLE2(Vector2, y, z) + +// swizzle macros for Vector3 +#define GPH_VEC3_SWIZZLE \ + GPH_SWIZZLE2(Vector3, x, x) GPH_SWIZZLE2(Vector3, x, y) GPH_SWIZZLE2(Vector3, x, z) \ + GPH_SWIZZLE2(Vector3, y, x) GPH_SWIZZLE2(Vector3, y, y) GPH_SWIZZLE2(Vector3, y, z) \ + GPH_SWIZZLE2(Vector3, z, x) GPH_SWIZZLE2(Vector3, z, y) GPH_SWIZZLE2(Vector3, z, z) \ + GPH_SWIZZLE3(Vector3, x, x, x) GPH_SWIZZLE3(Vector3, x, x, y) GPH_SWIZZLE3(Vector3, x, x, z) \ + GPH_SWIZZLE3(Vector3, x, y, x) GPH_SWIZZLE3(Vector3, x, y, y) GPH_SWIZZLE3(Vector3, x, y, z) \ + GPH_SWIZZLE3(Vector3, x, z, x) GPH_SWIZZLE3(Vector3, x, z, y) GPH_SWIZZLE3(Vector3, x, z, z) \ + GPH_SWIZZLE3(Vector3, y, x, x) GPH_SWIZZLE3(Vector3, y, x, y) GPH_SWIZZLE3(Vector3, y, x, z) \ + GPH_SWIZZLE3(Vector3, y, y, x) GPH_SWIZZLE3(Vector3, y, y, y) GPH_SWIZZLE3(Vector3, y, y, z) \ + GPH_SWIZZLE3(Vector3, y, z, x) GPH_SWIZZLE3(Vector3, y, z, y) GPH_SWIZZLE3(Vector3, y, z, z) \ + GPH_SWIZZLE3(Vector3, z, x, x) GPH_SWIZZLE3(Vector3, z, x, y) GPH_SWIZZLE3(Vector3, z, x, z) \ + GPH_SWIZZLE3(Vector3, z, y, x) GPH_SWIZZLE3(Vector3, z, y, y) GPH_SWIZZLE3(Vector3, z, y, z) \ + GPH_SWIZZLE3(Vector3, z, z, x) GPH_SWIZZLE3(Vector3, z, z, y) GPH_SWIZZLE3(Vector3, z, z, z) \ + GPH_SWIZZLE4(Vector3, x, x, x, x) GPH_SWIZZLE4(Vector3, x, x, x, y) GPH_SWIZZLE4(Vector3, x, x, x, z) \ + GPH_SWIZZLE4(Vector3, x, x, y, x) GPH_SWIZZLE4(Vector3, x, x, y, y) GPH_SWIZZLE4(Vector3, x, x, y, z) \ + GPH_SWIZZLE4(Vector3, x, x, z, x) GPH_SWIZZLE4(Vector3, x, x, z, y) GPH_SWIZZLE4(Vector3, x, x, z, z) \ + GPH_SWIZZLE4(Vector3, x, y, x, x) GPH_SWIZZLE4(Vector3, x, y, x, y) GPH_SWIZZLE4(Vector3, x, y, x, z) \ + GPH_SWIZZLE4(Vector3, x, y, y, x) GPH_SWIZZLE4(Vector3, x, y, y, y) GPH_SWIZZLE4(Vector3, x, y, y, z) \ + GPH_SWIZZLE4(Vector3, x, y, z, x) GPH_SWIZZLE4(Vector3, x, y, z, y) GPH_SWIZZLE4(Vector3, x, y, z, z) \ + GPH_SWIZZLE4(Vector3, x, z, x, x) GPH_SWIZZLE4(Vector3, x, z, x, y) GPH_SWIZZLE4(Vector3, x, z, x, z) \ + GPH_SWIZZLE4(Vector3, x, z, y, x) GPH_SWIZZLE4(Vector3, x, z, y, y) GPH_SWIZZLE4(Vector3, x, z, y, z) \ + GPH_SWIZZLE4(Vector3, x, z, z, x) GPH_SWIZZLE4(Vector3, x, z, z, y) GPH_SWIZZLE4(Vector3, x, z, z, z) \ + GPH_SWIZZLE4(Vector3, y, x, x, x) GPH_SWIZZLE4(Vector3, y, x, x, y) GPH_SWIZZLE4(Vector3, y, x, x, z) \ + GPH_SWIZZLE4(Vector3, y, x, y, x) GPH_SWIZZLE4(Vector3, y, x, y, y) GPH_SWIZZLE4(Vector3, y, x, y, z) \ + GPH_SWIZZLE4(Vector3, y, x, z, x) GPH_SWIZZLE4(Vector3, y, x, z, y) GPH_SWIZZLE4(Vector3, y, x, z, z) \ + GPH_SWIZZLE4(Vector3, y, y, x, x) GPH_SWIZZLE4(Vector3, y, y, x, y) GPH_SWIZZLE4(Vector3, y, y, x, z) \ + GPH_SWIZZLE4(Vector3, y, y, y, x) GPH_SWIZZLE4(Vector3, y, y, y, y) GPH_SWIZZLE4(Vector3, y, y, y, z) \ + GPH_SWIZZLE4(Vector3, y, y, z, x) GPH_SWIZZLE4(Vector3, y, y, z, y) GPH_SWIZZLE4(Vector3, y, y, z, z) \ + GPH_SWIZZLE4(Vector3, y, z, x, x) GPH_SWIZZLE4(Vector3, y, z, x, y) GPH_SWIZZLE4(Vector3, y, z, x, z) \ + GPH_SWIZZLE4(Vector3, y, z, y, x) GPH_SWIZZLE4(Vector3, y, z, y, y) GPH_SWIZZLE4(Vector3, y, z, y, z) \ + GPH_SWIZZLE4(Vector3, y, z, z, x) GPH_SWIZZLE4(Vector3, y, z, z, y) GPH_SWIZZLE4(Vector3, y, z, z, z) \ + GPH_SWIZZLE4(Vector3, z, x, x, x) GPH_SWIZZLE4(Vector3, z, x, x, y) GPH_SWIZZLE4(Vector3, z, x, x, z) \ + GPH_SWIZZLE4(Vector3, z, x, y, x) GPH_SWIZZLE4(Vector3, z, x, y, y) GPH_SWIZZLE4(Vector3, z, x, y, z) \ + GPH_SWIZZLE4(Vector3, z, x, z, x) GPH_SWIZZLE4(Vector3, z, x, z, y) GPH_SWIZZLE4(Vector3, z, x, z, z) \ + GPH_SWIZZLE4(Vector3, z, y, x, x) GPH_SWIZZLE4(Vector3, z, y, x, y) GPH_SWIZZLE4(Vector3, z, y, x, z) \ + GPH_SWIZZLE4(Vector3, z, y, y, x) GPH_SWIZZLE4(Vector3, z, y, y, y) GPH_SWIZZLE4(Vector3, z, y, y, z) \ + GPH_SWIZZLE4(Vector3, z, y, z, x) GPH_SWIZZLE4(Vector3, z, y, z, y) GPH_SWIZZLE4(Vector3, z, y, z, z) \ + GPH_SWIZZLE4(Vector3, z, z, x, x) GPH_SWIZZLE4(Vector3, z, z, x, y) GPH_SWIZZLE4(Vector3, z, z, x, z) \ + GPH_SWIZZLE4(Vector3, z, z, y, x) GPH_SWIZZLE4(Vector3, z, z, y, y) GPH_SWIZZLE4(Vector3, z, z, y, z) \ + GPH_SWIZZLE4(Vector3, z, z, z, x) GPH_SWIZZLE4(Vector3, z, z, z, y) GPH_SWIZZLE4(Vector3, z, z, z, z) + +// swizzle macros for Vector4 (oh shit...) +#define GPH_VEC4_SWIZZLE \ + GPH_SWIZZLE2(Vector4, x, x) GPH_SWIZZLE2(Vector4, x, y) GPH_SWIZZLE2(Vector4, x, z) GPH_SWIZZLE2(Vector4, x, w) \ + GPH_SWIZZLE2(Vector4, y, x) GPH_SWIZZLE2(Vector4, y, y) GPH_SWIZZLE2(Vector4, y, z) GPH_SWIZZLE2(Vector4, y, w) \ + GPH_SWIZZLE2(Vector4, z, x) GPH_SWIZZLE2(Vector4, z, y) GPH_SWIZZLE2(Vector4, z, z) GPH_SWIZZLE2(Vector4, z, w) \ + GPH_SWIZZLE2(Vector4, w, x) GPH_SWIZZLE2(Vector4, w, y) GPH_SWIZZLE2(Vector4, w, z) GPH_SWIZZLE2(Vector4, w, w) \ + GPH_SWIZZLE3(Vector4, x, x, x) GPH_SWIZZLE3(Vector4, x, x, y) GPH_SWIZZLE3(Vector4, x, x, z) GPH_SWIZZLE3(Vector4, x, x, w) \ + GPH_SWIZZLE3(Vector4, x, y, x) GPH_SWIZZLE3(Vector4, x, y, y) GPH_SWIZZLE3(Vector4, x, y, z) GPH_SWIZZLE3(Vector4, x, y, w) \ + GPH_SWIZZLE3(Vector4, x, z, x) GPH_SWIZZLE3(Vector4, x, z, y) GPH_SWIZZLE3(Vector4, x, z, z) GPH_SWIZZLE3(Vector4, x, z, w) \ + GPH_SWIZZLE3(Vector4, x, w, x) GPH_SWIZZLE3(Vector4, x, w, y) GPH_SWIZZLE3(Vector4, x, w, z) GPH_SWIZZLE3(Vector4, x, w, w) \ + GPH_SWIZZLE3(Vector4, y, x, x) GPH_SWIZZLE3(Vector4, y, x, y) GPH_SWIZZLE3(Vector4, y, x, z) GPH_SWIZZLE3(Vector4, y, x, w) \ + GPH_SWIZZLE3(Vector4, y, y, x) GPH_SWIZZLE3(Vector4, y, y, y) GPH_SWIZZLE3(Vector4, y, y, z) GPH_SWIZZLE3(Vector4, y, y, w) \ + GPH_SWIZZLE3(Vector4, y, z, x) GPH_SWIZZLE3(Vector4, y, z, y) GPH_SWIZZLE3(Vector4, y, z, z) GPH_SWIZZLE3(Vector4, y, z, w) \ + GPH_SWIZZLE3(Vector4, y, w, x) GPH_SWIZZLE3(Vector4, y, w, y) GPH_SWIZZLE3(Vector4, y, w, z) GPH_SWIZZLE3(Vector4, y, w, w) \ + GPH_SWIZZLE3(Vector4, z, x, x) GPH_SWIZZLE3(Vector4, z, x, y) GPH_SWIZZLE3(Vector4, z, x, z) GPH_SWIZZLE3(Vector4, z, x, w) \ + GPH_SWIZZLE3(Vector4, z, y, x) GPH_SWIZZLE3(Vector4, z, y, y) GPH_SWIZZLE3(Vector4, z, y, z) GPH_SWIZZLE3(Vector4, z, y, w) \ + GPH_SWIZZLE3(Vector4, z, z, x) GPH_SWIZZLE3(Vector4, z, z, y) GPH_SWIZZLE3(Vector4, z, z, z) GPH_SWIZZLE3(Vector4, z, z, w) \ + GPH_SWIZZLE3(Vector4, z, w, x) GPH_SWIZZLE3(Vector4, z, w, y) GPH_SWIZZLE3(Vector4, z, w, z) GPH_SWIZZLE3(Vector4, z, w, w) \ + GPH_SWIZZLE3(Vector4, w, x, x) GPH_SWIZZLE3(Vector4, w, x, y) GPH_SWIZZLE3(Vector4, w, x, z) GPH_SWIZZLE3(Vector4, w, x, w) \ + GPH_SWIZZLE3(Vector4, w, y, x) GPH_SWIZZLE3(Vector4, w, y, y) GPH_SWIZZLE3(Vector4, w, y, z) GPH_SWIZZLE3(Vector4, w, y, w) \ + GPH_SWIZZLE3(Vector4, w, z, x) GPH_SWIZZLE3(Vector4, w, z, y) GPH_SWIZZLE3(Vector4, w, z, z) GPH_SWIZZLE3(Vector4, w, z, w) \ + GPH_SWIZZLE3(Vector4, w, w, x) GPH_SWIZZLE3(Vector4, w, w, y) GPH_SWIZZLE3(Vector4, w, w, z) GPH_SWIZZLE3(Vector4, w, w, w) \ + GPH_SWIZZLE4(Vector4, x, x, x, x) GPH_SWIZZLE4(Vector4, x, x, x, y) GPH_SWIZZLE4(Vector4, x, x, x, z) GPH_SWIZZLE4(Vector4, x, x, x, w) \ + GPH_SWIZZLE4(Vector4, x, x, y, x) GPH_SWIZZLE4(Vector4, x, x, y, y) GPH_SWIZZLE4(Vector4, x, x, y, z) GPH_SWIZZLE4(Vector4, x, x, y, w) \ + GPH_SWIZZLE4(Vector4, x, x, z, x) GPH_SWIZZLE4(Vector4, x, x, z, y) GPH_SWIZZLE4(Vector4, x, x, z, z) GPH_SWIZZLE4(Vector4, x, x, z, w) \ + GPH_SWIZZLE4(Vector4, x, x, w, x) GPH_SWIZZLE4(Vector4, x, x, w, y) GPH_SWIZZLE4(Vector4, x, x, w, z) GPH_SWIZZLE4(Vector4, x, x, w, w) \ + GPH_SWIZZLE4(Vector4, x, y, x, x) GPH_SWIZZLE4(Vector4, x, y, x, y) GPH_SWIZZLE4(Vector4, x, y, x, z) GPH_SWIZZLE4(Vector4, x, y, x, w) \ + GPH_SWIZZLE4(Vector4, x, y, y, x) GPH_SWIZZLE4(Vector4, x, y, y, y) GPH_SWIZZLE4(Vector4, x, y, y, z) GPH_SWIZZLE4(Vector4, x, y, y, w) \ + GPH_SWIZZLE4(Vector4, x, y, z, x) GPH_SWIZZLE4(Vector4, x, y, z, y) GPH_SWIZZLE4(Vector4, x, y, z, z) GPH_SWIZZLE4(Vector4, x, y, z, w) \ + GPH_SWIZZLE4(Vector4, x, y, w, x) GPH_SWIZZLE4(Vector4, x, y, w, y) GPH_SWIZZLE4(Vector4, x, y, w, z) GPH_SWIZZLE4(Vector4, x, y, w, w) \ + GPH_SWIZZLE4(Vector4, x, z, x, x) GPH_SWIZZLE4(Vector4, x, z, x, y) GPH_SWIZZLE4(Vector4, x, z, x, z) GPH_SWIZZLE4(Vector4, x, z, x, w) \ + GPH_SWIZZLE4(Vector4, x, z, y, x) GPH_SWIZZLE4(Vector4, x, z, y, y) GPH_SWIZZLE4(Vector4, x, z, y, z) GPH_SWIZZLE4(Vector4, x, z, y, w) \ + GPH_SWIZZLE4(Vector4, x, z, z, x) GPH_SWIZZLE4(Vector4, x, z, z, y) GPH_SWIZZLE4(Vector4, x, z, z, z) GPH_SWIZZLE4(Vector4, x, z, z, w) \ + GPH_SWIZZLE4(Vector4, x, z, w, x) GPH_SWIZZLE4(Vector4, x, z, w, y) GPH_SWIZZLE4(Vector4, x, z, w, z) GPH_SWIZZLE4(Vector4, x, z, w, w) \ + GPH_SWIZZLE4(Vector4, x, w, x, x) GPH_SWIZZLE4(Vector4, x, w, x, y) GPH_SWIZZLE4(Vector4, x, w, x, z) GPH_SWIZZLE4(Vector4, x, w, x, w) \ + GPH_SWIZZLE4(Vector4, x, w, y, x) GPH_SWIZZLE4(Vector4, x, w, y, y) GPH_SWIZZLE4(Vector4, x, w, y, z) GPH_SWIZZLE4(Vector4, x, w, y, w) \ + GPH_SWIZZLE4(Vector4, x, w, z, x) GPH_SWIZZLE4(Vector4, x, w, z, y) GPH_SWIZZLE4(Vector4, x, w, z, z) GPH_SWIZZLE4(Vector4, x, w, z, w) \ + GPH_SWIZZLE4(Vector4, x, w, w, x) GPH_SWIZZLE4(Vector4, x, w, w, y) GPH_SWIZZLE4(Vector4, x, w, w, z) GPH_SWIZZLE4(Vector4, x, w, w, w) \ + GPH_SWIZZLE4(Vector4, y, x, x, x) GPH_SWIZZLE4(Vector4, y, x, x, y) GPH_SWIZZLE4(Vector4, y, x, x, z) GPH_SWIZZLE4(Vector4, y, x, x, w) \ + GPH_SWIZZLE4(Vector4, y, x, y, x) GPH_SWIZZLE4(Vector4, y, x, y, y) GPH_SWIZZLE4(Vector4, y, x, y, z) GPH_SWIZZLE4(Vector4, y, x, y, w) \ + GPH_SWIZZLE4(Vector4, y, x, z, x) GPH_SWIZZLE4(Vector4, y, x, z, y) GPH_SWIZZLE4(Vector4, y, x, z, z) GPH_SWIZZLE4(Vector4, y, x, z, w) \ + GPH_SWIZZLE4(Vector4, y, x, w, x) GPH_SWIZZLE4(Vector4, y, x, w, y) GPH_SWIZZLE4(Vector4, y, x, w, z) GPH_SWIZZLE4(Vector4, y, x, w, w) \ + GPH_SWIZZLE4(Vector4, y, y, x, x) GPH_SWIZZLE4(Vector4, y, y, x, y) GPH_SWIZZLE4(Vector4, y, y, x, z) GPH_SWIZZLE4(Vector4, y, y, x, w) \ + GPH_SWIZZLE4(Vector4, y, y, y, x) GPH_SWIZZLE4(Vector4, y, y, y, y) GPH_SWIZZLE4(Vector4, y, y, y, z) GPH_SWIZZLE4(Vector4, y, y, y, w) \ + GPH_SWIZZLE4(Vector4, y, y, z, x) GPH_SWIZZLE4(Vector4, y, y, z, y) GPH_SWIZZLE4(Vector4, y, y, z, z) GPH_SWIZZLE4(Vector4, y, y, z, w) \ + GPH_SWIZZLE4(Vector4, y, y, w, x) GPH_SWIZZLE4(Vector4, y, y, w, y) GPH_SWIZZLE4(Vector4, y, y, w, z) GPH_SWIZZLE4(Vector4, y, y, w, w) \ + GPH_SWIZZLE4(Vector4, y, z, x, x) GPH_SWIZZLE4(Vector4, y, z, x, y) GPH_SWIZZLE4(Vector4, y, z, x, z) GPH_SWIZZLE4(Vector4, y, z, x, w) \ + GPH_SWIZZLE4(Vector4, y, z, y, x) GPH_SWIZZLE4(Vector4, y, z, y, y) GPH_SWIZZLE4(Vector4, y, z, y, z) GPH_SWIZZLE4(Vector4, y, z, y, w) \ + GPH_SWIZZLE4(Vector4, y, z, z, x) GPH_SWIZZLE4(Vector4, y, z, z, y) GPH_SWIZZLE4(Vector4, y, z, z, z) GPH_SWIZZLE4(Vector4, y, z, z, w) \ + GPH_SWIZZLE4(Vector4, y, z, w, x) GPH_SWIZZLE4(Vector4, y, z, w, y) GPH_SWIZZLE4(Vector4, y, z, w, z) GPH_SWIZZLE4(Vector4, y, z, w, w) \ + GPH_SWIZZLE4(Vector4, y, w, x, x) GPH_SWIZZLE4(Vector4, y, w, x, y) GPH_SWIZZLE4(Vector4, y, w, x, z) GPH_SWIZZLE4(Vector4, y, w, x, w) \ + GPH_SWIZZLE4(Vector4, y, w, y, x) GPH_SWIZZLE4(Vector4, y, w, y, y) GPH_SWIZZLE4(Vector4, y, w, y, z) GPH_SWIZZLE4(Vector4, y, w, y, w) \ + GPH_SWIZZLE4(Vector4, y, w, z, x) GPH_SWIZZLE4(Vector4, y, w, z, y) GPH_SWIZZLE4(Vector4, y, w, z, z) GPH_SWIZZLE4(Vector4, y, w, z, w) \ + GPH_SWIZZLE4(Vector4, y, w, w, x) GPH_SWIZZLE4(Vector4, y, w, w, y) GPH_SWIZZLE4(Vector4, y, w, w, z) GPH_SWIZZLE4(Vector4, y, w, w, w) \ + GPH_SWIZZLE4(Vector4, z, x, x, x) GPH_SWIZZLE4(Vector4, z, x, x, y) GPH_SWIZZLE4(Vector4, z, x, x, z) GPH_SWIZZLE4(Vector4, z, x, x, w) \ + GPH_SWIZZLE4(Vector4, z, x, y, x) GPH_SWIZZLE4(Vector4, z, x, y, y) GPH_SWIZZLE4(Vector4, z, x, y, z) GPH_SWIZZLE4(Vector4, z, x, y, w) \ + GPH_SWIZZLE4(Vector4, z, x, z, x) GPH_SWIZZLE4(Vector4, z, x, z, y) GPH_SWIZZLE4(Vector4, z, x, z, z) GPH_SWIZZLE4(Vector4, z, x, z, w) \ + GPH_SWIZZLE4(Vector4, z, x, w, x) GPH_SWIZZLE4(Vector4, z, x, w, y) GPH_SWIZZLE4(Vector4, z, x, w, z) GPH_SWIZZLE4(Vector4, z, x, w, w) \ + GPH_SWIZZLE4(Vector4, z, y, x, x) GPH_SWIZZLE4(Vector4, z, y, x, y) GPH_SWIZZLE4(Vector4, z, y, x, z) GPH_SWIZZLE4(Vector4, z, y, x, w) \ + GPH_SWIZZLE4(Vector4, z, y, y, x) GPH_SWIZZLE4(Vector4, z, y, y, y) GPH_SWIZZLE4(Vector4, z, y, y, z) GPH_SWIZZLE4(Vector4, z, y, y, w) \ + GPH_SWIZZLE4(Vector4, z, y, z, x) GPH_SWIZZLE4(Vector4, z, y, z, y) GPH_SWIZZLE4(Vector4, z, y, z, z) GPH_SWIZZLE4(Vector4, z, y, z, w) \ + GPH_SWIZZLE4(Vector4, z, y, w, x) GPH_SWIZZLE4(Vector4, z, y, w, y) GPH_SWIZZLE4(Vector4, z, y, w, z) GPH_SWIZZLE4(Vector4, z, y, w, w) \ + GPH_SWIZZLE4(Vector4, z, z, x, x) GPH_SWIZZLE4(Vector4, z, z, x, y) GPH_SWIZZLE4(Vector4, z, z, x, z) GPH_SWIZZLE4(Vector4, z, z, x, w) \ + GPH_SWIZZLE4(Vector4, z, z, y, x) GPH_SWIZZLE4(Vector4, z, z, y, y) GPH_SWIZZLE4(Vector4, z, z, y, z) GPH_SWIZZLE4(Vector4, z, z, y, w) \ + GPH_SWIZZLE4(Vector4, z, z, z, x) GPH_SWIZZLE4(Vector4, z, z, z, y) GPH_SWIZZLE4(Vector4, z, z, z, z) GPH_SWIZZLE4(Vector4, z, z, z, w) \ + GPH_SWIZZLE4(Vector4, z, z, w, x) GPH_SWIZZLE4(Vector4, z, z, w, y) GPH_SWIZZLE4(Vector4, z, z, w, z) GPH_SWIZZLE4(Vector4, z, z, w, w) \ + GPH_SWIZZLE4(Vector4, z, w, x, x) GPH_SWIZZLE4(Vector4, z, w, x, y) GPH_SWIZZLE4(Vector4, z, w, x, z) GPH_SWIZZLE4(Vector4, z, w, x, w) \ + GPH_SWIZZLE4(Vector4, z, w, y, x) GPH_SWIZZLE4(Vector4, z, w, y, y) GPH_SWIZZLE4(Vector4, z, w, y, z) GPH_SWIZZLE4(Vector4, z, w, y, w) \ + GPH_SWIZZLE4(Vector4, z, w, z, x) GPH_SWIZZLE4(Vector4, z, w, z, y) GPH_SWIZZLE4(Vector4, z, w, z, z) GPH_SWIZZLE4(Vector4, z, w, z, w) \ + GPH_SWIZZLE4(Vector4, z, w, w, x) GPH_SWIZZLE4(Vector4, z, w, w, y) GPH_SWIZZLE4(Vector4, z, w, w, z) GPH_SWIZZLE4(Vector4, z, w, w, w) \ + GPH_SWIZZLE4(Vector4, w, x, x, x) GPH_SWIZZLE4(Vector4, w, x, x, y) GPH_SWIZZLE4(Vector4, w, x, x, z) GPH_SWIZZLE4(Vector4, w, x, x, w) \ + GPH_SWIZZLE4(Vector4, w, x, y, x) GPH_SWIZZLE4(Vector4, w, x, y, y) GPH_SWIZZLE4(Vector4, w, x, y, z) GPH_SWIZZLE4(Vector4, w, x, y, w) \ + GPH_SWIZZLE4(Vector4, w, x, z, x) GPH_SWIZZLE4(Vector4, w, x, z, y) GPH_SWIZZLE4(Vector4, w, x, z, z) GPH_SWIZZLE4(Vector4, w, x, z, w) \ + GPH_SWIZZLE4(Vector4, w, x, w, x) GPH_SWIZZLE4(Vector4, w, x, w, y) GPH_SWIZZLE4(Vector4, w, x, w, z) GPH_SWIZZLE4(Vector4, w, x, w, w) \ + GPH_SWIZZLE4(Vector4, w, y, x, x) GPH_SWIZZLE4(Vector4, w, y, x, y) GPH_SWIZZLE4(Vector4, w, y, x, z) GPH_SWIZZLE4(Vector4, w, y, x, w) \ + GPH_SWIZZLE4(Vector4, w, y, y, x) GPH_SWIZZLE4(Vector4, w, y, y, y) GPH_SWIZZLE4(Vector4, w, y, y, z) GPH_SWIZZLE4(Vector4, w, y, y, w) \ + GPH_SWIZZLE4(Vector4, w, y, z, x) GPH_SWIZZLE4(Vector4, w, y, z, y) GPH_SWIZZLE4(Vector4, w, y, z, z) GPH_SWIZZLE4(Vector4, w, y, z, w) \ + GPH_SWIZZLE4(Vector4, w, y, w, x) GPH_SWIZZLE4(Vector4, w, y, w, y) GPH_SWIZZLE4(Vector4, w, y, w, z) GPH_SWIZZLE4(Vector4, w, y, w, w) \ + GPH_SWIZZLE4(Vector4, w, z, x, x) GPH_SWIZZLE4(Vector4, w, z, x, y) GPH_SWIZZLE4(Vector4, w, z, x, z) GPH_SWIZZLE4(Vector4, w, z, x, w) \ + GPH_SWIZZLE4(Vector4, w, z, y, x) GPH_SWIZZLE4(Vector4, w, z, y, y) GPH_SWIZZLE4(Vector4, w, z, y, z) GPH_SWIZZLE4(Vector4, w, z, y, w) \ + GPH_SWIZZLE4(Vector4, w, z, z, x) GPH_SWIZZLE4(Vector4, w, z, z, y) GPH_SWIZZLE4(Vector4, w, z, z, z) GPH_SWIZZLE4(Vector4, w, z, z, w) \ + GPH_SWIZZLE4(Vector4, w, z, w, x) GPH_SWIZZLE4(Vector4, w, z, w, y) GPH_SWIZZLE4(Vector4, w, z, w, z) GPH_SWIZZLE4(Vector4, w, z, w, w) \ + GPH_SWIZZLE4(Vector4, w, w, x, x) GPH_SWIZZLE4(Vector4, w, w, x, y) GPH_SWIZZLE4(Vector4, w, w, x, z) GPH_SWIZZLE4(Vector4, w, w, x, w) \ + GPH_SWIZZLE4(Vector4, w, w, y, x) GPH_SWIZZLE4(Vector4, w, w, y, y) GPH_SWIZZLE4(Vector4, w, w, y, z) GPH_SWIZZLE4(Vector4, w, w, y, w) \ + GPH_SWIZZLE4(Vector4, w, w, z, x) GPH_SWIZZLE4(Vector4, w, w, z, y) GPH_SWIZZLE4(Vector4, w, w, z, z) GPH_SWIZZLE4(Vector4, w, w, z, w) \ + GPH_SWIZZLE4(Vector4, w, w, w, x) GPH_SWIZZLE4(Vector4, w, w, w, y) GPH_SWIZZLE4(Vector4, w, w, w, z) GPH_SWIZZLE4(Vector4, w, w, w, w) diff -r d30e24132b6e -r 2ce58d5309f0 src/gmath/vector.cc --- a/src/gmath/vector.cc Sat Jul 25 07:42:30 2015 +0300 +++ b/src/gmath/vector.cc Sat Jul 25 17:19:27 2015 +0300 @@ -3,6 +3,11 @@ namespace gph { +Vector2::Vector2(const Vector3 &v) + : x(v.x), y(v.y) +{ +} + Vector3::Vector3(const Vector4 &v) : x(v.x), y(v.y), z(v.z) { diff -r d30e24132b6e -r 2ce58d5309f0 src/gmath/vector.h --- a/src/gmath/vector.h Sat Jul 25 07:42:30 2015 +0300 +++ b/src/gmath/vector.h Sat Jul 25 17:19:27 2015 +0300 @@ -2,12 +2,33 @@ #define GMATH_VEC_H_ #include +#include "swizzle.h" namespace gph { +#define GPH_SWIZZLE2(T, a, b) inline Vector2 a##b() const; +#define GPH_SWIZZLE3(T, a, b, c) inline Vector3 a##b##c() const; +#define GPH_SWIZZLE4(T, a, b, c, d) inline Vector4 a##b##c##d() const; + +class Vector3; class Vector4; class Matrix4x4; +class Vector2 { +public: + float x, y; + + Vector2() : x(0), y(0) {} + Vector2(float x_, float y_) : x(x_), y(y_) {} + Vector2(const Vector3 &v); + + inline void normalize(); + inline float &operator[] (int idx); + inline const float &operator[] (int idx) const; + + GPH_VEC2_SWIZZLE +}; + class Vector3 { public: float x, y, z; @@ -19,6 +40,8 @@ inline void normalize(); inline float &operator[] (int idx); inline const float &operator[] (int idx) const; + + GPH_VEC3_SWIZZLE }; @@ -33,6 +56,8 @@ inline void normalize(); inline float &operator[] (int idx); inline const float &operator[] (int idx) const; + + GPH_VEC4_SWIZZLE }; // ---- Vector3 functions ---- diff -r d30e24132b6e -r 2ce58d5309f0 src/gmath/vector.inl --- a/src/gmath/vector.inl Sat Jul 25 07:42:30 2015 +0300 +++ b/src/gmath/vector.inl Sat Jul 25 17:19:27 2015 +0300 @@ -2,6 +2,13 @@ namespace gph { +#undef GPH_SWIZZLE2 +#undef GPH_SWIZZLE3 +#undef GPH_SWIZZLE4 +#define GPH_SWIZZLE2(T, a, b) inline Vector2 T::a##b() const { return Vector2(a, b); } +#define GPH_SWIZZLE3(T, a, b, c) inline Vector3 T::a##b##c() const { return Vector3(a, b, c); } +#define GPH_SWIZZLE4(T, a, b, c, d) inline Vector4 T::a##b##c##d() const { return Vector4(a, b, c, d); } + // ---- Vector3 ---- inline void Vector3::normalize() @@ -190,6 +197,8 @@ return dot(ng, i) < 0.0f ? n : -n; } +GPH_VEC3_SWIZZLE + // ---- Vector4 ---- @@ -214,4 +223,29 @@ return idx == 0 ? x : (idx == 1 ? y : (idx == 2 ? z : w)); } +GPH_VEC4_SWIZZLE + +// ---- Vector2 ---- + +inline void Vector2::normalize() +{ + float len = (float)sqrt(x * x + y * y); + if(len != 0.0f) { + x /= len; + y /= len; + } +} + +inline float &Vector2::operator[] (int idx) +{ + return idx == 0 ? x : y; +} + +inline const float &Vector2::operator[] (int idx) const +{ + return idx == 0 ? x : y; +} + +GPH_VEC2_SWIZZLE + } // namespace gph