ads-game:: past/future cone view

This commit is contained in:
Zeno Rogue 2022-10-15 17:56:15 +02:00
parent 1ace6d4fff
commit 38fddfa43f
3 changed files with 79 additions and 6 deletions

View File

@ -340,7 +340,7 @@ void view_ads_game() {
});
}
if(!game_over && !paused && !in_replay && !hv) {
if(!game_over && !paused && !in_replay && !hv && !which_cross) {
poly_outline = 0xFF;
if(ship_pt < invincibility_pt) {
ld u = (invincibility_pt-ship_pt) / ads_how_much_invincibility;

View File

@ -411,9 +411,38 @@ bool ds_turn(int idelta) {
hyperpoint pov = point30(0, 0, 1);
cross_result ds_cross0(transmatrix T) {
cross_result ds_cross0_cone(const transmatrix& T, ld which) {
ld a = T[2][2];
ld b = T[2][3];
// a * cosh(t) + b * sinh(t) = 1
// solution: t = log((1 +- sqrt(-a^2 + b^2 + 1))/(a + b))
ld underroot = (1+b*b-a*a);
if(underroot < 0) return cross_result { Hypc, 0};
ld underlog = (1 + which * sqrt(underroot)) / (a + b);
if(underlog < 0) return cross_result { Hypc, 0};
ld t = log(underlog);
cross_result res;
res.shift = t;
res.h = T * hyperpoint(0, 0, cosh(t), sinh(t));
if(abs(res.h[2] - 1) > .01) return cross_result{Hypc, 0};
res.h[2] -= res.h[3];
res.h[3] = 0;
res.h /= hypot_d(3, res.h);
// res.h[2] = sqrt(1 - res.h[3] * res.h[3]); res.h[3] = 0;
return res;
}
cross_result ds_cross0_sim(const transmatrix& T) {
// h = T * (0 0 cosh(t) sinh(t))
// h[3] == 0
// T[3][2] * cosh(t) + T[3][3] * sinh(t) = 0
// T[3][2] + T[3][3] * tanh(t) = 0
ld tt = - T[3][2] / T[3][3];
@ -425,6 +454,10 @@ cross_result ds_cross0(transmatrix T) {
return res;
}
cross_result ds_cross0(const transmatrix& T) {
return which_cross ? ds_cross0_cone(T, which_cross) : ds_cross0_sim(T);
}
cross_result ds_cross0_light(transmatrix T) {
// h = T * (t 0 1 t); h[3] == 0
ld t = T[3][2] / -(T[3][0] + T[3][3]);
@ -626,7 +659,7 @@ void view_ds_game() {
queuestr(shiftless(sphereflip), .1, str, 0xFFFF00, 8);
}
if(paused && !game_over && !in_replay && !hv) {
if(paused && !game_over && !in_replay && !hv && !which_cross) {
vector<hyperpoint> pts;
int ok = 0, bad = 0;
for(int i=0; i<=360; i++) {

View File

@ -115,7 +115,7 @@ extern ads_matrix current;
* shift is T's proper time at the point of crossing, and h=(x,y,z) is the Minkowski hyperboloid point where it crosses.
**/
cross_result cross0(ads_matrix hz) {
cross_result cross0_sim(ads_matrix hz) {
transmatrix deg90 = chg_shift(90*degree);
hyperpoint uhz = unshift(hz * C0);
@ -145,7 +145,47 @@ cross_result cross0(ads_matrix hz) {
return cross_result{uhzt, t};
}
/** Similar as cross0_light but for light-like wordlines.
/** 0 = draw time t=0, -1 = take light into account, +1 = predict future */
ld which_cross;
/** Similar as cross0_sim but detects a crossing with the light cone. That is,
* the spacetime event that was (which==-1) or will be (which==+1) seen by
* the frame of reference.
**/
cross_result cross0_cone(ads_matrix hz, ld which) {
auto cr = cross0_sim(hz);
hz = hz * chg_shift(cr.shift);
auto uhz = unshift(hz);
// (hz.T * chg_shift(t) * C0)[3] = 1
// (hz.T * cspin(2, 3, t) * C0)[3] = 1
// (hz.T * [0, 0, sin(t), cos(t)])[3] = 1
ld a = uhz[3][3];
ld b = uhz[3][2];
// b sin(t) + a cos(t) = 1
// t = 2*atan((b +- sqrt(a^2 + b^2 - 1))/(a + 1))
ld underroot = a * a + b * b - 1;
if(underroot < 0) return { Hypc, 0 };
ld t = 2 * atan((b + which * sqrt(underroot)) / (a+1));
hyperpoint uhzt = uhz * chg_shift(t) * C0;
uhzt[2] = sqrt(uhzt[2]*uhzt[2] + uhzt[3]*uhzt[3]);
uhzt[3] = 0;
return cross_result{uhzt, cr.shift + t};
}
cross_result cross0(const ads_matrix& T) {
return which_cross ? cross0_cone(T, which_cross) : cross0_sim(T);
}
/** Similar as cross0_sim but for light-like wordlines.
* The point returned by cross0_light(T) is the same as the limit of cross0(T * lorentz(0, 2, v)).
**/