diff --git a/src/input.cpp b/src/input.cpp index c759e283..f9d0cfc8 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -134,7 +134,7 @@ void Input::SetMousePos(ivec2 coord) { if (data->entities[n] == top) { - data->entities[n]->mousepos = coord - (ivec2)top->bbox[0].xy(); + data->entities[n]->mousepos = coord - (ivec2)top->bbox[0].xy; if (top != data->lastfocus) data->entities[n]->pressed = data->buttons; else diff --git a/src/lol/math/matrix.h b/src/lol/math/matrix.h index eb80e403..d2b6834b 100644 --- a/src/lol/math/matrix.h +++ b/src/lol/math/matrix.h @@ -49,6 +49,33 @@ VECTOR_TYPES(Vec4, vec4) VECTOR_TYPES(Quat, quat) VECTOR_TYPES(Mat4, mat4) +/* + * Magic swizzling (part 1/2) + */ + +template struct MagicVec2 +{ + inline Vec2 operator =(Vec2 that); + + float ptr[1 + (I > J ? I : J)]; +}; + +template struct MagicVec3 +{ + inline Vec3 operator =(Vec3 that); + + float ptr[1 + (I > J ? I > K ? I : K + : J > K ? J : K)]; +}; + +template struct MagicVec4 +{ + inline Vec4 operator =(Vec4 that); + + float ptr[1 + (I > J ? I > K ? I > L ? I : L : K > L ? K : L + : J > K ? J > L ? J : L : K > L ? K : L)]; +}; + #define MEMBER_OPS() \ inline T& operator[](int n) { return *(&x + n); } \ inline T const& operator[](int n) const { return *(&x + n); } \ @@ -111,67 +138,6 @@ VECTOR_TYPES(Mat4, mat4) return ret; \ } -#define SWIZZLE2(e1, e2) \ - inline Vec2 e1##e2() const \ - { \ - return Vec2(this->e1, this->e2); \ - } - -#define SWIZZLE3(e1, e2, e3) \ - inline Vec3 e1##e2##e3() const \ - { \ - return Vec3(this->e1, this->e2, this->e3); \ - } - -#define SWIZZLE4(e1, e2, e3, e4) \ - inline Vec4 e1##e2##e3##e4() const \ - { \ - return Vec4(this->e1, this->e2, this->e3, this->e4); \ - } - -#define SWIZZLE22(e1) \ - SWIZZLE2(e1, x); SWIZZLE2(e1, y); -#define SWIZZLE23(e1) \ - SWIZZLE2(e1, x); SWIZZLE2(e1, y); SWIZZLE2(e1, z); -#define SWIZZLE24(e1) \ - SWIZZLE2(e1, x); SWIZZLE2(e1, y); SWIZZLE2(e1, z); SWIZZLE2(e1, w); - -#define SWIZZLE32(e1, e2) \ - SWIZZLE3(e1, e2, x); SWIZZLE3(e1, e2, y); -#define SWIZZLE322(e1) \ - SWIZZLE32(e1, x); SWIZZLE32(e1, y); -#define SWIZZLE33(e1, e2) \ - SWIZZLE3(e1, e2, x); SWIZZLE3(e1, e2, y); SWIZZLE3(e1, e2, z); -#define SWIZZLE333(e1) \ - SWIZZLE33(e1, x); SWIZZLE33(e1, y); SWIZZLE33(e1, z); -#define SWIZZLE34(e1, e2) \ - SWIZZLE3(e1, e2, x); SWIZZLE3(e1, e2, y); \ - SWIZZLE3(e1, e2, z); SWIZZLE3(e1, e2, w); -#define SWIZZLE344(e1) \ - SWIZZLE34(e1, x); SWIZZLE34(e1, y); \ - SWIZZLE34(e1, z); SWIZZLE34(e1, w); - -#define SWIZZLE42(e1, e2, e3) \ - SWIZZLE4(e1, e2, e3, x); SWIZZLE4(e1, e2, e3, y); -#define SWIZZLE422(e1, e2) \ - SWIZZLE42(e1, e2, x); SWIZZLE42(e1, e2, y); -#define SWIZZLE4222(e1) \ - SWIZZLE422(e1, x); SWIZZLE422(e1, y); -#define SWIZZLE43(e1, e2, e3) \ - SWIZZLE4(e1, e2, e3, x); SWIZZLE4(e1, e2, e3, y); SWIZZLE4(e1, e2, e3, z); -#define SWIZZLE433(e1, e2) \ - SWIZZLE43(e1, e2, x); SWIZZLE43(e1, e2, y); SWIZZLE43(e1, e2, z); -#define SWIZZLE4333(e1) \ - SWIZZLE433(e1, x); SWIZZLE433(e1, y); SWIZZLE433(e1, z); -#define SWIZZLE44(e1, e2, e3) \ - SWIZZLE4(e1, e2, e3, x); SWIZZLE4(e1, e2, e3, y); \ - SWIZZLE4(e1, e2, e3, z); SWIZZLE4(e1, e2, e3, w); -#define SWIZZLE444(e1, e2) \ - SWIZZLE44(e1, e2, x); SWIZZLE44(e1, e2, y); \ - SWIZZLE44(e1, e2, z); SWIZZLE44(e1, e2, w); -#define SWIZZLE4444(e1) \ - SWIZZLE444(e1, x); SWIZZLE444(e1, y); SWIZZLE444(e1, z); SWIZZLE444(e1, w); - /* * 2-element vectors */ @@ -184,13 +150,13 @@ template struct Vec2 explicit inline Vec2(T val) { x = y = val; } inline Vec2(T _x, T _y) { x = _x; y = _y; } + template + inline Vec2(MagicVec2 const &v) + : x(v.ptr[I]), y(v.ptr[J]) {} + MEMBER_OPS() OTHER_MEMBER_OPS(Vec2) - SWIZZLE22(x); SWIZZLE22(y); - SWIZZLE322(x); SWIZZLE322(y); - SWIZZLE4222(x); SWIZZLE4222(y); - #if !defined __ANDROID__ template friend std::ostream &operator<<(std::ostream &stream, Vec2 const &v); @@ -201,6 +167,35 @@ template struct Vec2 struct { T x, y; }; struct { T r, g; }; struct { T s, t; }; + + MagicVec2 xx, rr, ss; + MagicVec2 xy, rg, st; + MagicVec2 yx, gr, ts; + MagicVec2 yy, gg, tt; + MagicVec3 xxx, rrr, sss; + MagicVec3 xxy, rrg, sst; + MagicVec3 xyx, rgr, sts; + MagicVec3 xyy, rgg, stt; + MagicVec3 yxx, grr, tss; + MagicVec3 yxy, grg, tst; + MagicVec3 yyx, ggr, tts; + MagicVec3 yyy, ggg, ttt; + MagicVec4 xxxx, rrrr, ssss; + MagicVec4 xxxy, rrrg, ssst; + MagicVec4 xxyx, rrgr, ssts; + MagicVec4 xxyy, rrgg, sstt; + MagicVec4 xyxx, rgrr, stss; + MagicVec4 xyxy, rgrg, stst; + MagicVec4 xyyx, rggr, stts; + MagicVec4 xyyy, rggg, sttt; + MagicVec4 yxxx, grrr, tsss; + MagicVec4 yxxy, grrg, tsst; + MagicVec4 yxyx, grgr, tsts; + MagicVec4 yxyy, grgg, tstt; + MagicVec4 yyxx, ggrr, ttss; + MagicVec4 yyxy, ggrg, ttst; + MagicVec4 yyyx, gggr, ttts; + MagicVec4 yyyy, gggg, tttt; }; }; @@ -278,13 +273,13 @@ template struct Vec3 inline Vec3(Vec2 _xy, T _z) { x = _xy.x; y = _xy.y; z = _z; } inline Vec3(T _x, Vec2 _yz) { x = _x; y = _yz.x; z = _yz.y; } + template + inline Vec3(MagicVec3 const &v) + : x(v.ptr[I]), y(v.ptr[J]), z(v.ptr[K]) {} + MEMBER_OPS() OTHER_MEMBER_OPS(Vec3) - SWIZZLE23(x); SWIZZLE23(y); SWIZZLE23(z); - SWIZZLE333(x); SWIZZLE333(y); SWIZZLE333(z); - SWIZZLE4333(x); SWIZZLE4333(y); SWIZZLE4333(z); - template friend Vec3 cross(Vec3, Vec3); @@ -298,6 +293,124 @@ template struct Vec3 struct { T x, y, z; }; struct { T r, g, b; }; struct { T s, t, p; }; + + MagicVec2 xx, rr, ss; + MagicVec2 xy, rg, st; + MagicVec2 xz, rb, sp; + MagicVec2 yx, gr, ts; + MagicVec2 yy, gg, tt; + MagicVec2 yz, gb, tp; + MagicVec2 zx, br, ps; + MagicVec2 zy, bg, pt; + MagicVec2 zz, bb, pp; + MagicVec3 xxx, rrr, sss; + MagicVec3 xxy, rrg, sst; + MagicVec3 xxz, rrb, ssp; + MagicVec3 xyx, rgr, sts; + MagicVec3 xyy, rgg, stt; + MagicVec3 xyz, rgb, stp; + MagicVec3 xzx, rbr, sps; + MagicVec3 xzy, rbg, spt; + MagicVec3 xzz, rbb, spp; + MagicVec3 yxx, grr, tss; + MagicVec3 yxy, grg, tst; + MagicVec3 yxz, grb, tsp; + MagicVec3 yyx, ggr, tts; + MagicVec3 yyy, ggg, ttt; + MagicVec3 yyz, ggb, ttp; + MagicVec3 yzx, gbr, tps; + MagicVec3 yzy, gbg, tpt; + MagicVec3 yzz, gbb, tpp; + MagicVec3 zxx, brr, pss; + MagicVec3 zxy, brg, pst; + MagicVec3 zxz, brb, psp; + MagicVec3 zyx, bgr, pts; + MagicVec3 zyy, bgg, ptt; + MagicVec3 zyz, bgb, ptp; + MagicVec3 zzx, bbr, pps; + MagicVec3 zzy, bbg, ppt; + MagicVec3 zzz, bbb, ppp; + MagicVec4 xxxx, rrrr, ssss; + MagicVec4 xxxy, rrrg, ssst; + MagicVec4 xxxz, rrrb, sssp; + MagicVec4 xxyx, rrgr, ssts; + MagicVec4 xxyy, rrgg, sstt; + MagicVec4 xxyz, rrgb, sstp; + MagicVec4 xxzx, rrbr, ssps; + MagicVec4 xxzy, rrbg, sspt; + MagicVec4 xxzz, rrbb, sspp; + MagicVec4 xyxx, rgrr, stss; + MagicVec4 xyxy, rgrg, stst; + MagicVec4 xyxz, rgrb, stsp; + MagicVec4 xyyx, rggr, stts; + MagicVec4 xyyy, rggg, sttt; + MagicVec4 xyyz, rggb, sttp; + MagicVec4 xyzx, rgbr, stps; + MagicVec4 xyzy, rgbg, stpt; + MagicVec4 xyzz, rgbb, stpp; + MagicVec4 xzxx, rbrr, spss; + MagicVec4 xzxy, rbrg, spst; + MagicVec4 xzxz, rbrb, spsp; + MagicVec4 xzyx, rbgr, spts; + MagicVec4 xzyy, rbgg, sptt; + MagicVec4 xzyz, rbgb, sptp; + MagicVec4 xzzx, rbbr, spps; + MagicVec4 xzzy, rbbg, sppt; + MagicVec4 xzzz, rbbb, sppp; + MagicVec4 yxxx, grrr, tsss; + MagicVec4 yxxy, grrg, tsst; + MagicVec4 yxxz, grrb, tssp; + MagicVec4 yxyx, grgr, tsts; + MagicVec4 yxyy, grgg, tstt; + MagicVec4 yxyz, grgb, tstp; + MagicVec4 yxzx, grbr, tsps; + MagicVec4 yxzy, grbg, tspt; + MagicVec4 yxzz, grbb, tspp; + MagicVec4 yyxx, ggrr, ttss; + MagicVec4 yyxy, ggrg, ttst; + MagicVec4 yyxz, ggrb, ttsp; + MagicVec4 yyyx, gggr, ttts; + MagicVec4 yyyy, gggg, tttt; + MagicVec4 yyyz, gggb, tttp; + MagicVec4 yyzx, ggbr, ttps; + MagicVec4 yyzy, ggbg, ttpt; + MagicVec4 yyzz, ggbb, ttpp; + MagicVec4 yzxx, gbrr, tpss; + MagicVec4 yzxy, gbrg, tpst; + MagicVec4 yzxz, gbrb, tpsp; + MagicVec4 yzyx, gbgr, tpts; + MagicVec4 yzyy, gbgg, tptt; + MagicVec4 yzyz, gbgb, tptp; + MagicVec4 yzzx, gbbr, tpps; + MagicVec4 yzzy, gbbg, tppt; + MagicVec4 yzzz, gbbb, tppp; + MagicVec4 zxxx, brrr, psss; + MagicVec4 zxxy, brrg, psst; + MagicVec4 zxxz, brrb, pssp; + MagicVec4 zxyx, brgr, psts; + MagicVec4 zxyy, brgg, pstt; + MagicVec4 zxyz, brgb, pstp; + MagicVec4 zxzx, brbr, psps; + MagicVec4 zxzy, brbg, pspt; + MagicVec4 zxzz, brbb, pspp; + MagicVec4 zyxx, bgrr, ptss; + MagicVec4 zyxy, bgrg, ptst; + MagicVec4 zyxz, bgrb, ptsp; + MagicVec4 zyyx, bggr, ptts; + MagicVec4 zyyy, bggg, pttt; + MagicVec4 zyyz, bggb, pttp; + MagicVec4 zyzx, bgbr, ptps; + MagicVec4 zyzy, bgbg, ptpt; + MagicVec4 zyzz, bgbb, ptpp; + MagicVec4 zzxx, bbrr, ppss; + MagicVec4 zzxy, bbrg, ppst; + MagicVec4 zzxz, bbrb, ppsp; + MagicVec4 zzyx, bbgr, ppts; + MagicVec4 zzyy, bbgg, pptt; + MagicVec4 zzyz, bbgb, pptp; + MagicVec4 zzzx, bbbr, ppps; + MagicVec4 zzzy, bbbg, pppt; + MagicVec4 zzzz, bbbb, pppp; }; }; @@ -319,13 +432,17 @@ template struct Vec4 inline Vec4(Vec3 _xyz, T _w) : x(_xyz.x), y(_xyz.y), z(_xyz.z), w(_w) { } inline Vec4(T _x, Vec3 _yzw) : x(_x), y(_yzw.x), z(_yzw.y), w(_yzw.z) { } + template + inline Vec4(MagicVec4 const &v) + : x(v.ptr[I]), y(v.ptr[J]), z(v.ptr[K]), w(v.ptr[L]) {} + + template + explicit inline Vec4(MagicVec4 const &v) + : x(v.ptr[I]), y(v.ptr[J]), z(v.ptr[K]), w(v.ptr[L]) {} + MEMBER_OPS() OTHER_MEMBER_OPS(Vec4) - SWIZZLE24(x); SWIZZLE24(y); SWIZZLE24(z); SWIZZLE24(w); - SWIZZLE344(x); SWIZZLE344(y); SWIZZLE344(z); SWIZZLE344(w); - SWIZZLE4444(x); SWIZZLE4444(y); SWIZZLE4444(z); SWIZZLE4444(w); - #if !defined __ANDROID__ template friend std::ostream &operator<<(std::ostream &stream, Vec4 const &v); @@ -336,9 +453,351 @@ template struct Vec4 struct { T x, y, z, w; }; struct { T r, g, b, a; }; struct { T s, t, p, q; }; + + MagicVec2 xx, rr, ss; + MagicVec2 xy, rg, st; + MagicVec2 xz, rb, sp; + MagicVec2 xw, ra, sq; + MagicVec2 yx, gr, ts; + MagicVec2 yy, gg, tt; + MagicVec2 yz, gb, tp; + MagicVec2 yw, ga, tq; + MagicVec2 zx, br, ps; + MagicVec2 zy, bg, pt; + MagicVec2 zz, bb, pp; + MagicVec2 zw, ba, pq; + MagicVec2 wx, ar, qs; + MagicVec2 wy, ag, qt; + MagicVec2 wz, ab, qp; + MagicVec2 ww, aa, qq; + MagicVec3 xxx, rrr, sss; + MagicVec3 xxy, rrg, sst; + MagicVec3 xxz, rrb, ssp; + MagicVec3 xxw, rra, ssq; + MagicVec3 xyx, rgr, sts; + MagicVec3 xyy, rgg, stt; + MagicVec3 xyz, rgb, stp; + MagicVec3 xyw, rga, stq; + MagicVec3 xzx, rbr, sps; + MagicVec3 xzy, rbg, spt; + MagicVec3 xzz, rbb, spp; + MagicVec3 xzw, rba, spq; + MagicVec3 xwx, rar, sqs; + MagicVec3 xwy, rag, sqt; + MagicVec3 xwz, rab, sqp; + MagicVec3 xww, raa, sqq; + MagicVec3 yxx, grr, tss; + MagicVec3 yxy, grg, tst; + MagicVec3 yxz, grb, tsp; + MagicVec3 yxw, gra, tsq; + MagicVec3 yyx, ggr, tts; + MagicVec3 yyy, ggg, ttt; + MagicVec3 yyz, ggb, ttp; + MagicVec3 yyw, gga, ttq; + MagicVec3 yzx, gbr, tps; + MagicVec3 yzy, gbg, tpt; + MagicVec3 yzz, gbb, tpp; + MagicVec3 yzw, gba, tpq; + MagicVec3 ywx, gar, tqs; + MagicVec3 ywy, gag, tqt; + MagicVec3 ywz, gab, tqp; + MagicVec3 yww, gaa, tqq; + MagicVec3 zxx, brr, pss; + MagicVec3 zxy, brg, pst; + MagicVec3 zxz, brb, psp; + MagicVec3 zxw, bra, psq; + MagicVec3 zyx, bgr, pts; + MagicVec3 zyy, bgg, ptt; + MagicVec3 zyz, bgb, ptp; + MagicVec3 zyw, bga, ptq; + MagicVec3 zzx, bbr, pps; + MagicVec3 zzy, bbg, ppt; + MagicVec3 zzz, bbb, ppp; + MagicVec3 zzw, bba, ppq; + MagicVec3 zwx, bar, pqs; + MagicVec3 zwy, bag, pqt; + MagicVec3 zwz, bab, pqp; + MagicVec3 zww, baa, pqq; + MagicVec3 wxx, arr, qss; + MagicVec3 wxy, arg, qst; + MagicVec3 wxz, arb, qsp; + MagicVec3 wxw, ara, qsq; + MagicVec3 wyx, agr, qts; + MagicVec3 wyy, agg, qtt; + MagicVec3 wyz, agb, qtp; + MagicVec3 wyw, aga, qtq; + MagicVec3 wzx, abr, qps; + MagicVec3 wzy, abg, qpt; + MagicVec3 wzz, abb, qpp; + MagicVec3 wzw, aba, qpq; + MagicVec3 wwx, aar, qqs; + MagicVec3 wwy, aag, qqt; + MagicVec3 wwz, aab, qqp; + MagicVec3 www, aaa, qqq; + MagicVec4 xxxx, rrrr, ssss; + MagicVec4 xxxy, rrrg, ssst; + MagicVec4 xxxz, rrrb, sssp; + MagicVec4 xxxw, rrra, sssq; + MagicVec4 xxyx, rrgr, ssts; + MagicVec4 xxyy, rrgg, sstt; + MagicVec4 xxyz, rrgb, sstp; + MagicVec4 xxyw, rrga, sstq; + MagicVec4 xxzx, rrbr, ssps; + MagicVec4 xxzy, rrbg, sspt; + MagicVec4 xxzz, rrbb, sspp; + MagicVec4 xxzw, rrba, sspq; + MagicVec4 xxwx, rrar, ssqs; + MagicVec4 xxwy, rrag, ssqt; + MagicVec4 xxwz, rrab, ssqp; + MagicVec4 xxww, rraa, ssqq; + MagicVec4 xyxx, rgrr, stss; + MagicVec4 xyxy, rgrg, stst; + MagicVec4 xyxz, rgrb, stsp; + MagicVec4 xyxw, rgra, stsq; + MagicVec4 xyyx, rggr, stts; + MagicVec4 xyyy, rggg, sttt; + MagicVec4 xyyz, rggb, sttp; + MagicVec4 xyyw, rgga, sttq; + MagicVec4 xyzx, rgbr, stps; + MagicVec4 xyzy, rgbg, stpt; + MagicVec4 xyzz, rgbb, stpp; + MagicVec4 xyzw, rgba, stpq; + MagicVec4 xywx, rgar, stqs; + MagicVec4 xywy, rgag, stqt; + MagicVec4 xywz, rgab, stqp; + MagicVec4 xyww, rgaa, stqq; + MagicVec4 xzxx, rbrr, spss; + MagicVec4 xzxy, rbrg, spst; + MagicVec4 xzxz, rbrb, spsp; + MagicVec4 xzxw, rbra, spsq; + MagicVec4 xzyx, rbgr, spts; + MagicVec4 xzyy, rbgg, sptt; + MagicVec4 xzyz, rbgb, sptp; + MagicVec4 xzyw, rbga, sptq; + MagicVec4 xzzx, rbbr, spps; + MagicVec4 xzzy, rbbg, sppt; + MagicVec4 xzzz, rbbb, sppp; + MagicVec4 xzzw, rbba, sppq; + MagicVec4 xzwx, rbar, spqs; + MagicVec4 xzwy, rbag, spqt; + MagicVec4 xzwz, rbab, spqp; + MagicVec4 xzww, rbaa, spqq; + MagicVec4 xwxx, rarr, sqss; + MagicVec4 xwxy, rarg, sqst; + MagicVec4 xwxz, rarb, sqsp; + MagicVec4 xwxw, rara, sqsq; + MagicVec4 xwyx, ragr, sqts; + MagicVec4 xwyy, ragg, sqtt; + MagicVec4 xwyz, ragb, sqtp; + MagicVec4 xwyw, raga, sqtq; + MagicVec4 xwzx, rabr, sqps; + MagicVec4 xwzy, rabg, sqpt; + MagicVec4 xwzz, rabb, sqpp; + MagicVec4 xwzw, raba, sqpq; + MagicVec4 xwwx, raar, sqqs; + MagicVec4 xwwy, raag, sqqt; + MagicVec4 xwwz, raab, sqqp; + MagicVec4 xwww, raaa, sqqq; + MagicVec4 yxxx, grrr, tsss; + MagicVec4 yxxy, grrg, tsst; + MagicVec4 yxxz, grrb, tssp; + MagicVec4 yxxw, grra, tssq; + MagicVec4 yxyx, grgr, tsts; + MagicVec4 yxyy, grgg, tstt; + MagicVec4 yxyz, grgb, tstp; + MagicVec4 yxyw, grga, tstq; + MagicVec4 yxzx, grbr, tsps; + MagicVec4 yxzy, grbg, tspt; + MagicVec4 yxzz, grbb, tspp; + MagicVec4 yxzw, grba, tspq; + MagicVec4 yxwx, grar, tsqs; + MagicVec4 yxwy, grag, tsqt; + MagicVec4 yxwz, grab, tsqp; + MagicVec4 yxww, graa, tsqq; + MagicVec4 yyxx, ggrr, ttss; + MagicVec4 yyxy, ggrg, ttst; + MagicVec4 yyxz, ggrb, ttsp; + MagicVec4 yyxw, ggra, ttsq; + MagicVec4 yyyx, gggr, ttts; + MagicVec4 yyyy, gggg, tttt; + MagicVec4 yyyz, gggb, tttp; + MagicVec4 yyyw, ggga, tttq; + MagicVec4 yyzx, ggbr, ttps; + MagicVec4 yyzy, ggbg, ttpt; + MagicVec4 yyzz, ggbb, ttpp; + MagicVec4 yyzw, ggba, ttpq; + MagicVec4 yywx, ggar, ttqs; + MagicVec4 yywy, ggag, ttqt; + MagicVec4 yywz, ggab, ttqp; + MagicVec4 yyww, ggaa, ttqq; + MagicVec4 yzxx, gbrr, tpss; + MagicVec4 yzxy, gbrg, tpst; + MagicVec4 yzxz, gbrb, tpsp; + MagicVec4 yzxw, gbra, tpsq; + MagicVec4 yzyx, gbgr, tpts; + MagicVec4 yzyy, gbgg, tptt; + MagicVec4 yzyz, gbgb, tptp; + MagicVec4 yzyw, gbga, tptq; + MagicVec4 yzzx, gbbr, tpps; + MagicVec4 yzzy, gbbg, tppt; + MagicVec4 yzzz, gbbb, tppp; + MagicVec4 yzzw, gbba, tppq; + MagicVec4 yzwx, gbar, tpqs; + MagicVec4 yzwy, gbag, tpqt; + MagicVec4 yzwz, gbab, tpqp; + MagicVec4 yzww, gbaa, tpqq; + MagicVec4 ywxx, garr, tqss; + MagicVec4 ywxy, garg, tqst; + MagicVec4 ywxz, garb, tqsp; + MagicVec4 ywxw, gara, tqsq; + MagicVec4 ywyx, gagr, tqts; + MagicVec4 ywyy, gagg, tqtt; + MagicVec4 ywyz, gagb, tqtp; + MagicVec4 ywyw, gaga, tqtq; + MagicVec4 ywzx, gabr, tqps; + MagicVec4 ywzy, gabg, tqpt; + MagicVec4 ywzz, gabb, tqpp; + MagicVec4 ywzw, gaba, tqpq; + MagicVec4 ywwx, gaar, tqqs; + MagicVec4 ywwy, gaag, tqqt; + MagicVec4 ywwz, gaab, tqqp; + MagicVec4 ywww, gaaa, tqqq; + MagicVec4 zxxx, brrr, psss; + MagicVec4 zxxy, brrg, psst; + MagicVec4 zxxz, brrb, pssp; + MagicVec4 zxxw, brra, pssq; + MagicVec4 zxyx, brgr, psts; + MagicVec4 zxyy, brgg, pstt; + MagicVec4 zxyz, brgb, pstp; + MagicVec4 zxyw, brga, pstq; + MagicVec4 zxzx, brbr, psps; + MagicVec4 zxzy, brbg, pspt; + MagicVec4 zxzz, brbb, pspp; + MagicVec4 zxzw, brba, pspq; + MagicVec4 zxwx, brar, psqs; + MagicVec4 zxwy, brag, psqt; + MagicVec4 zxwz, brab, psqp; + MagicVec4 zxww, braa, psqq; + MagicVec4 zyxx, bgrr, ptss; + MagicVec4 zyxy, bgrg, ptst; + MagicVec4 zyxz, bgrb, ptsp; + MagicVec4 zyxw, bgra, ptsq; + MagicVec4 zyyx, bggr, ptts; + MagicVec4 zyyy, bggg, pttt; + MagicVec4 zyyz, bggb, pttp; + MagicVec4 zyyw, bgga, pttq; + MagicVec4 zyzx, bgbr, ptps; + MagicVec4 zyzy, bgbg, ptpt; + MagicVec4 zyzz, bgbb, ptpp; + MagicVec4 zyzw, bgba, ptpq; + MagicVec4 zywx, bgar, ptqs; + MagicVec4 zywy, bgag, ptqt; + MagicVec4 zywz, bgab, ptqp; + MagicVec4 zyww, bgaa, ptqq; + MagicVec4 zzxx, bbrr, ppss; + MagicVec4 zzxy, bbrg, ppst; + MagicVec4 zzxz, bbrb, ppsp; + MagicVec4 zzxw, bbra, ppsq; + MagicVec4 zzyx, bbgr, ppts; + MagicVec4 zzyy, bbgg, pptt; + MagicVec4 zzyz, bbgb, pptp; + MagicVec4 zzyw, bbga, pptq; + MagicVec4 zzzx, bbbr, ppps; + MagicVec4 zzzy, bbbg, pppt; + MagicVec4 zzzz, bbbb, pppp; + MagicVec4 zzzw, bbba, pppq; + MagicVec4 zzwx, bbar, ppqs; + MagicVec4 zzwy, bbag, ppqt; + MagicVec4 zzwz, bbab, ppqp; + MagicVec4 zzww, bbaa, ppqq; + MagicVec4 zwxx, barr, pqss; + MagicVec4 zwxy, barg, pqst; + MagicVec4 zwxz, barb, pqsp; + MagicVec4 zwxw, bara, pqsq; + MagicVec4 zwyx, bagr, pqts; + MagicVec4 zwyy, bagg, pqtt; + MagicVec4 zwyz, bagb, pqtp; + MagicVec4 zwyw, baga, pqtq; + MagicVec4 zwzx, babr, pqps; + MagicVec4 zwzy, babg, pqpt; + MagicVec4 zwzz, babb, pqpp; + MagicVec4 zwzw, baba, pqpq; + MagicVec4 zwwx, baar, pqqs; + MagicVec4 zwwy, baag, pqqt; + MagicVec4 zwwz, baab, pqqp; + MagicVec4 zwww, baaa, pqqq; + MagicVec4 wxxx, arrr, qsss; + MagicVec4 wxxy, arrg, qsst; + MagicVec4 wxxz, arrb, qssp; + MagicVec4 wxxw, arra, qssq; + MagicVec4 wxyx, argr, qsts; + MagicVec4 wxyy, argg, qstt; + MagicVec4 wxyz, argb, qstp; + MagicVec4 wxyw, arga, qstq; + MagicVec4 wxzx, arbr, qsps; + MagicVec4 wxzy, arbg, qspt; + MagicVec4 wxzz, arbb, qspp; + MagicVec4 wxzw, arba, qspq; + MagicVec4 wxwx, arar, qsqs; + MagicVec4 wxwy, arag, qsqt; + MagicVec4 wxwz, arab, qsqp; + MagicVec4 wxww, araa, qsqq; + MagicVec4 wyxx, agrr, qtss; + MagicVec4 wyxy, agrg, qtst; + MagicVec4 wyxz, agrb, qtsp; + MagicVec4 wyxw, agra, qtsq; + MagicVec4 wyyx, aggr, qtts; + MagicVec4 wyyy, aggg, qttt; + MagicVec4 wyyz, aggb, qttp; + MagicVec4 wyyw, agga, qttq; + MagicVec4 wyzx, agbr, qtps; + MagicVec4 wyzy, agbg, qtpt; + MagicVec4 wyzz, agbb, qtpp; + MagicVec4 wyzw, agba, qtpq; + MagicVec4 wywx, agar, qtqs; + MagicVec4 wywy, agag, qtqt; + MagicVec4 wywz, agab, qtqp; + MagicVec4 wyww, agaa, qtqq; + MagicVec4 wzxx, abrr, qpss; + MagicVec4 wzxy, abrg, qpst; + MagicVec4 wzxz, abrb, qpsp; + MagicVec4 wzxw, abra, qpsq; + MagicVec4 wzyx, abgr, qpts; + MagicVec4 wzyy, abgg, qptt; + MagicVec4 wzyz, abgb, qptp; + MagicVec4 wzyw, abga, qptq; + MagicVec4 wzzx, abbr, qpps; + MagicVec4 wzzy, abbg, qppt; + MagicVec4 wzzz, abbb, qppp; + MagicVec4 wzzw, abba, qppq; + MagicVec4 wzwx, abar, qpqs; + MagicVec4 wzwy, abag, qpqt; + MagicVec4 wzwz, abab, qpqp; + MagicVec4 wzww, abaa, qpqq; + MagicVec4 wwxx, aarr, qqss; + MagicVec4 wwxy, aarg, qqst; + MagicVec4 wwxz, aarb, qqsp; + MagicVec4 wwxw, aara, qqsq; + MagicVec4 wwyx, aagr, qqts; + MagicVec4 wwyy, aagg, qqtt; + MagicVec4 wwyz, aagb, qqtp; + MagicVec4 wwyw, aaga, qqtq; + MagicVec4 wwzx, aabr, qqps; + MagicVec4 wwzy, aabg, qqpt; + MagicVec4 wwzz, aabb, qqpp; + MagicVec4 wwzw, aaba, qqpq; + MagicVec4 wwwx, aaar, qqqs; + MagicVec4 wwwy, aaag, qqqt; + MagicVec4 wwwz, aaab, qqqp; + MagicVec4 wwww, aaaa, qqqq; }; }; +inline Vec2 operator /(Vec2 a, Vec2 b) +{ + return Vec2(a.x / b.x, a.y / b.y); +} + /* * 4-element quaternions */ @@ -515,6 +974,31 @@ OTHER_OPS(Vec2) OTHER_OPS(Vec3) OTHER_OPS(Vec4) +/* + * Magic swizzling (part 2/2) + */ + +template +inline Vec2 MagicVec2::operator =(Vec2 that) +{ + ptr[I] = that.x; ptr[J] = that.y; + return *this; +} + +template +inline Vec3 MagicVec3::operator =(Vec3 that) +{ + ptr[I] = that.x; ptr[J] = that.y; ptr[K] = that.z; + return *this; +} + +template +inline Vec4 MagicVec4::operator =(Vec4 that) +{ + ptr[I] = that.x; ptr[J] = that.y; ptr[K] = that.z; ptr[L] = that.w; + return *this; +} + /* * 4×4-element matrices */ diff --git a/test/tutorial/tut03.cpp b/test/tutorial/tut03.cpp index 030f7b62..455f8139 100644 --- a/test/tutorial/tut03.cpp +++ b/test/tutorial/tut03.cpp @@ -56,8 +56,8 @@ public: m_size = size; m_size.x = (m_size.x + 15) & ~15; m_size.y = (m_size.y + 15) & ~15; - m_texel_settings = vec4(1.0, 1.0, 2.0, 2.0) / (vec4)m_size.xyxy(); - m_screen_settings = vec4(1.0, 1.0, 0.5, 0.5) * (vec4)m_size.xyxy(); + m_texel_settings = vec4(1.0, 1.0, 2.0, 2.0) / (vec4)m_size.xyxy; + m_screen_settings = vec4(1.0, 1.0, 0.5, 0.5) * (vec4)m_size.xyxy; /* Window size decides the world aspect ratio. For instance, 640×480 * will be mapped to (-0.66,-0.5) - (0.66,0.5). */ diff --git a/test/unit/matrix.cpp b/test/unit/matrix.cpp index 4e6db4e0..1d59a6ab 100644 --- a/test/unit/matrix.cpp +++ b/test/unit/matrix.cpp @@ -121,14 +121,14 @@ LOLUNIT_FIXTURE(MatrixTest) vec2 a1(1.0f, 3.0f); vec3 b(a1, 0.0f); - vec2 a2(b.xy()); + vec2 a2(b.xy); LOLUNIT_ASSERT_EQUAL(b.x, a1.x); LOLUNIT_ASSERT_EQUAL(b.y, a1.y); LOLUNIT_ASSERT_EQUAL(b.z, 0.0f); LOLUNIT_ASSERT_EQUAL(a2, a1); vec4 c(a1, 0.0f, 0.0f); - vec2 a3(c.xy()); + vec2 a3(c.xy); LOLUNIT_ASSERT_EQUAL(c.x, a1.x); LOLUNIT_ASSERT_EQUAL(c.y, a1.y); LOLUNIT_ASSERT_EQUAL(c.z, 0.0f);