/* * Simple Egg Version 2.1 * David Barberi Spring 1993, 3/25/92 2/24/92 * dbarberi@sunsite.unc.edu * * Prototype virtual walk-through of a Building * */ /* Hotkeys in input() function */ char Version[]="Version 2.1 "; #include #include #include #include "glove.h" #include "colors.h" #define BOX(x1,x2,y1,y2,z1,z2) if(polygon)draw_poly_rect(x1,x2,y1,y2,z1,z2);if(wireframe)draw_rectangle(x1,x2,y1,y2,z1,z2); #define RECT(x1,x2,y1,y2) if(polygon) rectf(x1,x2,y1,y2); if(wireframe) rect(x1,x2,y1,y2); #define DEBUG 1 #define X 0 #define Y 1 #define Z 2 #define CLICK 10.0 #define WORLD_SIZE_X 400.0 #define WORLD_SIZE_Y 400.0 #define WORLD_SIZE_Z 400.0 #define GROUND_LEVEL -10.0 #define FORWARD 1 #define BACKWARDS 2 #define SIZE 20 char char_ispeed[5], char_clicks[10], char_sspeed[5]; char char_x[10], char_y[10], char_z[10]; char char_gesture[12], char_key[12]; char char_thumb[5], char_one[5], char_two[5], char_three[5], char_twist[5]; char char_key1[5], char_key2[5], char_key3[5], char_key4[5]; float view_distance, field_of_view, near_clipping_plane, far_clipping_plane, aspect_ratio; float azim, inc, rotation; float ispeed = 2.0, sspeed = 0.1; int turn_right=0, go_forward=0, turn_left=0, walking = FALSE; int fast_display = TRUE; int wireframe, polygon; typedef struct { /* structure for multiple windows, */ int gid; } wrecord; wrecord wins[3]; /* leave 0th spot empty */ int EggWindow, DataWindow; /* names of windows */ int click; /***** Static Coordinates ****/ float ground0[3] = { -WORLD_SIZE_X, GROUND_LEVEL, -WORLD_SIZE_Z}; float ground1[3] = { -WORLD_SIZE_X, GROUND_LEVEL, WORLD_SIZE_Z}; float ground2[3] = { WORLD_SIZE_X, GROUND_LEVEL, WORLD_SIZE_Z}; float ground3[3] = { WORLD_SIZE_X, GROUND_LEVEL, -WORLD_SIZE_Z}; float road0[3] = { -10.0, (GROUND_LEVEL+0.4), -WORLD_SIZE_Z}; float road1[3] = { -10.0, (GROUND_LEVEL+0.4), WORLD_SIZE_Z}; float road2[3] = { 10.0, (GROUND_LEVEL+0.4), WORLD_SIZE_Z}; float road3[3] = { 10.0, (GROUND_LEVEL+0.4), -WORLD_SIZE_Z}; float egg_x_back = -100.0, egg_x_front = 100.0, egg_y_back = GROUND_LEVEL + 0.5, egg_y_front = 45.0, egg_z_back = -100.0, egg_z_front = 100.0, egg_y_top = 55.0; float center[3]={0.0,0.0,0.0}; float xspeed, yspeed, zspeed; float xrot, yrot, zrot; float eye_x, eye_y, eye_z; float px, py, pz, twist; char char_field_of_view[SIZE], char_aspect_ratio[SIZE], char_near_clipping_plane[SIZE]; char char_far_clipping_plane[SIZE], char_view_distance[SIZE]; char char_azim[SIZE], char_inc[SIZE], char_rotation[SIZE]; char char_xspeed[SIZE], char_yspeed[SIZE], char_zspeed[SIZE]; char char_xrot[SIZE], char_yrot[SIZE], char_zrot[SIZE]; char char_sleepval[SIZE]; char char_eye_x[SIZE], char_eye_y[SIZE], char_eye_z[SIZE]; char char_px[SIZE], char_py[SIZE], char_pz[SIZE]; float octogon_vertice[16][3]= { { 1.0, 2.0, -3.0}, { 2.0, 1.0, -3.0}, { 2.0, -1.0, -3.0}, { 1.0, -2.0, -3.0}, {-1.0, -2.0, -3.0}, {-2.0, -1.0, -3.0}, {-2.0, 1.0, -3.0}, {-1.0, 2.0, -3.0}, { 1.0, 2.0, 3.0}, { 2.0, 1.0, 3.0}, { 2.0, -1.0, 3.0}, { 1.0, -2.0, 3.0}, {-1.0, -2.0, 3.0}, {-2.0, -1.0, 3.0}, {-2.0, 1.0, 3.0}, {-1.0, 2.0, 3.0} }; int octogon_faces[8][4]= { {0,1,9,8}, {1,2,10,9}, {2,3,11,10}, {3,4,12,11}, {4,5,13,12}, {5,6,14,13}, {6,7,15,14}, {7,0,8,15} }; /*************************************************************************/ main(argc, argv) int argc; char **argv; { int i; char *foo; /* defaults */ polygon = wireframe = TRUE; #ifdef DEBUG printf("argc = %i\n", argc); for(i=0; i 1) { /* if there are argv's */ foo = argv[1]; foo++; /* past the dash */ switch(*foo) { case 'w': wireframe = TRUE; polygon = FALSE; break; case 'p': wireframe = FALSE; polygon = TRUE; break; } } #ifdef DEBUG printf(" wireframe = %i\n", wireframe); printf(" polygon = %i\n", polygon); #endif #ifdef DEBUG printf(" initlizing glove.."); #endif file_id = init_glove(); /* initilize glove */ sleepval = 70; /* and sleep time */ #ifdef DEBUG printf(" .. done\n"); #endif init(); /* initilize graphics */ /******* Da Main Loop ************/ while(!getbutton(ESCKEY)) { if( ++click > 999) click=0; winset(EggWindow); /* We are in the Big window */ c3i(background); /* Clear the screen and Zbuffer */ clear(); zclear(); pushmatrix(); input(); /* keyboard input */ query_glove(file_id, &pglove); /* Get the Glove info */ do_perspective(); /* Correct perspective view */ draw_topology(); /* draw ground, roads */ draw_egg(); /* Draw Eggers Hall */ draw_hand(); /* Draw the powerglove data */ popmatrix(); swapbuffers(); do_data(); /* 2nd window */ } printf("\n\nDon't count your Eggs 'till they hatch!\n\n\n"); } /*************************************************************************/ do_perspective() { lookat( eye_x, eye_y, eye_z, px, py, pz, twist); perspective(field_of_view, aspect_ratio, near_clipping_plane, far_clipping_plane); polarview(view_distance,azim,inc,rotation); translate(xspeed, yspeed, zspeed); rot(xrot, 'x'); rot(yrot, 'y'); rot(zrot, 'z'); if( fast_display ) { if(walking && polygon) { polygon= FALSE; wireframe = TRUE; } if(!walking) { polygon= TRUE; } } } /*************************************************************************/ draw_hand() { pushmatrix(); ortho2( -125.0, 125.0, -125.0, 125.0); c3i(aqua); cmov2( 0, 0); charstr("MIDDLE!#$!#$!#$!#$!#$!#$!#$"); circf( 0.0, 0.0, 100.0); pushmatrix(); translate( (float)pglove.x, (float)pglove.y); c3i(red); circf( 0.0, 0.0, 10.0); popmatrix(); popmatrix(); pushmatrix(); translate( (float)pglove.x, (float)pglove.y, (float)pglove.z ); c3i(white); draw_wire_sphere( center, 5.0, 7); popmatrix(); } /*************************************************************************/ draw_topology() { register int i,j; /* draw the ground */ if(polygon) { bgnpolygon(); c3i(grass0); v3f(ground0); v3f(ground1); v3f(ground2); v3f(ground3); endpolygon(); } else if(wireframe) { pushmatrix(); rot(90, 'x'); translate(0,0,10); c3i(grass0); for(i= -WORLD_SIZE_Z; i