transmatrix back to old definition (some weird bugs?) but improved

This commit is contained in:
Zeno Rogue 2019-08-07 20:03:50 +02:00
parent 64e212cd42
commit 60bf28f359
4 changed files with 38 additions and 24 deletions

View File

@ -349,8 +349,18 @@ 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( 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 source = matrix3(
px[0], px[1], px[2],
py[0], py[1], py[2],
1, 1, 1);
transmatrix target = matrix3(
tv[0][0], tv[1][0], tv[2][0],
tv[0][1], tv[1][1], tv[2][1],
1, 1, 1
);
transmatrix isource = inverse(source);
int minx = px[0], maxx = px[0];
int miny = py[0], maxy = py[0];

26
hyper.h
View File

@ -348,14 +348,10 @@ struct hyperpoint : array<ld, MAXMDIM> {
}
};
struct transmatrix : array<hyperpoint, MAXMDIM> {
transmatrix() {}
transmatrix(hyperpoint a, hyperpoint b, hyperpoint c, hyperpoint d) {
(*this)[0] = a;
(*this)[1] = b;
(*this)[2] = c;
(*this)[3] = d;
}
struct transmatrix {
ld tab[MAXMDIM][MAXMDIM];
hyperpoint& operator [] (int i) { return (hyperpoint&)tab[i][0]; }
const ld * operator [] (int i) const { return tab[i]; }
};
inline hyperpoint operator * (const transmatrix& T, const hyperpoint& H) {
@ -377,16 +373,12 @@ inline transmatrix operator * (const transmatrix& T, const transmatrix& U) {
return R;
}
inline transmatrix diag(ld a, ld b, ld c, ld d) {
transmatrix T;
for(int i=0; i<MAXMDIM; i++) for(int j=0; j<MAXMDIM; j++) T[i][j] = 0;
T[0][0] = a;
T[1][1] = b;
T[2][2] = c;
#if MAXMDIM==4
T[3][3] = d;
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}}};
#endif
return T;
}
const static hyperpoint Hypc = hyperpoint(0, 0, 0, 0);

View File

@ -345,14 +345,22 @@ transmatrix ypush(ld alpha) { return cpush(1, alpha); }
transmatrix zpush(ld z) { return cpush(2, z); }
transmatrix matrix3(ld a, ld b, ld c, ld d, ld e, ld f, ld g, ld h, ld i) {
#if MAXMDIM==3
return transmatrix {{{a,b,c},{d,e,f},{g,h,i}}};
#else
if(DIM == 2)
return transmatrix(hyperpoint(a,b,c,0), hyperpoint(d,e,f,0), hyperpoint(g,h,i,0), hyperpoint(0,0,0,1));
return transmatrix {{{a,b,c,0},{d,e,f,0},{g,h,i,0},{0,0,0,1}}};
else
return transmatrix(hyperpoint(a,b,0,c), hyperpoint(d,e,0,f), hyperpoint(0,0,1,0), hyperpoint(g,h,0,i));
return transmatrix {{{a,b,0,c},{d,e,0,f},{0,0,1,0},{g,h,0,i}}};
#endif
}
transmatrix matrix4(ld a, ld b, ld c, ld d, ld e, ld f, ld g, ld h, ld i, ld j, ld k, ld l, ld m, ld n, ld o, ld p) {
return transmatrix(hyperpoint(a,b,c,d), hyperpoint(e,f,g,h), hyperpoint(i,j,k,l), hyperpoint(m,n,o,p));
#if MAXMDIM==3
return transmatrix {{{a,b,d},{e,f,h},{m,n,p}}};
#else
return transmatrix {{{a,b,c,d},{e,f,g,h},{i,j,k,l},{m,n,o,p}}};
#endif
}
#if MAXMDIM >= 4

View File

@ -454,13 +454,17 @@ void buildTorusRug() {
// 22,1
// 7,-17
transmatrix z1 = matrix3(
solution.first.x, solution.second.x, 0,
solution.first.y, solution.second.y, 0,
0, 0, 1);
// transmatrix z1 = {{{22,7,0}, {1,-17,0}, {0,0,1}}};
transmatrix z1(
/* 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) {