// File: navigate.cc // Summary: Use the joystick to navigate through an environment, where // the world extends beyond the CAVE coordinate system. // Joystick Y value controls forward and backward speed. // Wand direction controls direction of travel. #include #include #include #include // Make a 3 x 3 'world' of squares, each 100 units on a side. #define BLOCK_COUNT 3 #define BLOCK_SIZE 100 #define SPEED 4 // Colors for the blocks. float colors[9][3] = { 1.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 1.0, // 1.0, 0.5, 0.0, 0.5, 0.5, 0.5, 0.0, 0.5, 0.5, // 1.0, 1.0, 0.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.0 }; void appProcCompute (); void renderProcDraw (); void main (int argc, char ** argv) { CAVEConfigure (&argc, argv, NULL); CAVEInit (); CAVEDisplay (renderProcDraw, 0); while (!CAVEgetbutton (CAVE_ESCKEY)) appProcCompute (); CAVEExit (); } void appProcCompute () { static float oldTime = 0; float newTime = CAVEGetTime (); float elapsedTime = newTime - oldTime; float joystickY = CAVE_JOYSTICK_Y; float wandDir[3], deltaPos[3]; // Find how far to move... if (fabs (joystickY) > 0.2) { float distance = joystickY * SPEED * elapsedTime; // ...and in what direction. // Get the wand's direction vector. CAVEGetVector (CAVE_WAND_FRONT, wandDir); for (int i=0; i<3; i++) deltaPos[i] = wandDir[i] * distance; // Add in this translation to the CAVE navigation matrix. CAVENavTranslate (deltaPos[0], 0.0, deltaPos[2]); } oldTime = newTime; } void renderProcDraw () { // Clear the z-buffer and set the screen to blue. glClearDepth (1.0); glClearColor (0.2, 0.2, 0.8, 1.0); glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // Apply the CAVE navigation transform. CAVENavTransform (); // Draw a multi-colored ground plane. // 'glRectf' draws a rectangle in xy-plane. // Rotate rectangle 90 degrees around 'x' to lay flat. // Shift the collection of squares in the xy-plane to center // the "world" at the CAVE's center. glTranslatef (-0.5*BLOCK_COUNT*BLOCK_SIZE, 0.0, -0.5*BLOCK_COUNT*BLOCK_SIZE); for (int i=0; i