#include #include #include #include #include "sphplot.h" int Ncall = 0; int Winid; /* If you don't like purplish spheres, try setting Sphere_color to RED, WHITE, BLUE, GREEN, YELLOW, or CYAN */ int Sphere_color = MAGENTA; void sphplot_(double *pos,int *pncharge,double *pradius) { sphplot(pos,*pncharge,*pradius); } /* Call this routine with ncharge > 0 for normal operation, ncharge < 0 for tumble mode until escape key is depressed in graphics window ... */ void sphplot(double *pos,int ncharge,double radius) { int i; int rotx, roty, rotz; int drotx = 2, droty = 3, drotz = 4; long dev; short val; if( Ncall == 0 ) { /* Open window, set graphics attributes and clear to black ... */ keepaspect(1,1); foreground(); Winid = winopen("sphplot"); cmode(); doublebuffer(); gconfig(); perspective(250,1.0,0.0001,100000.0); color(BLACK); clear(); swapbuffers(); translate(0.0,0.0,-7.5); /* Set sphere attributes ... */ sphmode(SPH_TESS,SPH_OCT); sphmode(SPH_DEPTH,5); sphmode(SPH_PRIM,SPH_POLY); /* Queue escape-key ... */ qdevice(ESCKEY); } if( ncharge > 0 ) { /* Regular draw ... */ draw_spheres(pos,ncharge,radius,0,0,0); } else { /* Tumble and wait for escape key ... */ rotx = 0; roty = 0; rotz = 0; while( 1 ) { if( qtest() ) { dev = qread(&val); if( (dev == ESCKEY) && val ) return; } draw_spheres(pos,-ncharge,radius,rotx,roty,rotz); rotx = (rotx + drotx) % 3600; roty = (roty + droty) % 3600; rotz = (rotz + drotz) % 3600; } } Ncall++; } void draw_spheres(double *pos,int ncharge,double radius, int rotx,int roty,int rotz) { float sphparams[4]; int i; sphparams[3] = radius; pushmatrix(); color(BLACK); clear(); rotate(rotx,'x'); rotate(roty,'y'); rotate(rotz,'z'); color(Sphere_color); for( i = 0; i < ncharge; i++ ) { sphparams[0] = pos[3 * i]; sphparams[1] = pos[3 * i + 1]; sphparams[2] = pos[3 * i + 2]; sphdraw(sphparams); } swapbuffers(); popmatrix(); return; }