mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-04-21 10:13:14 +00:00
rogueviz/balls: improvement
This commit is contained in:
parent
6d8cc0eadc
commit
ec6068944f
@ -9,6 +9,10 @@
|
||||
|
||||
namespace rogueviz {
|
||||
|
||||
namespace balls {
|
||||
|
||||
bool on = true;
|
||||
|
||||
struct ball {
|
||||
hyperpoint at;
|
||||
hyperpoint vel;
|
||||
@ -21,10 +25,8 @@ ld r_big_ball = 1;
|
||||
|
||||
hpcshape shSmallBall, shBigBall, shShell;
|
||||
|
||||
bool init = false;
|
||||
|
||||
void initialize() {
|
||||
init = true;
|
||||
void initialize(int max_ball) {
|
||||
on = true;
|
||||
|
||||
cgi.make_ball(shSmallBall, r_small_ball, 2);
|
||||
cgi.make_ball(shBigBall, r_big_ball, 4);
|
||||
@ -33,7 +35,7 @@ void initialize() {
|
||||
shShell.flags |= POLY_TRIANGLES;
|
||||
|
||||
auto pt = [] (int i, int j) {
|
||||
cgi.hpcpush(direct_exp(cspin(0, 2, -30*degree) * cspin(0, 2, 90*degree) * cspin(0, 1, j * degree) * cspin(0, 2, i * M_PI / 2 / 16) * ztangent(r_big_ball)));
|
||||
cgi.hpcpush(direct_exp(/* cspin(0, 2, -30*degree) **/ cspin(2, 1, 90*degree) * cspin(0, 1, j * degree) * cspin(0, 2, i * M_PI / 2 / 16) * ztangent(r_big_ball)));
|
||||
};
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
@ -48,9 +50,9 @@ void initialize() {
|
||||
cgi.finishshape();
|
||||
cgi.extra_vertices();
|
||||
|
||||
for(int a=-3; a<=3; a++)
|
||||
for(int b=-3; b<=3; b++)
|
||||
for(int c=-3; c<=3; c++)
|
||||
for(int a=-max_ball; a<=max_ball; a++)
|
||||
for(int b=-max_ball; b<=max_ball; b++)
|
||||
for(int c=-max_ball; c<=max_ball; c++)
|
||||
{
|
||||
hyperpoint h = point3(0.21*a + 1e-2, 0.21*b, 0.21*c);
|
||||
|
||||
@ -63,13 +65,13 @@ void initialize() {
|
||||
|
||||
}
|
||||
|
||||
bool draw_balls(cell *c, const transmatrix& V) {
|
||||
if(!init) initialize();
|
||||
bool draw_balls(cell *c, const shiftmatrix& V) {
|
||||
if(!on) return false;
|
||||
|
||||
if(c == currentmap->gamestart()) {
|
||||
for(auto& b: balls)
|
||||
queuepoly(V * rgpushxto0(b.at), shSmallBall, 0xFFFFFFFF);
|
||||
queuepoly(Id, shShell, 0x0000F0FF);
|
||||
queuepoly(V, shShell, 0x0000F0FF);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -104,6 +106,7 @@ ld elastic_out = .2;
|
||||
ld gravity = 1;
|
||||
|
||||
bool turn(int delta) {
|
||||
if(!on) return false;
|
||||
for(int i=0; i<delta; i++) {
|
||||
for(auto& b: balls) {
|
||||
/* gravity direction: z */
|
||||
@ -118,7 +121,7 @@ bool turn(int delta) {
|
||||
b.vel -= b.at * e2;
|
||||
}
|
||||
|
||||
hyperpoint v = inverse_exp(b.at);
|
||||
hyperpoint v = inverse_exp(shiftless(b.at));
|
||||
ld d = hypot_d(3, v);
|
||||
ld rbs = r_big_ball - r_small_ball;
|
||||
if(d > rbs) {
|
||||
@ -142,12 +145,12 @@ bool turn(int delta) {
|
||||
for(auto& b1: balls)
|
||||
for(auto& b2: balls) {
|
||||
if(&b2 == &b1) break;
|
||||
hyperpoint dif = inverse_exp(gpushxto0(b1.at) * b2.at);
|
||||
hyperpoint dif = inverse_exp(shiftless(gpushxto0(b1.at) * b2.at));
|
||||
ld d = hypot_d(3, dif);
|
||||
if(d < r_small_ball * 2) {
|
||||
hyperpoint ort1 = (dif / d);
|
||||
ld vel1 = +inner(gpushxto0(b1.at) * b1.vel, ort1);
|
||||
hyperpoint ort2 = inverse_exp(gpushxto0(b2.at) * b1.at) / d;
|
||||
hyperpoint ort2 = inverse_exp(shiftless(gpushxto0(b2.at) * b1.at)) / d;
|
||||
ld vel2 = +inner(gpushxto0(b2.at) * b2.vel, ort2);
|
||||
ld vels = vel1 + vel2;
|
||||
if(vels < 0) continue;
|
||||
@ -162,8 +165,32 @@ bool turn(int delta) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto celldemo = addHook(hooks_drawcell, 100, draw_balls) +
|
||||
addHook(shmup::hooks_turn, 100, turn);
|
||||
int args() {
|
||||
using namespace arg;
|
||||
|
||||
if(0) ;
|
||||
|
||||
else if(argis("-ball-physics")) {
|
||||
start_game();
|
||||
check_cgi();
|
||||
cgi.require_shapes();
|
||||
shift();
|
||||
initialize(argi());
|
||||
View = cspin(1, 2, M_PI/2);
|
||||
}
|
||||
|
||||
else return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
auto celldemo = addHook(hooks_drawcell, 100, draw_balls) +
|
||||
addHook(shmup::hooks_turn, 100, turn) +
|
||||
addHook(hooks_args, 100, args) +
|
||||
addHook(hooks_clearmemory, 40, [] () {
|
||||
balls.clear();
|
||||
on = false;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user