mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-25 17:40:36 +00:00
simplified hyperpoint.cpp a bit
This commit is contained in:
parent
1d3ee8f0a1
commit
fc964ec7b2
24
hyper.h
24
hyper.h
@ -27,10 +27,9 @@ typedef long double ld;
|
|||||||
|
|
||||||
#define DEBSM(x)
|
#define DEBSM(x)
|
||||||
|
|
||||||
struct hyperpoint {
|
struct hyperpoint : array<ld, 3> {
|
||||||
ld tab[3];
|
hyperpoint() {}
|
||||||
ld& operator [] (int i) { return tab[i]; }
|
hyperpoint(ld x, ld y, ld z) : array<ld,3> {x,y,z} {}
|
||||||
const ld& operator [] (int i) const { return tab[i]; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct transmatrix {
|
struct transmatrix {
|
||||||
@ -56,7 +55,7 @@ inline transmatrix operator * (const transmatrix& T, const transmatrix& U) {
|
|||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
|
|
||||||
hyperpoint hpxyz(ld x, ld y, ld z);
|
#define hpxyz hyperpoint
|
||||||
|
|
||||||
namespace hyperpoint_vec {
|
namespace hyperpoint_vec {
|
||||||
|
|
||||||
@ -2256,19 +2255,24 @@ struct qcir {
|
|||||||
|
|
||||||
enum eKind { pkPoly, pkLine, pkString, pkCircle, pkShape, pkResetModel, pkSpecial };
|
enum eKind { pkPoly, pkLine, pkString, pkCircle, pkShape, pkResetModel, pkSpecial };
|
||||||
|
|
||||||
struct polytodraw {
|
union polyunion {
|
||||||
eKind kind;
|
|
||||||
int prio, col;
|
|
||||||
union {
|
|
||||||
qpoly poly;
|
qpoly poly;
|
||||||
qline line;
|
qline line;
|
||||||
qchr chr;
|
qchr chr;
|
||||||
qcir cir;
|
qcir cir;
|
||||||
double dvalue;
|
double dvalue;
|
||||||
} u;
|
polyunion() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct polytodraw {
|
||||||
|
eKind kind;
|
||||||
|
int prio, col;
|
||||||
|
polyunion u;
|
||||||
#if CAP_ROGUEVIZ
|
#if CAP_ROGUEVIZ
|
||||||
string* info;
|
string* info;
|
||||||
polytodraw() { info = NULL; }
|
polytodraw() { info = NULL; }
|
||||||
|
#else
|
||||||
|
polytodraw() {}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -118,24 +118,18 @@ ld atan2_auto(ld y, ld x) {
|
|||||||
// by points in 3D space (Minkowski space) such that x^2+y^2-z^2 == -1, z > 0
|
// by points in 3D space (Minkowski space) such that x^2+y^2-z^2 == -1, z > 0
|
||||||
// (this is analogous to representing a sphere with points such that x^2+y^2+z^2 == 1)
|
// (this is analogous to representing a sphere with points such that x^2+y^2+z^2 == 1)
|
||||||
|
|
||||||
hyperpoint hpxyz(ld x, ld y, ld z) {
|
|
||||||
// EUCLIDEAN
|
|
||||||
hyperpoint r; r[0] = x; r[1] = y; r[2] = z; return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
hyperpoint hpxy(ld x, ld y) {
|
hyperpoint hpxy(ld x, ld y) {
|
||||||
// EUCLIDEAN
|
|
||||||
return hpxyz(x,y, euclid ? 1 : sphere ? sqrt(1-x*x-y*y) : sqrt(1+x*x+y*y));
|
return hpxyz(x,y, euclid ? 1 : sphere ? sqrt(1-x*x-y*y) : sqrt(1+x*x+y*y));
|
||||||
}
|
}
|
||||||
|
|
||||||
// center of the pseudosphere
|
// center of the pseudosphere
|
||||||
const hyperpoint Hypc = { {0,0,0} };
|
const hyperpoint Hypc(0,0,0);
|
||||||
|
|
||||||
// origin of the hyperbolic plane
|
// origin of the hyperbolic plane
|
||||||
const hyperpoint C0 = { {0,0,1} };
|
const hyperpoint C0(0,0,1);
|
||||||
|
|
||||||
// a point (I hope this number needs no comments ;) )
|
// a point (I hope this number needs no comments ;) )
|
||||||
const hyperpoint Cx1 = { {1,0,1.41421356237} };
|
const hyperpoint Cx1(1,0,1.41421356237);
|
||||||
|
|
||||||
// this function returns approximate square of distance between two points
|
// this function returns approximate square of distance between two points
|
||||||
// (in the spherical analogy, this would be the distance in the 3D space,
|
// (in the spherical analogy, this would be the distance in the 3D space,
|
||||||
@ -207,13 +201,7 @@ ld hypot_auto(ld x, ld y) {
|
|||||||
|
|
||||||
// move H back to the sphere/hyperboloid/plane
|
// move H back to the sphere/hyperboloid/plane
|
||||||
hyperpoint normalize(hyperpoint H) {
|
hyperpoint normalize(hyperpoint H) {
|
||||||
ld Z;
|
ld Z = zlevel(H);
|
||||||
if(sphere) Z = sqrt(intval(H, Hypc));
|
|
||||||
else if(!euclid) {
|
|
||||||
Z = intval(H, Hypc);
|
|
||||||
Z = sqrt(-Z);
|
|
||||||
}
|
|
||||||
else Z = H[2];
|
|
||||||
for(int c=0; c<3; c++) H[c] /= Z;
|
for(int c=0; c<3; c++) H[c] /= Z;
|
||||||
return H;
|
return H;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user