mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-18 06:50:27 +00:00
transmatrix now implemented as an array of hyperpoints
This commit is contained in:
parent
c1b1e61069
commit
ad5ec24e7b
@ -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];
|
||||
|
27
hyper.h
27
hyper.h
@ -346,10 +346,14 @@ struct hyperpoint : array<ld, MAXMDIM> {
|
||||
}
|
||||
};
|
||||
|
||||
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<hyperpoint, MAXMDIM> {
|
||||
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<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;
|
||||
#endif
|
||||
return T;
|
||||
}
|
||||
|
||||
const static hyperpoint Hypc = hyperpoint(0, 0, 0, 0);
|
||||
@ -406,6 +414,7 @@ const static transmatrix centralsym = diag(-1,-1,-1,-1);
|
||||
inline hyperpoint hpxyz(ld x, ld y, ld z) { return DIM == 2 ? hyperpoint(x,y,z,0) : hyperpoint(x,y,0,z); }
|
||||
inline hyperpoint hpxyz3(ld x, ld y, ld z, ld w) { return DIM == 2 ? hyperpoint(x,y,w,0) : hyperpoint(x,y,z,w); }
|
||||
inline hyperpoint point3(ld x, ld y, ld z) { return hyperpoint(x,y,z,0); }
|
||||
inline hyperpoint point31(ld x, ld y, ld z) { return hyperpoint(x,y,z,1); }
|
||||
inline hyperpoint point2(ld x, ld y) { return hyperpoint(x,y,0,0); }
|
||||
|
||||
namespace hyperpoint_vec {
|
||||
|
@ -353,22 +353,14 @@ 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 {{{a,b,c,0},{d,e,f,0},{g,h,i,0},{0,0,0,1}}};
|
||||
return transmatrix(hyperpoint(a,b,c,0), hyperpoint(d,e,f,0), hyperpoint(g,h,i,0), hyperpoint(0,0,0,1));
|
||||
else
|
||||
return transmatrix {{{a,b,0,c},{d,e,0,f},{0,0,1,0},{g,h,0,i}}};
|
||||
#endif
|
||||
return transmatrix(hyperpoint(a,b,0,c), hyperpoint(d,e,0,f), hyperpoint(0,0,1,0), hyperpoint(g,h,0,i));
|
||||
}
|
||||
|
||||
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) {
|
||||
#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
|
||||
return transmatrix(hyperpoint(a,b,c,d), hyperpoint(e,f,g,h), hyperpoint(i,j,k,l), hyperpoint(m,n,o,p));
|
||||
}
|
||||
|
||||
#if MAXMDIM >= 4
|
||||
|
7
rug.cpp
7
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user