/* dbounce.c /* A dynamic environment for the distributed CAVE. This is a /* slightly modified version of bounce.c which uses the CAVEDistrib /* functions to share data between the two nodes of a 4-wall CAVE. /* The only changes are in main() and compute(). */ #include #include #include struct _balldata { float y; }; void init_gl(void),draw_balls(struct _balldata *); struct _balldata *init_shmem(void); void compute(struct _balldata *); main(int argc,char **argv) { struct _balldata *ball; CAVEConfigure(&argc,argv,NULL); ball = init_shmem(); CAVEInit(); /* Initialize the distributed CAVE communication */ CAVEDistribConnect(); CAVEInitApplication(init_gl,0); CAVEDisplay(draw_balls,1,ball); while (!getbutton(ESCKEY)) { compute(ball); sginap(1); } CAVEDistribClose(); CAVEExit(); } struct _balldata *init_shmem(void) { struct _balldata *ball; ball = CAVEMalloc(2*sizeof(struct _balldata)); bzero(ball,2*sizeof(struct _balldata)); return ball; } /* compute - compute new positions for the balls. Only the master node will perform calculations. It then does a send of the results, which the slave node receives. */ void compute(struct _balldata *ball) { if (CAVEDistribMaster()) { float t = CAVEGetTime(); ball[0].y = fabs(sin(t)) * 6 + 1; ball[1].y = fabs(sin(t*1.2)) * 4 + 1; CAVEDistribSend(ball,2*sizeof(struct _balldata)); } else { CAVEDistribReceive(ball,2*sizeof(struct _balldata)); } /* Synchronize so that the master node does not get ahead */ CAVEDistribBarrier(); } void init_gl(void) { float redMaterial[] = { DIFFUSE, 1, 0, 0, LMNULL }; float blueMaterial[] = { DIFFUSE, 0, 0, 1, LMNULL }; lmdef(DEFLMODEL,1,0,NULL); lmbind(LMODEL,1); lmdef(DEFLIGHT,1,0,NULL); lmbind(LIGHT0,1); lmdef(DEFMATERIAL,1,0,redMaterial); lmdef(DEFMATERIAL,2,0,blueMaterial); } void draw_balls(struct _balldata *ball) { float sphereParam0[] = { 2, 4, -5, 1}; float sphereParam1[] = { -2, 4, -5, 1}; czclear(0,getgdesc(GD_ZMAX)); lmbind(MATERIAL,0); cpack(0xff088018); pushmatrix(); rot(-90.0,'x'); rectf(-100.0,-100.0,100.0,100.0); popmatrix(); lmbind(MATERIAL,1); sphereParam0[1] = ball[0].y; sphdraw(sphereParam0); lmbind(MATERIAL,2); sphereParam1[1] = ball[1].y; sphdraw(sphereParam1); }