Beispiel #1
0
void annotate(void)
{
    char buf[64];
    int ypos, xpos;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho((GLdouble) 0, (GLdouble) wscreen,
	    (GLdouble) hscreen, (GLdouble) 0,
	    (GLdouble) -1.0, (GLdouble) 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glPushMatrix();
    glColor3f(RVAL(0xffffff), GVAL(0xffffff), BVAL(0xffffff));
    if (actval == -1) {
	if (! strnull(getparam("ident")))
            showtext(getparam("ident"), 10, 20);
        sprintf(buf, "%.2f", tnow);
	showtext(buf, wscreen - (8 * strlen(buf) + 10), 20);
    } else {
        ypos = hscreen - 10;
	if (vectoroff != -1) {
	  sprintf(buf, "vector scale: %.2f", vscale);
	  showtext(buf, 10, ypos);
	  ypos -= 20;
	}
	if (scalaroff != -1 || dopcolor) {
	    xpos = 10;
	    sprintf(buf, "mapping: ");
	    showtext(buf, xpos, ypos);
	    xpos += 8 * strlen(buf);
	    sprintf(buf, "%.2f", cmidpt + crange);
	    glColor3f(RVAL(0x0000ff), GVAL(0x0000ff), BVAL(0x0000ff));
	    showtext(buf, xpos, ypos);
	    xpos += 8 * strlen(buf);
	    glColor3f(RVAL(0xffffff), GVAL(0xffffff), BVAL(0xffffff));
	    showtext(" to ", xpos, ypos);
	    xpos += 32;
	    sprintf(buf, "%.2f", cmidpt - crange);
	    glColor3f(RVAL(0xff4f00), GVAL(0xff4f00), BVAL(0xff4f00));
	    showtext(buf, xpos, ypos);
	    xpos += 8 * strlen(buf);
	    ypos -= 20;
	    glColor3f(RVAL(0xffffff), GVAL(0xffffff), BVAL(0xffffff));
	}
	sprintf(buf, "angles: %.2f, %.2f, %.2f", thetax, thetay, thetaz);
	showtext(buf, 10, ypos);
	ypos -= 20;
        sprintf(buf, "view: %.2f, %.2f, %.2f; %.2f",
		xoff, yoff, dview, fview);
	showtext(buf, 10, ypos);
	ypos -= 20;
    }	
    glPopMatrix();
}
Beispiel #2
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();
}
Beispiel #3
0
void canblend(canvas *dst, canvas *src, float fr, float fg, float fb, float fa)
{
    if(!cansizecheck(dst, src, "canmult: canvases must be the same size\n"))
        return;
    unsigned int *dptr = dst->data;
    unsigned int *sptr = src->data;
    int npix = dst->sizex*dst->sizey;
    while(npix--) {
        float fas = fa*AVAL(*sptr)/255.0;
        int rd = round(fr*RVAL(*sptr) + (1.0-fas)*RVAL(*dptr));
        int gd = round(fg*GVAL(*sptr) + (1.0-fas)*GVAL(*dptr));
        int bd = round(fb*BVAL(*sptr) + (1.0-fas)*BVAL(*dptr));
        int ad = round(fa*AVAL(*sptr) + (1.0-fas)*AVAL(*dptr));
        *dptr++ = CPACK(rd, gd, bd, ad);
        sptr++;
    }
}
Beispiel #4
0
void canmult(canvas *a, canvas *b)
{
    if(!cansizecheck(a, b, "canmult: canvases must be the same size\n"))
        return;
    int npix = a->sizex*a->sizey;
    unsigned int *aptr = a->data;
    unsigned int *bptr = b->data;
    while(npix--) {
        int ir = round(RVAL(*aptr)*RVAL(*bptr)/255.0);
        int ig = round(GVAL(*aptr)*GVAL(*bptr)/255.0);
        int ib = round(BVAL(*aptr)*BVAL(*bptr)/255.0);
        int ia = round(AVAL(*aptr)*AVAL(*bptr)/255.0);
        *aptr = CPACK(ir,ig,ib,ia);
        aptr++;
        bptr++;
    }
}
Beispiel #5
0
void canscalergba(canvas *c, float r, float g, float b, float a)
{
    int npix = c->sizex*c->sizey;
    unsigned int *lptr = c->data;
    while(npix--) {
	int ir = round(r*RVAL(*lptr));
	int ig = round(g*GVAL(*lptr));
	int ib = round(b*BVAL(*lptr));
	int ia = round(a*AVAL(*lptr));
	*lptr++ = CPACK(ir,ig,ib,ia);
    }
}
Beispiel #6
0
void cansaturate(canvas *c, float sat)
{
    int npix = c->sizex*c->sizey;
    unsigned int *lptr = c->data;
    while(npix--) {
	int r = RVAL(*lptr);
	int g = GVAL(*lptr);
	int b = BVAL(*lptr);
	int lum = ILUM(r,g,b);
	*lptr++ = CPACK(pixlerp(lum,r,sat),pixlerp(lum,g,sat),pixlerp(lum,b,sat),255);
    }
}
Beispiel #7
0
int cantofile(canvas *c, const char *outfilename)
{
    FILE *fptr = fopen(outfilename, "wb");
    if(!fptr) {
	fprintf(stderr, "    Error: cantofile: can't open output file\n");
	fprintf(stderr, "    [%s]\n",outfilename);
	return 0;
    }
    int sizex = c->sizex;
    int sizey = c->sizey;
    
    // from http://paulbourke.net/dataformats/tga/

    putc(0,fptr);
    putc(0,fptr);
    putc(2,fptr);                         /* uncompressed RGB */
    putc(0,fptr); putc(0,fptr);
    putc(0,fptr); putc(0,fptr);
    putc(0,fptr);
    putc(0,fptr); putc(0,fptr);           /* X origin */
    putc(0,fptr); putc(0,fptr);           /* y origin */
    putc((sizex & 0x00FF),fptr);
    putc((sizex & 0xFF00) / 256,fptr);
    putc((sizey & 0x00FF),fptr);
    putc((sizey & 0xFF00) / 256,fptr);
    putc(32,fptr);                        /* 32 bit bitmap */
    putc(0,fptr);

    for(int y=0; y<sizey; y++) {
        unsigned int *lptr = c->data+((sizey-1-y)*sizex);
        for(int x=0; x<sizex; x++) {
            putc(BVAL(*lptr),fptr);
            putc(GVAL(*lptr),fptr);
            putc(RVAL(*lptr),fptr);
            putc(AVAL(*lptr),fptr);
	    lptr++;
        }
    }
    fclose(fptr);
    return 1;
}