games/galaxy: Change button 2 to reposition the galaxy, remove "move" from the button 3 menu

This commit is contained in:
spew 2017-03-01 15:59:26 -06:00
parent a4895f5e44
commit 0e9973c80f
5 changed files with 29 additions and 43 deletions

View file

@ -45,15 +45,12 @@ of the body. Holding a button 1-3 chord
changes the initial velocity of the body. Releasing button 1
restarts the simulator with the new body in motion. When new
bodies are created, the simulator maintains the Galilean (inertial)
reference frame.
reference frame where the center of mass of the galaxy is at rest.
.PP
Mouse button 2 repositions the visible region of the galaxy by dragging.
.PP
Mouse button 3 opens a menu with the following options:
.TP
.B move
Change the visible region of the simulation
by holding button 1 and dragging. Any other mouse
button restarts the simulation.
.TP
.B zoom
Prompts for a floating point value to change the scale of the
simulation. E.g. a value of 2 will halve the scale (zoom in)

View file

@ -35,8 +35,7 @@ Cursor pausecursor={
enum {
STK = 8192,
MOVE = 0,
ZOOM,
ZOOM = 0,
SPEED,
GRAV,
SAVE,
@ -57,7 +56,7 @@ double
LIM = 10,
dt²;
char *file;
int showv, showa, throttle, moving;
int showv, showa, throttle;
char *menustr[] = {
[SAVE] "save",
@ -65,7 +64,6 @@ char *menustr[] = {
[ZOOM] "zoom",
[SPEED] "speed",
[GRAV] "gravity",
[MOVE] "move",
[EXIT] "exit",
[MEND] nil
};
@ -313,31 +311,24 @@ getinput(char *info, char *sug)
}
void
move(void)
domove(void)
{
Point od;
Point oldp, off;
setcursor(mc, &crosscursor);
pause(0, 0);
oldp = mc->xy;
for(;;) {
for(;;) {
readmouse(mc);
if(mc->buttons & 1)
break;
if(mc->buttons & 4) {
moving = 0;
setcursor(mc, cursor);
return;
}
}
moving = 1;
od = subpt(orig, mc->xy);
for(;;) {
readmouse(mc);
if(!(mc->buttons & 1))
break;
orig = addpt(od, mc->xy);
drawglxy();
}
readmouse(mc);
if(mc->buttons != 2)
break;
off = subpt(mc->xy, oldp);
oldp = mc->xy;
orig = addpt(orig, off);
drawglxy();
}
setcursor(mc, cursor);
pause(1, 0);
}
void
@ -413,9 +404,6 @@ domenu(void)
break;
G *= z;
break;
case MOVE:
move();
break;
case EXIT:
threadexitsall(nil);
break;
@ -434,6 +422,9 @@ mousethread(void*)
case 1:
dobody();
break;
case 2:
domove();
break;
case 4:
domenu();
break;
@ -488,8 +479,6 @@ kbdthread(void*)
showa ^= 1;
break;
case ' ':
if(moving)
break;
paused ^= 1;
if(paused) {
cursor = &pausecursor;
@ -537,7 +526,7 @@ Again:
b->a.y = b->newa.y;
b->newa.x = b->newa.y = 0;
STATS(calcs = 0;)
quadcalc(space, b, LIM);
quadcalc(b, space, LIM);
STATS(avgcalcs += calcs;)
}
STATS(avgcalcs /= glxy.l;)

View file

@ -64,7 +64,7 @@ void readglxy(int);
void writeglxy(int);
int Bfmt(Fmt*);
void quadcalc(QB, Body*, double);
void quadcalc(Body*, QB, double);
int quadins(Body*, double);
void growquads(void);
void quadsinit(void);

View file

@ -12,7 +12,7 @@ double
av, avrand;
int new, c = 1;
void quadcalc(QB, Body*, double){}
void quadcalc(Body*, QB, double){}
Image *randcol(void){ return nil; }
void

View file

@ -84,7 +84,7 @@ quadins(Body *nb, double size)
}
void
quadcalc(QB qb, Body *b, double size)
quadcalc(Body *b, QB qb, double size)
{
double fx÷mm, fy÷mm, dx, dy, h, G÷h³;
@ -121,9 +121,9 @@ quadcalc(QB qb, Body *b, double size)
return;
}
size /= 2;
quadcalc(qb.q->c[0], b, size);
quadcalc(qb.q->c[1], b, size);
quadcalc(qb.q->c[2], b, size);
quadcalc(b, qb.q->c[0], size);
quadcalc(b, qb.q->c[1], size);
quadcalc(b, qb.q->c[2], size);
qb = qb.q->c[3];
break; /* quadcalc(q->q[3], b, size); */
}