|
CAVELib Sample Program 2
|
Previous Top Next |
| float y;
|
|
|
| CAVEConfigure(&argc,argv,NULL);
|
|
|
| /* Initialize sphere memory */
|
| initSphereMem();
|
| CAVEInitApplication(initGL,0);
|
|
|
| /* Give the library a pointer to the drawing function */
|
| CAVEDisplay((CAVECALLBACK)drawSpheres,0);
|
|
|
| /* Give the library a pointer to an update function */
|
| CAVEFrameFunction((CAVECALLBACK)frameUpdate,0);
|
|
|
| CAVEInit();
|
|
|
| while (!CAVEgetbutton(CAVE_ESCKEY) && !CAVESync->Quit) {
|
|
|
| /* Nap in the while loop if not doing any processing,
|
| cuts down on needless looping
|
| */
|
| CAVEUSleep(10);
|
|
|
| }
|
| CAVEExit();
|
|
|
| sphere = (SPHEREDATA*) malloc(2*sizeof(SPHEREDATA));
|
| #ifndef WIN32
|
| bzero(sphere,2*sizeof(SPHEREDATA));
|
| #else
|
| memset(sphere,0,2*sizeof(SPHEREDATA));
|
| #endif
|
|
|
| if(CAVEMasterDisplay()) {
|
|
|
| compute();
|
| navigate();
|
|
|
| }
|
| CAVEDisplayBarrier();
|
|
|
| float t = *CAVETime;
|
| sphere[0].y = (float) fabs(sin(t)) * 6 + 1;
|
| sphere[1].y = (float) fabs(sin(t)) * 4 + 1;
|
|
|
| float jx, jy, dt, t;
|
| static float prevtime = 0;
|
|
|
| if(CAVEMasterDisplay()) {
|
|
|
| jx=CAVE_JOYSTICK_X;
|
| jy=CAVE_JOYSTICK_Y;
|
| t = (float) 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');
|
|
|
| }
|
|
|
| }
|
|
|
| float redMaterial[] = { 1, 0, 0, 1 };
|
| float blueMaterial[] = { 0, 0, 1, 1 };
|
|
|
| /* Enable light 0*/
|
| glEnable(GL_LIGHT0);
|
|
|
| /* Create a thread unique display list for the red and
|
| then the blue material
|
| */
|
| redMat[CAVEUniqueIndex()] = glGenLists(1);
|
| glNewList(redMat[CAVEUniqueIndex()], GL_COMPILE);
|
| glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, redMaterial);
|
| glEndList();
|
| blueMat[CAVEUniqueIndex()] = glGenLists(1);
|
| glNewList(blueMat[CAVEUniqueIndex()], GL_COMPILE);
|
| glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blueMaterial);
|
| glEndList();
|
|
|
| /* Make a new quadric to draw a sphere */
|
| sphereObj[CAVEUniqueIndex()] = gluNewQuadric();
|
|
|
|
|
| /* Clear the screen and zbuffer */
|
| glClearColor(0., 0., 0., 0.);
|
| glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
|
|
|
| glEnable(GL_LIGHTING);
|
|
|
| /* Apply the navigation transformation */
|
| CAVENavTransform();
|
|
|
| /* Activate the Red Material and draw a red sphere */
|
| glCallList(redMat[CAVEUniqueIndex()]);
|
| glPushMatrix();
|
| glTranslatef(2.0, sphere[0].y, -5.0);
|
| gluSphere(sphereObj[CAVEUniqueIndex()], 1.0, 8, 8);
|
| glPopMatrix();
|
|
|
| /* Activate the Blue Material and draw a blue sphere */
|
| glCallList(blueMat[CAVEUniqueIndex()]);
|
| glPushMatrix();
|
| glTranslatef(-2.0, sphere[1].y, -5.0);
|
| gluSphere(sphereObj[CAVEUniqueIndex()], 1.0, 8, 8);
|
| glPopMatrix();
|
| glDisable(GL_LIGHTING);
|
| drawGround();
|
|
|
| int x;
|
| float pt[3];
|
|
|
| glColor3ub(255, 255, 0);
|
| for (x = -N; x <= N; x+=INCGRID) {
|
|
|
| glBegin(GL_LINE_STRIP);
|
| pt[0] = x; pt[1] = 0.0; pt[2] = -N;
|
| glVertex3fv(pt);
|
| pt[0] = x; pt[1] = 0.0; pt[2] = N;
|
| glVertex3fv(pt);
|
| glEnd();
|
|
|
| glBegin(GL_LINE_STRIP);
|
| pt[0] = -N; pt[1] = 0.0; pt[2] = x;
|
| glVertex3fv(pt);
|
| pt[0] = N; pt[1] = 0.0; pt[2] = x;
|
| glVertex3fv(pt);
|
| glEnd();
|
|
|
| }
|