/* network1.c /* An example of a static networked CAVE environment. The world is that /* of navigate1.c, except that the balls do not bounce (as that would /* require synchronization of the different CAVEs). This program does not /* use any networked application data; it merely uses the networked /* tracking data in drawing the remote users. */ #include #include void init_gl(void),draw_world(void); void navigate(void); void draw_user(volatile CAVE_USER_ST *user); void draw_head(volatile CAVE_USER_ST *user); void draw_wand(volatile CAVE_USER_ST *user); main(int argc,char **argv) { CAVEConfigure(&argc,argv,NULL); CAVEInit(); CAVEInitApplication(init_gl,0); CAVEDisplay(draw_world,0); while (!CAVEgetbutton(CAVE_ESCKEY)) { navigate(); sginap(1); } CAVEExit(); } #define SPEED 5.0f /* Max navigation speed in feet per second */ /* navigate - perform the navigation calculations. This checks the joystick state and uses that to move and rotate. The Y position of the joystick determines the speed of motion in the direction of the wand. The X position of the joystick determines the speed of rotation about the CAVE's Y axis. Joystick values in the range -.2 to .2 are ignored; this provides a dead zone to eliminate noise. The motion is scaled by dt, the time passed since the last call to navigate(), in order to maintain a smooth speed. */ void navigate(void) { float jx=CAVE_JOYSTICK_X,jy=CAVE_JOYSTICK_Y,dt,t; static float prevtime = 0; t = CAVEGetTime(); dt = t - prevtime; prevtime = t; if (fabs(jy)>0.2) { float wandFront[3]; CAVEGetVector(CAVE_WAND_FRONT,wandFront); CAVENavTranslate(wandFront[0]*jy*SPEED*dt, wandFront[1]*jy*SPEED*dt, wandFront[2]*jy*SPEED*dt); } if (fabs(jx)>0.2) CAVENavRot(-jx*90.0f*dt,'y'); } static GLuint greenMat, blueMat; static GLUquadricObj *sphereObj; /* init_gl - initialize GL lighting & materials */ void init_gl(void) { float greenMaterial[] = { 0, 1, 0, 1 }; float blueMaterial[] = { 0, 0, 1, 1 }; glEnable(GL_LIGHT0); greenMat = glGenLists(1); glNewList(greenMat, GL_COMPILE); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, greenMaterial); glEndList(); blueMat = glGenLists(1); glNewList(blueMat, GL_COMPILE); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blueMaterial); glEndList(); sphereObj = gluNewQuadric(); } /* draw_world - draw the world - the two balls, and the networked users */ void draw_world(void) { int i; glClearColor(0., 0., 0., 0.); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); /* Apply the navigation transformation */ glPushMatrix(); CAVENavTransform(); glColor3f(.03, .5, .1); glBegin(GL_QUADS); glVertex3f(-100.0, 0.0, -100.0); glVertex3f(100.0, 0.0, -100.0); glVertex3f(100.0, 0.0, 100.0); glVertex3f(-100.0, 0.0, 100.0); glEnd(); glEnable(GL_LIGHTING); glCallList(greenMat); glPushMatrix(); glTranslatef(2.0, 3.0, -5.0); gluSphere(sphereObj, 1.0, 8, 8); glPopMatrix(); glCallList(blueMat); glPushMatrix(); glTranslatef(-2.0, 1.0, -5.0); gluSphere(sphereObj, 1.0, 8, 8); glPopMatrix(); glDisable(GL_LIGHTING); /* Draw all the remote users (but not the local user; hence count from 1) */ glPopMatrix(); for (i=1; i<*CAVENumUsers; i++) draw_user(CAVEUser[i]); } /* draw_user - draw the given user's head and wand */ /* note that this is performed in tracker, not navigated, coordinates */ void draw_user(volatile CAVE_USER_ST *user) { glPushMatrix(); CAVESensorTransform(CAVENETSENSOR(user,0)); draw_head(user); glPopMatrix(); glPushMatrix(); CAVESensorTransform(CAVENETSENSOR(user,1)); draw_wand(user); glPopMatrix(); } /* draw_head - draw the given user's head, using a few spheres for a head, eyes, and nose */ void draw_head(volatile CAVE_USER_ST *user) { glColor3f(.5, .5, .5); gluSphere(sphereObj, 0.5, 8, 8); glColor3f(.75, .0, .0); glPushMatrix(); glTranslatef(0.0, 0.1, -.5); gluSphere(sphereObj, 0.1, 5, 5); glPopMatrix(); glColor3f(.0, .0, .75); glPushMatrix(); glTranslatef(-0.2, 0.3, -.3); gluSphere(sphereObj, 0.1, 5, 5); glPopMatrix(); glPushMatrix(); glTranslatef(0.2, 0.3, -.3); gluSphere(sphereObj, 0.1, 5, 5); glPopMatrix(); } /* draw_wand - draw the given user's wand as a small sphere */ void draw_wand(volatile CAVE_USER_ST *user) { glColor3f(1.0, .0, .0); gluSphere(sphereObj, 0.1, 5, 5); }