From ad5ec24e7b52d381b282d0b461d7b38977eb3420 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 6 Aug 2019 11:56:01 +0200 Subject: [PATCH] transmatrix now implemented as an array of hyperpoints --- drawing.cpp | 4 ++-- hyper.h | 27 ++++++++++++++++++--------- hyperpoint.cpp | 14 +++----------- rug.cpp | 7 ++++++- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/drawing.cpp b/drawing.cpp index 7cfe252a..1dea8813 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -349,8 +349,8 @@ void filledPolygonColorI(SDL_Surface *s, int* px, int *py, int polyi, color_t co #if CAP_TEXTURE void drawTexturedTriangle(SDL_Surface *s, int *px, int *py, glvertex *tv, color_t col) { - transmatrix source = {{{ld(px[0]),ld(px[1]),ld(px[2])}, {ld(py[0]),ld(py[1]),ld(py[2])}, {1,1,1}}}; - transmatrix target = {{{tv[0][0],tv[1][0],tv[2][0]}, {tv[0][1],tv[1][1],tv[2][1]}, {1,1,1}}}; + transmatrix source( point3(px[0], px[1], px[2]), point3(py[0], py[1], py[2]), point3(1,1,1), point31(0,0,0) ); + transmatrix target( point3(tv[0][0], tv[1][0], tv[2][0]), point3(tv[0][1],tv[1][1],tv[2][1]), point3(1,1,1), point31(0,0,0) ); transmatrix isource = inverse(source); int minx = px[0], maxx = px[0]; int miny = py[0], maxy = py[0]; diff --git a/hyper.h b/hyper.h index 654b9f8e..52894ea5 100644 --- a/hyper.h +++ b/hyper.h @@ -346,10 +346,14 @@ struct hyperpoint : array { } }; -struct transmatrix { - ld tab[MAXMDIM][MAXMDIM]; - ld * operator [] (int i) { return tab[i]; } - const ld * operator [] (int i) const { return tab[i]; } +struct transmatrix : array { + transmatrix() {} + transmatrix(hyperpoint a, hyperpoint b, hyperpoint c, hyperpoint d) { + (*this)[0] = a; + (*this)[1] = b; + (*this)[2] = c; + (*this)[3] = d; + } }; inline hyperpoint operator * (const transmatrix& T, const hyperpoint& H) { @@ -371,12 +375,16 @@ inline transmatrix operator * (const transmatrix& T, const transmatrix& U) { return R; } -constexpr transmatrix diag(ld a, ld b, ld c, ld d) { - #if MAXMDIM==3 - return transmatrix{{{a,0,0}, {0,b,0}, {0,0,c}}}; - #else - return transmatrix{{{a,0,0,0}, {0,b,0,0}, {0,0,c,0}, {0,0,0,d}}}; +inline transmatrix diag(ld a, ld b, ld c, ld d) { + transmatrix T; + for(int i=0; i= 4 diff --git a/rug.cpp b/rug.cpp index 20494be8..6771c696 100644 --- a/rug.cpp +++ b/rug.cpp @@ -455,7 +455,12 @@ void buildTorusRug() { // 7,-17 // transmatrix z1 = {{{22,7,0}, {1,-17,0}, {0,0,1}}}; - transmatrix z1 = {{{(ld)solution.first.x,(ld)solution.second.x,0}, {(ld)solution.first.y,(ld)solution.second.y,0}, {0,0,1}}}; + transmatrix z1( + point3(solution.first.x, solution.second.x, 0), + point3(solution.first.y, solution.second.y, 0), + point3(0, 0, 1), + point31(0, 0, 0) + ); transmatrix z2 = inverse(z1); if(gwhere == gSphere) {