// File: bounce.cc // Summary: Draw single sphere. Bounce sphere up and down. Use CAVE // shared memory to communicate between compute and render processes // about new sphere position. #include #include #include #include // How high to bounce. #define MAX_BOUNCE 8.0 // Offset so that sphere doesn't bounce through floor. #define OFFSET 1.0 // How fast to bounce #define DELTA 0.2 float * height; void renderProcDraw (); void appProcCompute (); void main (int argc, char ** argv) { // Configure based on system files and user-supplied args. CAVEConfigure (&argc, argv, NULL); // Allocate and initialize shared memory variable. height = (float *) CAVEMalloc (sizeof (float)); *height = 0.0; // Fork rendering processes for each wall. CAVEInit (); // Specify application's drawing routine. CAVEDisplay (renderProcDraw, 0); // Let balls rise and fall over time. while (!CAVEgetbutton (CAVE_ESCKEY)) { appProcCompute (); sginap (10); } CAVEFree (height); CAVEExit (); } void appProcCompute () { static int nCalls = 0; float t; //static float t = 0; //t += DELTA; t = CAVEGetTime (); CAVEDisplaySync(); printf ("(%d) compute: %d\n", getpid(), nCalls++); *height = fabs (sin (t)) * MAX_BOUNCE + OFFSET; } void renderProcDraw () { static int nCalls = 0; // Clear the z-buffer and set the screen to blue. glClearColor (0.2, 0.2, 0.8, 1.0); glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glPushMatrix (); glTranslatef (0, *height, -4); glColor3f (1.0, 1.0, 0.0); GLUquadric * quad = gluNewQuadric (); gluSphere (quad, 1.0, 20, 20); // Reset the transformation matrix. glPopMatrix (); printf ("(%d) render: %d\n", getpid(), nCalls++); }