Last active
March 19, 2021 23:07
-
-
Save hikari-no-yume/5a3d68c1a1d9593ce776c33c3c9f154c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "who-needs-glsl-anyway.h" | |
#include <stdio.h> | |
int main(void) | |
{ | |
vec4 v = { {1.5, 2.5, 3.5, 4.5} }; | |
printf("%f, %f, %f, %f\n", v.rg.x, v.xy.t, v.stp.z, v.w); | |
for (int i = 3; i >= 0; i--) { | |
printf("%f\n", v._[i]); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define DEF_VEC2(_0, _1) \ | |
struct { \ | |
float _0; \ | |
float _1; \ | |
}; | |
typedef union { | |
float _[2]; | |
union { | |
DEF_VEC2(r, g) | |
DEF_VEC2(x, y) | |
DEF_VEC2(s, t) | |
}; | |
} vec2; | |
#define DEF_VEC3(_0, _1, _2) \ | |
struct { \ | |
union { \ | |
DEF_VEC2(_0, _1) \ | |
vec2 _0##_1; \ | |
}; \ | |
float _2; \ | |
}; | |
typedef union { | |
float _[3]; | |
union { | |
DEF_VEC3(r, g, b) | |
DEF_VEC3(x, y, z) | |
DEF_VEC3(s, t, p) | |
}; | |
} vec3; | |
#define DEF_VEC4(_0, _1, _2, _3) \ | |
struct { \ | |
union { \ | |
DEF_VEC3(_0, _1, _2) \ | |
vec3 _0##_1##_2; \ | |
}; \ | |
float _3; \ | |
}; | |
typedef union { | |
float _[4]; | |
union { | |
DEF_VEC4(r, g, b, a) | |
DEF_VEC4(x, y, z, w) | |
DEF_VEC4(s, t, p, q) | |
}; | |
} vec4; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment