diff --git a/main/include/glga.hpp b/main/include/glga.hpp new file mode 100644 index 0000000..2aea9be --- /dev/null +++ b/main/include/glga.hpp @@ -0,0 +1,121 @@ +#include + +namespace ga { + struct Vec; + struct Bivec; + struct Mat; + + struct Vec { + float x, y, z, w; + + Vec(float x, float y, float z, float w) : + x(x), y(y), z(z), w(w) {} + + }; + + struct Bivec { + float xy, yz, zw, wx, xz, yw; + + Bivec(float xy, float yz, float zw, float wx, float xz, float yw) : + xy(xy), yz(yz), zw(zw), wx(wx), xz(xz), yw(yw) {} + }; + + struct Mat { + Vec x, y, z, w; + + Mat(Vec x, Vec y, Vec z, Vec w) : x(x), y(y), z(z), w(w) {} + }; + + namespace unit { + Vec x() { return Vec(1, 0, 0, 0); }; + + Vec y() { return Vec(1, 0, 0, 0); }; + + Vec z() { return Vec(1, 0, 0, 0); }; + + Vec w() { return Vec(1, 0, 0, 0); }; + + Bivec xy() { return Bivec(1, 0, 0, 0, 0, 0); } + + Bivec yz() { return Bivec(0, 1, 0, 0, 0, 0); } + + Bivec zw() { return Bivec(0, 0, 1, 0, 0, 0); } + + Bivec wx() { return Bivec(0, 0, 0, 1, 0, 0); } + + Bivec xz() { return Bivec(0, 0, 0, 0, 1, 0); } + + Bivec yw() { return Bivec(0, 0, 0, 0, 0, 1); } + } + + float length2(Vec v) { + return v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w; + } + + float length2(Bivec v) { + return v.xy * v.xy + v.yz * v.yz + v.zw * v.zw + + v.wx * v.wx + v.xz * v.xz + v.yw * v.yw; + } + + float length(Vec v) { return sqrt(length2(v)); } + + float length(Bivec v) { return sqrt(length2(v)); } + + Vec add(Vec u, Vec v) { + return Vec(u.x + v.x, + u.y + v.y, + u.z + v.z, + u.w + v.w); + } + + Bivec add(Bivec u, Bivec v) { + Bivec(u.xy + v.xy, + u.yz + v.yz, + u.zw + v.zw, + u.wx + v.wx, + u.xz + v.xz, + u.yw + v.yw); + } + + Vec mul(float c, Vec v) { + return Vec(c * v.x, + c * v.y, + c * v.z, + c * v.w); + } + + Bivec mul(float c, Bivec v) { + Bivec(c * v.xy, + c * v.yz, + c * v.zw, + c * v.wx, + c * v.xz, + c * v.yw); + } + + Vec normalize(Vec v) { + return mul(1 / length(v), v); + } + + Bivec normalize(Bivec v) { + return mul(1 / length(v), v); + } + + Mat matrix(float c) { + // c as a transformation + // scale by c + return Mat(Vec(c, 0, 0, 0), Vec(0, c, 0, 0), Vec(0, 0, c, 0), Vec(0, 0, 0, c)); + } + + Mat matrix(Vec v) { + // v as a transformation + // reflect along v + return matrix(1); // todo reflection + } + + Mat rotor(Bivec v) { + // v as a transformation + // rotate along v + return matrix(1); + } +} \ No newline at end of file diff --git a/main/src/main.cpp b/main/src/main.cpp index 6a3562d..e735b61 100644 --- a/main/src/main.cpp +++ b/main/src/main.cpp @@ -7,6 +7,8 @@ #include #include +#include "glga.hpp" + #define PI 3.14159f namespace util { @@ -200,16 +202,19 @@ struct State { float s_ = std::sin(3.f / 8); glBindBuffer(GL_UNIFORM_BUFFER, ubo); - util::bufferData(GL_UNIFORM_BUFFER, { - 1.f / 4 / ar, 0, 0, 0, - 0, 0, 1.f / 10, 0, - 0, 1.f / 4, 0, 0, - 0, 0, 0, 1, + util::bufferData(GL_UNIFORM_BUFFER, { + ga::Mat( + ga::Vec(1.f / 4 / ar, 0, 0, 0), + ga::Vec(0, 0, 1.f / 10, 0), + ga::Vec(0, 1.f / 4, 0, 0), + ga::Vec(0, 0, 0, 1.f)), - c, 0, 0, s, - 0, c_, s_, 0, - 0, -s_, c_, 0, - -s, 0, 0, c + ga::Mat( + ga::Vec(c, 0, 0, s), + ga::Vec(0, c_, s_, 0), + ga::Vec(0, -s_, c_, 0), + ga::Vec(-s, 0, 0, c) + ) }, GL_STREAM_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); }