Пример #1
0
void render(void)
{
    int step, oldc, newc;
    bodyptr bp;
    float cval;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective((GLdouble) fview, (GLdouble) ((double) wscreen) / hscreen,
		   (GLdouble) 0.01 * dview, (GLdouble) 100.0 * dview);
    glGetFloatv(GL_PROJECTION_MATRIX, &projmat[0][0]);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glTranslatef(xoff, yoff, -dview);
    glRotatef(-thetaz, 0.0, 0.0, 1.0);		/* same map as snaprotate   */
    glRotatef(-thetay, 0.0, 1.0, 0.0);
    glRotatef(-thetax, 1.0, 0.0, 0.0);
    glGetFloatv(GL_MODELVIEW_MATRIX, &viewmat[0][0]);
    glBegin(vectoroff == -1 ? GL_POINTS : GL_LINES);
    step = (actval == -1 ? 1 : rceil((float) nbody / (float) maxfast));
    oldc = -1;
    for (bp = btab; bp < NthBody(btab, nbody); bp = NthBody(bp, step)) {
        if (scalaroff == -1 && ! dopcolor)
            newc = Key(bp);
        else {
	    if (! dopcolor)
	        cval = (SelectReal(bp, scalaroff) - cmidpt) / crange;
	    else
	        cval = (dotvp(Vel(bp), znorm) - cmidpt) / crange;
	    newc = (cval >  1.0 ? 0x0000ff : cval >  0.6 ? 0x006fdf :
		    cval >  0.2 ? 0x00cf7f : cval > -0.2 ? 0x00ff00 :
		    cval > -0.6 ? 0x7fcf00 : cval > -1.0 ? 0xbf8f00 :
		    0xff4f00);
	}
        if (oldc != newc)
	    glColor3f(RVAL(newc), GVAL(newc), BVAL(newc));
	oldc = newc;
        glVertex3f(Pos(bp)[0], Pos(bp)[1], Pos(bp)[2]);
	if (vectoroff != -1)
	    glVertex3f(Pos(bp)[0] + vscale * SelectVect(bp, vectoroff)[0],
		       Pos(bp)[1] + vscale * SelectVect(bp, vectoroff)[1],
		       Pos(bp)[2] + vscale * SelectVect(bp, vectoroff)[2]);
    }
    glEnd();
    if (actval != -1) {
        glColor3f(RVAL(bcolor), GVAL(bcolor), BVAL(bcolor));
	glutWireCube(refscale);
    }
    glPopMatrix();
}
Пример #2
0
real simpson(real (*integrand)(real, real, real, real),
	     real param1, real param2, real param3,
	     real xlow, real xhigh, real step0)
{
  int nstep, i;
  real step1, x;
  double v1, v2, v4;

  nstep = 1 + 2 * (int) rceil(0.5 * (xhigh - xlow) / step0);
  step1 = (xhigh - xlow) / (nstep - 1);
  v1 = v2 = v4 = 0.0;
  for (i = 1; i <= nstep; i++) {
    x = xlow + (i - 1) * step1;
    if (i == 1 || i == nstep)
      v1 = v1 + (*integrand)(x, param1, param2, param3);
    else if (i % 2 == 0)
      v4 = v4 + (*integrand)(x, param1, param2, param3);
    else
      v2 = v2 + (*integrand)(x, param1, param2, param3);
  }
  return (step1 * (v1 + 4.0*v4 + 2.0*v2) / 3.0);
}
Пример #3
0
void sphrprof(void)
{
    bodyptr *rsort;
    int skip, j, i;
    real r;

    if (nspheroid > 1) {
	rsort = (bodyptr *) allocate(nspheroid * sizeof(bodyptr));
	for (i = 0; i < nspheroid; i++)
	    rsort[i] = NthBody(spheroid, i);
	qsort(rsort, nspheroid, sizeof(bodyptr), rankrad);
        skip = (int) rceil(MAX(((real) nspheroid) / (NTAB - 1), 1.0));
	msph[0] = rsph[0] = 0.0;
	for (j = 1; j < NTAB; j++) {
	    i = skip * j - 1;
	    rsph[j] = (i < nspheroid ? absv(Pos(rsort[i])) : 1.0 + rsph[j-1]);
	    msph[j] = 0.0;
	}
	for (i = 0; i < nspheroid; i++) {
	    j = i / skip + 1;
	    if (j > NTAB-1)
		error("%s.sphrprof: table overflow: i = %d  skip = %d\n",
			  getargv0(), i, skip);
	    msph[j] = msph[j] + Mass(rsort[i]);
	}
	for (j = 1; j < NTAB; j++)
	    msph[j] += msph[j - 1];
    } else {
        for (j = 0; j < NTAB; j++) {
	    rsph[j] = 1.0 * j;
	    msph[j] = Mass(NthBody(spheroid, 0));
	}
    }
    eprintf("[%s.sphrprof: rsph = %f %f %f ... %f %f]\n", getargv0(),
	    rsph[0], rsph[1], rsph[2], rsph[NTAB-2], rsph[NTAB-1]);
    spline(mcof, rsph, msph, NTAB);
}