- Display *display = MI_DISPLAY(mi);
- Window window = MI_WINDOW(mi);
- GC gc = MI_GC(mi);
- unistruct *gp = &universes[MI_SCREEN(mi)];
- double d; /* tmp */
- int i, j, k; /* more tmp */
-
- for (i = 0; i < gp->ngalaxies; ++i) {
- Galaxy *gt = &gp->galaxies[i];
-
- for (j = 0; j < gp->galaxies[i].nstars; ++j) {
- Star *st = >->stars[j];
- double v0 = st->vel[0];
- double v1 = st->vel[1];
- double v2 = st->vel[2];
-
- for (k = 0; k < gp->ngalaxies; ++k) {
- Galaxy *gtk = &gp->galaxies[k];
- double d0 = gtk->pos[0] - st->pos[0];
- double d1 = gtk->pos[1] - st->pos[1];
- double d2 = gtk->pos[2] - st->pos[2];
-
- d = d0 * d0 + d1 * d1 + d2 * d2;
- if (d > EPSILON)
- d = gt->mass / (d * sqrt(d)) * DELTAT * DELTAT * QCONS;
- else
- d = gt->mass / (EPSILON * sqrt_EPSILON) * DELTAT * DELTAT * QCONS;
- v0 += d0 * d;
- v1 += d1 * d;
- v2 += d2 * d;
- }
-
- st->vel[0] = v0;
- st->vel[1] = v1;
- st->vel[2] = v2;
-
-#ifndef NO_VELOCITY_COLORING
- d = (v0 * v0 + v1 * v1 + v2 * v2) / (3.0 * DELTAT * DELTAT);
- if (d > (double) COLORSTEP)
- st->color = COLORSTEP * gt->galcol + COLORSTEP - 1;
- else
- st->color = COLORSTEP * gt->galcol + ((int) d) % COLORSTEP;
-#endif
- st->pos[0] += v0;
- st->pos[1] += v1;
- st->pos[2] += v2;
-
- if (st->px >= gp->clip.left &&
- st->px <= gp->clip.right - st->size &&
- st->py >= gp->clip.top &&
- st->py <= gp->clip.bottom - st->size) {
- XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
- drawStar(st->px, st->py, st->size);
- }
- st->px = (int) (st->pos[0] * gp->scale) + gp->midx;
- st->py = (int) (st->pos[1] * gp->scale) + gp->midy;
-
-
-#ifdef WRAP
- if (st->px < gp->clip.left) {
- (void) printf("wrap l -> r\n");
- st->px = gp->clip.right;
- }
- if (st->px > gp->clip.right) {
- (void) printf("wrap r -> l\n");
- st->px = gp->clip.left;
- }
- if (st->py > gp->clip.bottom) {
- (void) printf("wrap b -> t\n");
- st->py = gp->clip.top;
- }
- if (st->py < gp->clip.top) {
- (void) printf("wrap t -> b\n");
- st->py = gp->clip.bottom;
- }
-#endif /*WRAP */
-
-
- if (st->px >= gp->clip.left &&
- st->px <= gp->clip.right - st->size &&
- st->py >= gp->clip.top &&
- st->py <= gp->clip.bottom - st->size) {
- if (MI_NPIXELS(mi) > 2)
-#ifdef NO_VELOCITY_COLORING
- XSetForeground(display, gc, MI_PIXEL(mi, COLORSTEP * gt->galcol));
-#else
- XSetForeground(display, gc, MI_PIXEL(mi, st->color));
-#endif
- else
- XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
- if (tracks)
- drawStar(st->px + 1, st->py, st->size);
- else
- drawStar(st->px, st->py, st->size);
- }
- }
-
- for (k = i + 1; k < gp->ngalaxies; ++k) {
- Galaxy *gtk = &gp->galaxies[k];
- double d0 = gtk->pos[0] - gt->pos[0];
- double d1 = gtk->pos[1] - gt->pos[1];
- double d2 = gtk->pos[2] - gt->pos[2];
-
- d = d0 * d0 + d1 * d1 + d2 * d2;
- if (d > EPSILON)
- d = gt->mass * gt->mass / (d * sqrt(d)) * DELTAT * QCONS;
- else
- d = gt->mass * gt->mass / (EPSILON * sqrt_EPSILON) * DELTAT * QCONS;
- d0 *= d;
- d1 *= d;
- d2 *= d;
- gt->vel[0] += d0 / gt->mass;
- gt->vel[1] += d1 / gt->mass;
- gt->vel[2] += d2 / gt->mass;
- gtk->vel[0] -= d0 / gtk->mass;
- gtk->vel[1] -= d1 / gtk->mass;
- gtk->vel[2] -= d2 / gtk->mass;
- }
- gt->pos[0] += gt->vel[0] * DELTAT;
- gt->pos[1] += gt->vel[1] * DELTAT;
- gt->pos[2] += gt->vel[2] * DELTAT;
- }
-
- gp->step++;
- if (gp->step > gp->f_hititerations * 4)
- startover(mi);
+ Display *display = MI_DISPLAY(mi);
+ Window window = MI_WINDOW(mi);
+ GC gc = MI_GC(mi);
+ unistruct *gp = &universes[MI_SCREEN(mi)];
+ double d, eps, cox, six, cor, sir; /* tmp */
+ int i, j, k; /* more tmp */
+ XPoint *dummy = NULL;
+
+ if(spin){
+ gp->rot_y += 0.01;
+ gp->rot_x += 0.004;
+ }
+
+ cox = COSF(gp->rot_y);
+ six = SINF(gp->rot_y);
+ cor = COSF(gp->rot_x);
+ sir = SINF(gp->rot_x);
+
+ eps = 1/(EPSILON * sqrt_EPSILON * DELTAT * DELTAT * QCONS);
+
+ for (i = 0; i < gp->ngalaxies; ++i) {
+ Galaxy *gt = &gp->galaxies[i];
+
+ for (j = 0; j < gp->galaxies[i].nstars; ++j) {
+ Star *st = >->stars[j];
+ XPoint *newp = >->newpoints[j];
+ double v0 = st->vel[0];
+ double v1 = st->vel[1];
+ double v2 = st->vel[2];
+
+ for (k = 0; k < gp->ngalaxies; ++k) {
+ Galaxy *gtk = &gp->galaxies[k];
+ double d0 = gtk->pos[0] - st->pos[0];
+ double d1 = gtk->pos[1] - st->pos[1];
+ double d2 = gtk->pos[2] - st->pos[2];
+
+ d = d0 * d0 + d1 * d1 + d2 * d2;
+ if (d > EPSILON)
+ d = gt->mass / (d * sqrt(d)) * DELTAT * DELTAT * QCONS;
+ else
+ d = gt->mass * eps;
+ v0 += d0 * d;
+ v1 += d1 * d;
+ v2 += d2 * d;
+ }
+
+ st->vel[0] = v0;
+ st->vel[1] = v1;
+ st->vel[2] = v2;
+
+ st->pos[0] += v0;
+ st->pos[1] += v1;
+ st->pos[2] += v2;
+
+ newp->x = (short) (((cox * st->pos[0]) - (six * st->pos[2])) *
+gp->scale) + gp->midx;
+ newp->y = (short) (((cor * st->pos[1]) - (sir * ((six * st->pos[0]) +
+(cox * st->pos[2])))) * gp->scale) + gp->midy;
+
+ }
+
+ for (k = i + 1; k < gp->ngalaxies; ++k) {
+ Galaxy *gtk = &gp->galaxies[k];
+ double d0 = gtk->pos[0] - gt->pos[0];
+ double d1 = gtk->pos[1] - gt->pos[1];
+ double d2 = gtk->pos[2] - gt->pos[2];
+
+ d = d0 * d0 + d1 * d1 + d2 * d2;
+ if (d > EPSILON)
+ d = gt->mass * gt->mass / (d * sqrt(d)) * DELTAT * QCONS;
+ else
+ d = gt->mass * gt->mass / (EPSILON * sqrt_EPSILON) * DELTAT * QCONS;
+
+ d0 *= d;
+ d1 *= d;
+ d2 *= d;
+ gt->vel[0] += d0 / gt->mass;
+ gt->vel[1] += d1 / gt->mass;
+ gt->vel[2] += d2 / gt->mass;
+ gtk->vel[0] -= d0 / gtk->mass;
+ gtk->vel[1] -= d1 / gtk->mass;
+ gtk->vel[2] -= d2 / gtk->mass;
+ }
+
+ gt->pos[0] += gt->vel[0] * DELTAT;
+ gt->pos[1] += gt->vel[1] * DELTAT;
+ gt->pos[2] += gt->vel[2] * DELTAT;
+
+ XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
+ XDrawPoints(display, window, gc, gt->oldpoints, gt->nstars,
+CoordModeOrigin);
+ XSetForeground(display, gc, MI_PIXEL(mi, COLORSTEP * gt->galcol));
+ XDrawPoints(display, window, gc, gt->newpoints, gt->nstars,
+CoordModeOrigin);
+
+ dummy = gt->oldpoints;
+ gt->oldpoints = gt->newpoints;
+ gt->newpoints = dummy;
+ }
+
+ gp->step++;
+ if (gp->step > gp->f_hititerations * 4)
+ startover(mi);