mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-24 01:00:25 +00:00
simplified hyperpoint.cpp a bit
This commit is contained in:
parent
1d3ee8f0a1
commit
fc964ec7b2
28
hyper.h
28
hyper.h
@ -27,10 +27,9 @@ typedef long double ld;
|
||||
|
||||
#define DEBSM(x)
|
||||
|
||||
struct hyperpoint {
|
||||
ld tab[3];
|
||||
ld& operator [] (int i) { return tab[i]; }
|
||||
const ld& operator [] (int i) const { return tab[i]; }
|
||||
struct hyperpoint : array<ld, 3> {
|
||||
hyperpoint() {}
|
||||
hyperpoint(ld x, ld y, ld z) : array<ld,3> {x,y,z} {}
|
||||
};
|
||||
|
||||
struct transmatrix {
|
||||
@ -56,7 +55,7 @@ inline transmatrix operator * (const transmatrix& T, const transmatrix& U) {
|
||||
return R;
|
||||
}
|
||||
|
||||
hyperpoint hpxyz(ld x, ld y, ld z);
|
||||
#define hpxyz hyperpoint
|
||||
|
||||
namespace hyperpoint_vec {
|
||||
|
||||
@ -2256,19 +2255,24 @@ struct qcir {
|
||||
|
||||
enum eKind { pkPoly, pkLine, pkString, pkCircle, pkShape, pkResetModel, pkSpecial };
|
||||
|
||||
union polyunion {
|
||||
qpoly poly;
|
||||
qline line;
|
||||
qchr chr;
|
||||
qcir cir;
|
||||
double dvalue;
|
||||
polyunion() {}
|
||||
};
|
||||
|
||||
struct polytodraw {
|
||||
eKind kind;
|
||||
int prio, col;
|
||||
union {
|
||||
qpoly poly;
|
||||
qline line;
|
||||
qchr chr;
|
||||
qcir cir;
|
||||
double dvalue;
|
||||
} u;
|
||||
polyunion u;
|
||||
#if CAP_ROGUEVIZ
|
||||
string* info;
|
||||
polytodraw() { info = NULL; }
|
||||
#else
|
||||
polytodraw() {}
|
||||
#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
|
||||
// (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) {
|
||||
// EUCLIDEAN
|
||||
return hpxyz(x,y, euclid ? 1 : sphere ? sqrt(1-x*x-y*y) : sqrt(1+x*x+y*y));
|
||||
}
|
||||
|
||||
// center of the pseudosphere
|
||||
const hyperpoint Hypc = { {0,0,0} };
|
||||
const hyperpoint Hypc(0,0,0);
|
||||
|
||||
// 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 ;) )
|
||||
const hyperpoint Cx1 = { {1,0,1.41421356237} };
|
||||
const hyperpoint Cx1(1,0,1.41421356237);
|
||||
|
||||
// this function returns approximate square of distance between two points
|
||||
// (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
|
||||
hyperpoint normalize(hyperpoint H) {
|
||||
ld Z;
|
||||
if(sphere) Z = sqrt(intval(H, Hypc));
|
||||
else if(!euclid) {
|
||||
Z = intval(H, Hypc);
|
||||
Z = sqrt(-Z);
|
||||
}
|
||||
else Z = H[2];
|
||||
ld Z = zlevel(H);
|
||||
for(int c=0; c<3; c++) H[c] /= Z;
|
||||
return H;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user