/* * 3D Hand version 5.4 * by David Barberi Spring 93 * * Take data from the PowerGlove and translate it into * a roughly real 3-D hand made of lines or polygons * * History: * Added Correct movement in 3-d world * Added Data window to show glove variables * Added Twist * Changed from rotating object to Moving viewpoint * Added graphic Representation of Bad Data * MOVING BOXES!! * Redrew hand with correct orientation * Added tools * redid tons of polygonal and line stuff * added in new sleep timer for glove * Public Release, Spring 93 * * Contact: * dbarberi@sunsite.unc.edu * * * ------ hot keys ----------- * L - Lock hand to center * K - unlock hand * * S - toggle Skeleton * A - toggle Boxes * * F - Toggle Flicker * * Z - Change Azimuth * X - Change Incidence * C - Change Rotation * 0 - View distance Out * I - View Distance In * * # keys - speed of movement (1-45) * R - toggle Rotate mode * F1 - Zbuff on * F2 - Zbuff off * T - Toggle Twist * Y - Toggle show_xyz * B - Toggle box on/off * V - Recenter box * */ char copyright_notice[]=" COPYRIGHT (c) 1991, 1993 by David Barberi "; #include "glove.h" #include #include #define CLICK 10.0 /* Scale of hand size */ #define THUMB_SIZE (CLICK*3.0) #define THUMB_1 (CLICK*2.0) #define THUMB_2 CLICK #define ONE_SIZE (CLICK*5.0) #define ONE_1 ( (CLICK*3.0) -2.0 ) #define ONE_2 ( (CLICK*2.0) -2.0 ) /* useless info */ #define ONE_3 (CLICK - 1.0) #define TWO_SIZE ( (CLICK*5.0) +2.0 ) #define TWO_1 ( (CLICK*3.0) -1.0 ) #define TWO_2 ( (CLICK*2.0) -1.0 ) #define TWO_3 (CLICK - 1.0) #define THREE_SIZE ( (CLICK*5.0) +1.0 ) #define THREE_1 ( (CLICK*3.0) -1.0 ) #define THREE_2 ( (CLICK*2.0) -1.0 ) #define THREE_3 (CLICK - 2.0) #define X 0 #define Y 1 #define Z 2 #define WORLD_SIZE_X 150 /* size of the 'world' box */ #define WORLD_SIZE_Y 150 #define WORLD_SIZE_Z 150 #define rnd rand #define IN_BOX 0 #define NOT_IN_BOX 1 pglove_data pglove; int old_pglove_x, old_pglove_y, old_pglove_z; int box_mode, old_box_mode; float box_location[3], box_xback, box_xfront, box_yback, box_yfront, box_zback, box_zfront; int bad=0, flicker=FALSE; flip=1; float tval; int data; float view_distance, field_of_view, near_clipping_plane, far_clipping_plane, aspect_ratio; float azim, inc, rotation; int twist=TRUE, zbuff, center=FALSE; 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]; typedef struct { /* multiple windows */ int gid; } wrecord; wrecord wins[3]; /* leave 0th spot empty */ int HandWindow, DataWindow; /* names of windows */ /* The Many important points of the hand */ float thumb_nuck[3], thumb_midjoint[3], thumb_tip[3]; float one_nuck[3], one_midjoint[3], one_endjoint[3], one_tip[3]; float two_nuck[3], two_midjoint[3], two_endjoint[3], two_tip[3]; float three_nuck[3], three_midjoint[3], three_endjoint[3], three_tip[3]; float right_thumb_nuck[3], right_thumb_midjoint[3], right_thumb_tip[3]; float right_one_nuck[3], right_one_midjoint[3], right_one_endjoint[3], right_one_tip[3]; float right_two_nuck[3], right_two_midjoint[3], right_two_endjoint[3], right_two_tip[3]; float right_three_nuck[3], right_three_midjoint[3], right_three_endjoint[3], right_three_tip[3]; float left_thumb_nuck[3], left_thumb_midjoint[3], left_thumb_tip[3]; float left_one_nuck[3], left_one_midjoint[3], left_one_endjoint[3], left_one_tip[3]; float left_two_nuck[3], left_two_midjoint[3], left_two_endjoint[3], left_two_tip[3]; float left_three_nuck[3], left_three_midjoint[3], left_three_endjoint[3], left_three_tip[3]; float hand_center[3]; /* = two_nuck[3] */ float grab_point[3], blick; float wrist_right[3], wrist_left[3]; int rotate_mode, ispeed=20; int old_x, old_y, old_z; int show_skeleton, show_outline, show_filled, show_xyz, show_box; long v0[3]={-WORLD_SIZE_X, -WORLD_SIZE_Y, -WORLD_SIZE_Z}; long v1[3]={-WORLD_SIZE_X, -WORLD_SIZE_Y, WORLD_SIZE_X}; long v2[3]={-WORLD_SIZE_X, WORLD_SIZE_Y, WORLD_SIZE_X}; long v3[3]={-WORLD_SIZE_X, WORLD_SIZE_Y, -WORLD_SIZE_Z}; long v4[3]={WORLD_SIZE_X, -WORLD_SIZE_Y, -WORLD_SIZE_Z}; long v5[3]={WORLD_SIZE_X, -WORLD_SIZE_Y, WORLD_SIZE_X}; long v6[3]={WORLD_SIZE_X, WORLD_SIZE_Y, WORLD_SIZE_X}; long v7[3]={WORLD_SIZE_X, WORLD_SIZE_Y, -WORLD_SIZE_Z}; /********************* main() ***********************/ main() { init(); while(!getbutton(ESCKEY)) { winset(HandWindow); pushmatrix(); RGBcolor(1,1,1); clear(); /* Black background */ if(zbuff) zclear(); input(); /* user input on keyboard to move around */ do_perspective(); /* Figure out perspective to look at */ query_the_powerglove(); /* get data from glove */ position_hand(); /* decide x,y,z of hand_center */ get_hand_data(); /* Figure out knuckles, joints, wrist, grab_center */ draw_world(); /* Big box where the glove lives in */ draw_hand(); /* Draw the 3-d Hand inside the world */ if(show_box) draw_boxes(); /* Something to play with */ popmatrix(); swapbuffers(); do_data(); /* Do data window */ } gexit(); printf("\n\n\nRemember....\nPerceptions of Reality are more important then reality itself.\n\n"); printf("\nWhat the? "); } /*******************************************************************/ /* Initialize Graphics, Glove */ /*******************************************************************/ init() { ispeed = 15; file_id = init_glove(); /* open the serial port for glove data */ sleepval = 70; hand_center[X] = 0.0; hand_center[Y] = 0.0; hand_center[Z] = 0.0; show_skeleton=TRUE; show_outline=TRUE; show_filled=TRUE; show_xyz=TRUE; show_box=TRUE; zbuff=TRUE; center_box(); printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf(" Welcome to 3D hand \n\n\n By David Barberi\n\n\n\n\n"); /*** Initialize graphics ****/ /* open HandWindow */ keepaspect(1,1); prefposition(10, 990, 10, 990); wins[1].gid = winopen("3D Hand"); HandWindow = wins[1].gid; doublebuffer(); RGBmode(); gconfig(); zbuffer(TRUE); mmode(MVIEWING); /* Open DataWindow */ keepaspect(1,1); prefposition(1007, 1270, 10, 990); wins[2].gid = winopen("Data"); DataWindow = wins[2].gid; doublebuffer(); RGBmode(); gconfig(); /* initialize Hand window */ winset(HandWindow); view_distance = 400.0; /*700.0;*/ field_of_view = 300.0; /*600;*/ near_clipping_plane = 0.000001; /* 0.1; */ far_clipping_plane = 33.0; /*1000.1;*/ aspect_ratio = 1.0; /*(xmax-xmin)/(ymax-ymin);*/ azim = inc = rotation = 0.0; perspective(field_of_view, aspect_ratio, near_clipping_plane, far_clipping_plane); polarview(view_distance, azim, inc, rotation); } /**********************************************************************/ do_perspective() { perspective(field_of_view, aspect_ratio, near_clipping_plane, far_clipping_plane); polarview(view_distance, azim, inc, rotation); } /*******************************************************************************/ query_the_powerglove() { /* Query the Glove for data, decide if data is good or corrupt */ old_pglove_x = pglove.x; old_pglove_y = pglove.y; old_pglove_z = pglove.z; if (query_glove(file_id, &pglove) == 0) { data = CORRUPT; pglove.gesture = STRANGE; pglove.key = BAD; /* draw_bad_data(); */ return(-1); /* if bad data don't process it */ } else data = GOOD; } /********************************************************/ draw_hand() { pushmatrix(); check_for_twist(); /* rotate hand with pglove.twist */ if(show_skeleton) draw_skeleton(); /* Line drawing of hand */ if(show_outline) draw_polygon_outline(); /* Polygon drawing of hand */ draw_grab_point(); /* Draw the Grab point */ popmatrix(); } /*********************** Position the hand in the world **********/ position_hand() { if(center) { hand_center[X]=0.0; hand_center[Y]=0.0; hand_center[Z]=0.0; } else { hand_center[X] = (float)pglove.x; hand_center[Y] = (float)pglove.y; hand_center[Z] = (float)(pglove.z * ZSCALER); /** Make sure the hand doesn't go outside the world **/ /* if(hand_center[X] > WORLD_SIZE_X) hand_center[X] = WORLD_SIZE_X; if(hand_center[X] < -WORLD_SIZE_X) hand_center[X] = -WORLD_SIZE_X; if(hand_center[Y] > WORLD_SIZE_Y) hand_center[Y] = WORLD_SIZE_Y; if(hand_center[Y] < -WORLD_SIZE_Y) hand_center[Y] = -WORLD_SIZE_Y; if(hand_center[Z] > WORLD_SIZE_Z) hand_center[Z] = WORLD_SIZE_Z; if(hand_center[Z] < -WORLD_SIZE_Z) hand_center[Z] = -WORLD_SIZE_Z; fuck restrictions */ } } /*******************************************************************/ /* Figure out each hand, joint, and finger location */ /*******************************************************************/ get_hand_data() { /* Set the knuckle for each finger */ two_nuck[X] = hand_center[X]; two_nuck[Y] = hand_center[Y]; two_nuck[Z] = hand_center[Z]; one_nuck[X] = two_nuck[X] - CLICK; one_nuck[Y] = two_nuck[Y]; one_nuck[Z] = two_nuck[Z]; three_nuck[X] = two_nuck[X] + CLICK; three_nuck[Y] = two_nuck[Y]; three_nuck[Z] = two_nuck[Z]; thumb_nuck[X] = one_nuck[X] - (CLICK * 0.3); thumb_nuck[Y] = one_nuck[Y]; thumb_nuck[Z] = one_nuck[Z] + (CLICK * 2.2); /* Set the wrist */ wrist_left[X] = one_nuck[X]; wrist_left[Y] = one_nuck[Y]; wrist_left[Z] = one_nuck[Z] + (CLICK * 4.9); wrist_right[X] = three_nuck[X]; wrist_right[Y] = three_nuck[Y]; wrist_right[Z] = three_nuck[Z] + (CLICK * 4.9); /* grab_point is the place to look at to see if we are in a box */ grab_point[X] = hand_center[X]; grab_point[Y] = hand_center[Y] - (CLICK * 1.5); grab_point[Z] = hand_center[Z]; /* Using glove data figure out what finger positions to use */ /* opposable thumb */ switch(pglove.thumb) { case 0: thumb_midjoint[X] = thumb_nuck[X] - (CLICK * 0.5); thumb_midjoint[Y] = thumb_nuck[Y]; thumb_midjoint[Z] = thumb_nuck[Z] - THUMB_1; thumb_tip[X] = thumb_midjoint[X]; thumb_tip[Y] = thumb_midjoint[Y]; thumb_tip[Z] = thumb_midjoint[Z] - THUMB_2; break; case 1: thumb_nuck[Y] -= CLICK; thumb_midjoint[X] = thumb_nuck[X] - (CLICK * 0.5); thumb_midjoint[Y] = thumb_nuck[Y]; thumb_midjoint[Z] = thumb_nuck[Z] - (THUMB_1 * 0.5); thumb_tip[X] = thumb_midjoint[X]; thumb_tip[Y] = thumb_midjoint[Y]; thumb_tip[Z] = thumb_midjoint[Z] - (THUMB_2 * 0.5); break; case 2: thumb_nuck[Y] -= (CLICK * 2.0); thumb_midjoint[X] = one_nuck[X]; thumb_midjoint[Y] = thumb_nuck[Y]; thumb_midjoint[Z] = one_nuck[Z]; thumb_tip[X] = thumb_midjoint[X] + THUMB_1; thumb_tip[Y] = thumb_midjoint[Y]; thumb_tip[Z] = thumb_midjoint[Z]; break; case 3: thumb_nuck[Y] -= (CLICK * 2.0); thumb_midjoint[X] = one_nuck[X]; thumb_midjoint[Y] = thumb_nuck[Y]; thumb_midjoint[Z] = one_nuck[Z]; thumb_tip[X] = two_nuck[X]; thumb_tip[Y] = thumb_midjoint[Y]; thumb_tip[Z] = two_nuck[Z]; break; } /******* one **********/ switch(pglove.one) { case 0: one_midjoint[X] = one_nuck[X]; one_midjoint[Y] = one_nuck[Y]; one_midjoint[Z] = one_nuck[Z] - ONE_1; one_endjoint[X] = one_midjoint[X]; one_endjoint[Y] = one_midjoint[Y]; one_endjoint[Z] = one_midjoint[Z] - ONE_2; one_tip[X] = one_endjoint[X]; one_tip[Y] = one_endjoint[Y]; one_tip[Z] = one_endjoint[Z] - ONE_3; break; case 1: one_midjoint[X] = one_nuck[X]; one_midjoint[Y] = one_nuck[Y] - CLICK; one_midjoint[Z] = one_nuck[Z] - (ONE_1 * 0.8); one_endjoint[X] = one_midjoint[X]; one_endjoint[Y] = one_midjoint[Y] - (CLICK * 2.0); one_endjoint[Z] = one_midjoint[Z] - (ONE_1 * 0.8); one_tip[X] = one_endjoint[X]; one_tip[Y] = one_endjoint[Y] - (CLICK * 3.0); one_tip[Z] = one_endjoint[Z] - (ONE_2 * 0.8); break; case 2: one_midjoint[X] = one_nuck[X]; one_midjoint[Y] = one_nuck[Y] - CLICK; one_midjoint[Z] = one_nuck[Z] - (ONE_1 * 0.8); /* ??? */ one_endjoint[X] = one_midjoint[X]; one_endjoint[Y] = one_midjoint[Y] - (ONE_2 * 0.3); one_endjoint[Z] = one_midjoint[Z] + (CLICK * 3.0); one_tip[X] = one_endjoint[X]; one_tip[Y] = one_endjoint[Y]; one_tip[Z] = one_endjoint[Z] + ONE_3; break; case 3: one_midjoint[X] = one_nuck[X]; one_midjoint[Y] = one_nuck[Y] - (CLICK * 2.0); one_midjoint[Z] = one_nuck[Z] - (ONE_1 * 0.5); one_endjoint[X] = one_midjoint[X]; one_endjoint[Y] = one_midjoint[Y] - (CLICK * 4.0); one_endjoint[Z] = one_midjoint[Z] + (ONE_2 * 0.4); one_tip[X] = one_endjoint[X]; one_tip[Y] = one_endjoint[Y]; one_tip[Z] = one_endjoint[Z] + ONE_3; break; } switch(pglove.two) { case 0: two_midjoint[X] = two_nuck[X]; two_midjoint[Y] = two_nuck[Y]; two_midjoint[Z] = two_nuck[Z] - TWO_1; two_endjoint[X] = two_midjoint[X]; two_endjoint[Y] = two_midjoint[Y]; two_endjoint[Z] = two_midjoint[Z]- TWO_2; two_tip[X] = two_endjoint[X]; two_tip[Y] = two_endjoint[Y]; two_tip[Z] = two_endjoint[Z] - TWO_3; break; case 1: two_midjoint[X] = two_nuck[X]; two_midjoint[Y] = two_nuck[Y] - CLICK; two_midjoint[Z] = two_nuck[Z] -(TWO_1 * 0.8); two_endjoint[X] = two_midjoint[X]; two_endjoint[Y] = two_midjoint[Y] - (CLICK * 2.0); two_endjoint[Z] = two_midjoint[Z] - (TWO_2 * 0.8); two_tip[X] = two_endjoint[X]; two_tip[Y] = two_endjoint[Y] - (CLICK * 3.0); two_tip[Z] = two_endjoint[Z] - (TWO_3 * 0.8); break; case 2: two_midjoint[X] = two_nuck[X] ; two_midjoint[Y] = two_nuck[Y] - CLICK; two_midjoint[Z] = two_nuck[Z] - (TWO_1 * 0.8); two_endjoint[X] = two_midjoint[X]; two_endjoint[Y] = two_midjoint[Y] - (CLICK * 3.0); two_endjoint[Z] = two_midjoint[Z] - (TWO_2 * 0.3); two_tip[X] = two_endjoint[X]; two_tip[Y] = two_endjoint[Y]; two_tip[Z] = two_endjoint[Z] + TWO_3; break; case 3: two_midjoint[X] = two_nuck[X]; two_midjoint[Y] = two_nuck[Y] - (CLICK * 2.0); two_midjoint[Z] = two_nuck[Z] - (TWO_1 * 0.4); two_endjoint[X] = two_midjoint[X] ; two_endjoint[Y] = two_midjoint[Y] - (CLICK * 4.0); two_endjoint[Z] = two_midjoint[Z] + (TWO_2 * 0.4); two_tip[X] = two_endjoint[X]; two_tip[Y] = two_endjoint[Y]; two_tip[Z] = two_endjoint[Z] + TWO_3; break; } switch(pglove.three) { case 0: three_midjoint[X] = three_nuck[X]; three_midjoint[Y] = three_nuck[Y]; three_midjoint[Z] = three_nuck[Z] - THREE_1; three_endjoint[X] = three_midjoint[X]; three_endjoint[Y] = three_midjoint[Y]; three_endjoint[Z] = three_midjoint[Z] - THREE_2; three_tip[X] = three_endjoint[X]; three_tip[Y] = three_endjoint[Y]; three_tip[Z] = three_endjoint[Z] - THREE_3; break; case 1: three_midjoint[X] = three_nuck[X]; three_midjoint[Y] = three_nuck[Y] - CLICK; three_midjoint[Z] = three_nuck[Z] - (THREE_1 * 0.8) ; three_endjoint[X] = three_midjoint[X]; three_endjoint[Y] = three_midjoint[Y] - (THREE_2 * 0.8); three_endjoint[Z] = three_midjoint[Z] - (CLICK * 2.0); three_tip[X] = three_endjoint[X]; three_tip[Y] = three_endjoint[Y] - (CLICK * 3.0); three_tip[Z] = three_endjoint[Z] - (THREE_3 * 0.8); break; case 2: three_midjoint[X] = three_nuck[X]; three_midjoint[Y] = three_nuck[Y] - CLICK; three_midjoint[Z] = three_nuck[Z] - (THREE_1 * 0.8); three_endjoint[X] = three_midjoint[X]; three_endjoint[Y] = three_midjoint[Y] - (CLICK * 3.0); three_endjoint[Z] = three_midjoint[Z] + (THREE_2 * 0.3); three_tip[X] = three_endjoint[X]; three_tip[Y] = three_endjoint[Y]; three_tip[Z] = three_endjoint[Z] + THREE_3; break; case 3: three_midjoint[X] = three_nuck[X]; three_midjoint[Y] = three_nuck[Y] - (CLICK * 2.0); three_midjoint[Z] = three_nuck[Z] - (THREE_1 * 0.5); three_endjoint[X] = three_midjoint[X]; three_endjoint[Y] = three_midjoint[Y] - (CLICK*4); three_endjoint[Z] = three_midjoint[Z] + (THREE_2 * 0.4); three_tip[X] = three_endjoint[X]; three_tip[Y] = three_endjoint[Y]; three_tip[Z] = three_endjoint[Z] + THREE_3; break; } } /*** END get_hand_data() ***/ /******************************************************************/ draw_boxes() { if( ( box_xback < grab_point[X] ) && ( box_xfront > grab_point[X] ) && ( box_yback < grab_point[Y] ) && ( box_yfront > grab_point[Y] ) && ( box_zback < grab_point[Z] ) && ( box_zfront > grab_point[Z] ) ) box_mode = IN_BOX; else box_mode = NOT_IN_BOX; if( (box_mode == IN_BOX) && (pglove.gesture == FIST) ) { box_xback -= (float)(old_pglove_x - pglove.x); box_xfront -= (float)(old_pglove_x - pglove.x); box_yback -= (float)(old_pglove_y - pglove.y); box_yfront -= (float)(old_pglove_y - pglove.y); box_zback -= (float)((old_pglove_z - pglove.z) * ZSCALER); box_zfront -= (float)((old_pglove_z - pglove.z) * ZSCALER); } if(box_mode == IN_BOX) { linewidth(9); RGBcolor(99,175,247); /* draw_poly_rect(box_xback, box_xfront, box_yback, box_yfront, box_zback, box_zfront); */ draw_rectangle(box_xback, box_xfront, box_yback, box_yfront, box_zback, box_zfront); return(0); } if(box_mode == NOT_IN_BOX) { linewidth(2); RGBcolor(250,230,200); /* draw_poly_rect(box_xback, box_xfront, box_yback, box_yfront, box_zback, box_zfront); */ draw_rectangle(box_xback, box_xfront, box_yback, box_yfront, box_zback, box_zfront); return(0); } } /************************ draw_skeleton() **************************/ /***** ****/ /*******************************************************************/ draw_skeleton() { /* knuckles */ linewidth(1); RGBcolor(255,255,0); sphere( one_nuck, (CLICK/8.0), 5); RGBcolor(255,169,0); sphere( two_nuck, (CLICK/8.0), 5); RGBcolor(220, 81, 0); sphere( three_nuck, (CLICK/8.0), 5); RGBcolor(200, 0, 0); sphere( thumb_nuck, (CLICK/8.0), 5); linewidth(3); /* Body of Hand */ RGBcolor(255,181,116); bgnline(); v3f(one_nuck); v3f(thumb_nuck); v3f(wrist_left); v3f(one_nuck); v3f(two_nuck); v3f(three_nuck); v3f(wrist_right); v3f(wrist_left); v3f(three_nuck); v3f(one_nuck); v3f(wrist_right); endline(); /* Thumb */ bgnline(); v3f(thumb_nuck); RGBcolor(255,0,0); v3f(thumb_midjoint); RGBcolor(255, 41, 16); v3f(thumb_tip); endline(); /* First finger */ bgnline(); v3f(one_nuck); RGBcolor(255,0,160); v3f(one_midjoint); RGBcolor(255, 24, 201 ); v3f(one_endjoint); RGBcolor(255, 72, 251 ); v3f(one_tip); endline(); /* Second finger */ bgnline(); v3f(two_nuck); RGBcolor(208,117,0); v3f(two_midjoint); RGBcolor(208,150,59 ); v3f(two_endjoint); RGBcolor(208,150,112 ); v3f(two_tip); endline(); /* Third finger */ bgnline(); v3f(three_nuck); RGBcolor( 0,0,255); v3f(three_midjoint); RGBcolor(0,66,255 ); v3f(three_endjoint); RGBcolor(59, 128, 255 ); v3f(three_tip); endline(); } /*********************** draw_polygon_outline() ********************/ /***** ****/ /*******************************************************************/ draw_polygon_outline() { blick = (CLICK/9.7); /* Thumb */ right_thumb_nuck[X] = thumb_nuck[X] + blick; right_thumb_nuck[Y] = thumb_nuck[Y]; right_thumb_nuck[Z] = thumb_nuck[Z]; left_thumb_nuck[X] = thumb_nuck[X] - blick; left_thumb_nuck[Y] = thumb_nuck[Y]; left_thumb_nuck[Z] = thumb_nuck[Z]; right_thumb_midjoint[X] = thumb_midjoint[X] + blick; right_thumb_midjoint[Y] = thumb_midjoint[Y]; right_thumb_midjoint[Z] = thumb_midjoint[Z]; left_thumb_midjoint[X] = thumb_midjoint[X] - blick; left_thumb_midjoint[Y] = thumb_midjoint[Y]; left_thumb_midjoint[Z] = thumb_midjoint[Z]; right_thumb_tip[X] = thumb_tip[X] + blick; right_thumb_tip[Y] = thumb_tip[Y]; right_thumb_tip[Z] = thumb_tip[Z]; left_thumb_tip[X] = thumb_tip[X] - blick; left_thumb_tip[Y] = thumb_tip[Y]; left_thumb_tip[Z] = thumb_tip[Z]; bgnpolygon(); RGBcolor(255,0,0); v3f(right_thumb_nuck); v3f(left_thumb_nuck); v3f(left_thumb_midjoint); v3f(right_thumb_midjoint); endpolygon(); bgnpolygon(); RGBcolor(255,41,16); v3f(right_thumb_midjoint); v3f(left_thumb_midjoint); v3f(left_thumb_tip); v3f(right_thumb_tip); endpolygon(); bgnpolygon(); RGBcolor(230,166,116); v3f(wrist_left); v3f(thumb_nuck); v3f(one_nuck); endpolygon(); /* First finger */ right_one_nuck[X] = one_nuck[X] + blick; right_one_nuck[Y] = one_nuck[Y]; right_one_nuck[Z] = one_nuck[Z]; left_one_nuck[X] = one_nuck[X] - blick; left_one_nuck[Y] = one_nuck[Y]; left_one_nuck[Z] = one_nuck[Z]; right_one_midjoint[X] = one_midjoint[X] + blick; right_one_midjoint[Y] = one_midjoint[Y]; right_one_midjoint[Z] = one_midjoint[Z]; left_one_midjoint[X] = one_midjoint[X] - blick; left_one_midjoint[Y] = one_midjoint[Y]; left_one_midjoint[Z] = one_midjoint[Z]; right_one_endjoint[X] = one_endjoint[X] + blick; right_one_endjoint[Y] = one_endjoint[Y]; right_one_endjoint[Z] = one_endjoint[Z]; left_one_endjoint[X] = one_endjoint[X] - blick; left_one_endjoint[Y] = one_endjoint[Y]; left_one_endjoint[Z] = one_endjoint[Z]; right_one_tip[X] = one_tip[X] + blick; right_one_tip[Y] = one_tip[Y]; right_one_tip[Z] = one_tip[Z]; left_one_tip[X] = one_tip[X] - blick; left_one_tip[Y] = one_tip[Y]; left_one_tip[Z] = one_tip[Z]; RGBcolor(255,0,160); bgnpolygon(); v3f(right_one_nuck); v3f(left_one_nuck); v3f(left_one_midjoint); v3f(right_one_midjoint); endpolygon(); RGBcolor(255,0,160); bgnpolygon(); v3f(right_one_midjoint); v3f(left_one_midjoint); v3f(left_one_endjoint); v3f(right_one_endjoint); endpolygon(); RGBcolor(255, 72, 251 ); bgnpolygon(); v3f(right_one_endjoint); v3f(left_one_endjoint); v3f(left_one_tip); v3f(right_one_tip); endpolygon(); /* Second finger */ right_two_nuck[X] = two_nuck[X] + blick; right_two_nuck[Y] = two_nuck[Y]; right_two_nuck[Z] = two_nuck[Z]; left_two_nuck[X] = two_nuck[X] - blick; left_two_nuck[Y] = two_nuck[Y]; left_two_nuck[Z] = two_nuck[Z]; right_two_midjoint[X] = two_midjoint[X] + blick; right_two_midjoint[Y] = two_midjoint[Y]; right_two_midjoint[Z] = two_midjoint[Z]; left_two_midjoint[X] = two_midjoint[X] - blick; left_two_midjoint[Y] = two_midjoint[Y]; left_two_midjoint[Z] = two_midjoint[Z]; right_two_endjoint[X] = two_endjoint[X] + blick; right_two_endjoint[Y] = two_endjoint[Y]; right_two_endjoint[Z] = two_endjoint[Z]; left_two_endjoint[X] = two_endjoint[X] - blick; left_two_endjoint[Y] = two_endjoint[Y]; left_two_endjoint[Z] = two_endjoint[Z]; right_two_tip[X] = two_tip[X] + blick; right_two_tip[Y] = two_tip[Y]; right_two_tip[Z] = two_tip[Z]; left_two_tip[X] = two_tip[X] - blick; left_two_tip[Y] = two_tip[Y]; left_two_tip[Z] = two_tip[Z]; RGBcolor(208,117,0); bgnpolygon(); v3f(right_two_nuck); v3f(left_two_nuck); v3f(left_two_midjoint); v3f(right_two_midjoint); endpolygon(); RGBcolor(208,125,55 ); bgnpolygon(); v3f(right_two_midjoint); v3f(left_two_midjoint); v3f(left_two_endjoint); v3f(right_two_endjoint); endpolygon(); RGBcolor(208,150,112 ); bgnpolygon(); v3f(right_two_endjoint); v3f(left_two_endjoint); v3f(left_two_tip); v3f(right_two_tip); endpolygon(); /* third finger */ right_three_nuck[X] = three_nuck[X] + blick; right_three_nuck[Y] = three_nuck[Y]; right_three_nuck[Z] = three_nuck[Z]; left_three_nuck[X] = three_nuck[X] - blick; left_three_nuck[Y] = three_nuck[Y]; left_three_nuck[Z] = three_nuck[Z]; right_three_midjoint[X] = three_midjoint[X] + blick; right_three_midjoint[Y] = three_midjoint[Y]; right_three_midjoint[Z] = three_midjoint[Z]; left_three_midjoint[X] = three_midjoint[X] - blick; left_three_midjoint[Y] = three_midjoint[Y]; left_three_midjoint[Z] = three_midjoint[Z]; right_three_endjoint[X] = three_endjoint[X] + blick; right_three_endjoint[Y] = three_endjoint[Y]; right_three_endjoint[Z] = three_endjoint[Z]; left_three_endjoint[X] = three_endjoint[X] - blick; left_three_endjoint[Y] = three_endjoint[Y]; left_three_endjoint[Z] = three_endjoint[Z]; right_three_tip[X] = three_tip[X] + blick; right_three_tip[Y] = three_tip[Y]; right_three_tip[Z] = three_tip[Z]; left_three_tip[X] = three_tip[X] - blick; left_three_tip[Y] = three_tip[Y]; left_three_tip[Z] = three_tip[Z]; RGBcolor( 0,0,255); bgnpolygon(); v3f(right_three_nuck); v3f(left_three_nuck); v3f(left_three_midjoint); v3f(right_three_midjoint); endpolygon(); RGBcolor(0,66,255 ); bgnpolygon(); v3f(right_three_midjoint); v3f(left_three_midjoint); v3f(left_three_endjoint); v3f(right_three_endjoint); endpolygon(); RGBcolor(59, 128, 255 ); bgnpolygon(); v3f(right_three_endjoint); v3f(left_three_endjoint); v3f(left_three_tip); v3f(right_three_tip); endpolygon(); /* body of hand */ RGBcolor(255,181,116); bgnpolygon(); v3f(one_nuck); v3f(two_nuck); v3f(three_nuck); v3f(wrist_right); v3f(wrist_left); endpolygon(); } /*******************************************************************/ center_box() { box_xback = 0.0; box_xfront = 80.0; box_yback = 0.0; box_yfront = 80.0; box_zback = 0.0; box_zfront = 80.0; } /*************** draw_grab_point() ************/ draw_grab_point() { linewidth(3); RGBcolor(77,77,77); move(grab_point[X]-5, grab_point[Y], grab_point[Z]); draw(grab_point[X]+5, grab_point[Y], grab_point[Z]); move(grab_point[X], grab_point[Y]-5, grab_point[Z]); draw(grab_point[X], grab_point[Y]+5, grab_point[Z]); move(grab_point[X], grab_point[Y], grab_point[Z]-5); draw(grab_point[X], grab_point[Y], grab_point[Z]+5); } /*************** Bad Data! Bad! ***********/ draw_bad_data() { RGBcolor(237, 61, 7); linewidth(10); pushmatrix(); bad += 5; if(bad > 360) bad -= 360; rot(bad, 'x'); rot(bad, 'y'); rot(bad, 'z'); pushmatrix(); RGBcolor(255,0,0 ); circ(0.0, 0.0, (float)(WORLD_SIZE_Y * 0.06)); rot(80, 'x'); RGBcolor(235, 70, 8); circ(0.0, 0.0, (float)(WORLD_SIZE_X * 0.25)); rot(76, 'x'); RGBcolor(235, 255, 0); circ(0.0, 0.0, (float)(WORLD_SIZE_Y * 0.50)); rot(86, 'x'); RGBcolor(40, 125, 205); circ(0.0, 0.0, (float)(WORLD_SIZE_Z * 0.75)); rot(54, 'x'); RGBcolor(7,42,94 ); circ(0.0, 0.0, (float)(WORLD_SIZE_Z )); popmatrix(); popmatrix(); } /**********************************************************************/ check_for_twist() { /** twist of the wrist ***/ if(twist==TRUE) { switch(pglove.twist) { case 0: return(1); break; case 1: rot(-8, 'z'); break; case 2: rot(-16, 'z'); break; case 3: rot(-24, 'z'); break; case 4: rot(-32, 'z'); break; case 5: rot(-40, 'z'); break; case 6: rot(-48, 'z'); break; case 7: rot(-56, 'z'); break; case 8: rot(32, 'z'); break; case 9: rot(24, 'z'); break; case 10: rot(16, 'z'); break; case 11: rot(8, 'z'); break; } } } /*******************************************************************/ input() { if(getbutton(BKEY)) { if(show_box) show_box=FALSE; else show_box=TRUE; } if(getbutton(VKEY)) center_box(); if(getbutton(FKEY)) { /* Toggle 3-d */ if(flicker==TRUE) flicker=FALSE; else flicker=TRUE; } if(getbutton(LKEY)) center=TRUE; /* lock on 0,0,0 */ if(getbutton(KKEY)) center=FALSE; if(getbutton(YKEY)) { if(show_xyz) show_xyz=FALSE; else show_xyz=TRUE; } if(getbutton(F1KEY)) { zbuffer(TRUE); zbuff=TRUE; zclear(); } if(getbutton(F2KEY)) { zbuffer(FALSE); zbuff = FALSE; } if(getbutton(AKEY)) { if(show_filled==TRUE) show_filled=FALSE; else show_filled=TRUE; } if(getbutton(SKEY)) { if(show_skeleton==TRUE) show_skeleton=FALSE; else show_skeleton=TRUE; } if(getbutton(AKEY)) { if(show_outline==TRUE) show_outline=FALSE; else show_outline=TRUE; } if(getbutton(TKEY)) { if(twist==TRUE) twist=FALSE; else twist=TRUE; } if(getbutton(RKEY)) { if(rotate_mode==TRUE) rotate_mode = FALSE; else rotate_mode = TRUE; } /* R toggels rotation mode ON/OFF */ if(rotate_mode==TRUE) { azim += ispeed; inc += ispeed; rotation += ispeed; } if(getbutton(ONEKEY)) ispeed = 1; /* Number keys */ if(getbutton(TWOKEY)) ispeed = 5; /* control the speed */ if(getbutton(THREEKEY)) ispeed = 10; /* of movement */ if(getbutton(FOURKEY)) ispeed = 15; if(getbutton(FIVEKEY)) ispeed = 20; if(getbutton(SIXKEY)) ispeed = 25; if(getbutton(SEVENKEY)) ispeed = 30; if(getbutton(EIGHTKEY)) ispeed = 35; if(getbutton(NINEKEY)) ispeed = 45; if(getbutton(ZEROKEY)) ispeed = 55; if (getbutton(LEFTSHIFTKEY) || getbutton(RIGHTSHIFTKEY)) { if (getbutton(ZKEY)) azim = azim - ispeed; if (getbutton(XKEY)) inc = inc - ispeed; if (getbutton(CKEY)) rotation = rotation - ispeed; } else { if (getbutton(ZKEY)) azim += ispeed; if (getbutton(XKEY)) inc += ispeed; if (getbutton(CKEY)) rotation +=ispeed; if (getbutton(IKEY)) view_distance -= ispeed; if (getbutton(OKEY)) view_distance += ispeed; } } /***********************************************************/ /**** do_data() ***/ /***********************************************************/ do_data() { winset(DataWindow); pushmatrix(); ortho2(0.0, 25.0, 0.0, 1000.0); RGBcolor(40,40,40); clear(); RGBcolor(123,255,255); cmov2(5,985); charstr(" ******* "); cmov2(1,968); charstr(" Live Virtually..........."); cmov2(7,940); charstr("3D HAND"); cmov2(5,925); charstr("by"); RGBcolor(255,255,255); charstr(" David Barberi"); print_modes(); /* get char of glove data */ cmov2(1,890); RGBcolor(123,255,255); charstr("gesture= "); RGBcolor(255,250,2); charstr(char_gesture); RGBcolor(123,255,255); cmov2(1,870); charstr("key= "); RGBcolor(255,250,2); charstr(char_key); cmov2(1,850); RGBcolor(123,255,255); if(data==GOOD) charstr("Glove Data is Good"); else { RGBcolor(255,0,0); charstr("BAD Glove data!!!!!!!"); } cmov2(1, 825); RGBcolor(123,255,255); charstr("x="); RGBcolor(255,250,2); charstr(char_x); cmov2(8,825); RGBcolor(123,255,255); charstr("y="); RGBcolor(255,250,2); charstr(char_y); cmov2(15,825); RGBcolor(123,255,255); charstr("z="); RGBcolor(255,250,2); charstr(char_z); cmov2(1,800); RGBcolor(123,255,255); charstr("thumb="); RGBcolor(255,250,2); charstr(char_thumb); cmov2(1,780); RGBcolor(123,255,255); charstr("one ="); RGBcolor(255,250,2); charstr(char_one); cmov2(1,760); RGBcolor(123,255,255); charstr("two ="); RGBcolor(255,250,2); charstr(char_two); cmov2(1,740); RGBcolor(123,255,255); charstr("three="); RGBcolor(255,250,2); charstr(char_three); cmov2(1,720); RGBcolor(123,255,255); charstr("twist="); RGBcolor(255,250,2); charstr(char_twist); cmov2(15, 780); RGBcolor(123,255,255); charstr("key1="); RGBcolor(255,250,2); charstr(char_key1); cmov2(15, 760); RGBcolor(123,255,255); charstr("key2="); RGBcolor(255,250,2); charstr(char_key2); cmov2(15, 740); RGBcolor(123,255,255); charstr("key3="); RGBcolor(255,250,2); charstr(char_key3); cmov2(15, 720); RGBcolor(123,255,255); charstr("key4="); RGBcolor(255,250,2); charstr(char_key4); cmov2(1,520); RGBcolor(123,255,255); charstr("Rendering as: "); RGBcolor(255,250,2); if(show_skeleton) charstr("Lines "); if(show_outline) charstr("Polygons"); cmov2(1, 500); RGBcolor(123,255,255); charstr("box_mode="); RGBcolor(255,250,2); if(box_mode==IN_BOX) charstr("IN_BOX"); if(box_mode==NOT_IN_BOX) charstr("NOT_IN_BOX"); cmov2(0,1); charstr("123456789-123456789-123456789-123"); swapbuffers(); popmatrix(); } /***********************************************************/ /**** draw_world() ***/ /***********************************************************/ draw_world() { RGBcolor(77,77,77); linewidth(2); bgnline(); v3i(v0); v3i(v1); v3i(v2); v3i(v3); v3i(v0); v3i(v4); v3i(v5); v3i(v6); v3i(v7); v3i(v4); v3i(v5); v3i(v1); v3i(v2); v3i(v6); v3i(v7); v3i(v3); endline(); if(show_xyz) { RGBcolor(73,11,0); move(0,0,-5); draw(0,0,30); move(-5,0,0); draw(20,0,0); move(0,-5,0); draw(0,20,0); cmov(0,0,10); RGBcolor(255,255,255); charstr("z"); cmov(10,0,0); charstr("x"); cmov(0,10,0); charstr("y"); } } /******************************************************/ /******************************************************/ /******* Iris Graphic TOOLS ******/ /******************************************************/ /******************************************************/ /* * draw_rectangle() Wire Frame Rectangle * draw_poly_rect() Polygonal Rectangle * sphere() Wire Frame Sphere */ /************************* draw_rectangle ***********************/ /*** Wire frame Rectangle Tool ***/ /****************************************************************/ draw_rectangle(xback, xfront, yback, yfront, zback, zfront) float xback, xfront, yback, yfront, zback, zfront; { float b0[3], b1[3], b2[3], b3[3], b4[3], b5[3], b6[3], b7[3]; b0[0] = xback; b0[1] = yback; b0[2] = zback; b1[0] = xback; b1[1] = yback; b1[2] = zfront; b2[0] = xback; b2[1] = yfront; b2[2] = zfront; b3[0] = xback; b3[1] = yfront; b3[2] = zback; b4[0] = xfront; b4[1] = yback; b4[2] = zback; b5[0] = xfront; b5[1] = yback; b5[2] = zfront; b6[0] = xfront; b6[1] = yfront; b6[2] = zfront; b7[0] = xfront; b7[1] = yfront; b7[2] = zback; pushmatrix(); bgnline(); v3f(b0); v3f(b1); v3f(b2); v3f(b3); v3f(b0); v3f(b4); v3f(b5); v3f(b6); v3f(b7); v3f(b4); v3f(b5); v3f(b1); v3f(b2); v3f(b6); v3f(b7); v3f(b3); endline(); popmatrix(); } /*********************** draw_poly_rect() *************************/ /*** Polygonal Rectangle TOOL ***/ /******************************************************************/ draw_poly_rect(xback, xfront, yback, yfront, zback, zfront) float xback, xfront, yback, yfront, zback, zfront; { float p0[3], p1[3], p2[3], p3[3], p4[3], p5[3], p6[3], p7[3]; p0[0] = xback; p0[1] = yback; p0[2] = zback; p1[0] = xback; p1[1] = yback; p1[2] = zfront; p2[0] = xback; p2[1] = yfront; p2[2] = zfront; p3[0] = xback; p3[1] = yfront; p3[2] = zback; p4[0] = xfront; p4[1] = yback; p4[2] = zback; p5[0] = xfront; p5[1] = yback; p5[2] = zfront; p6[0] = xfront; p6[1] = yfront; p6[2] = zfront; p7[0] = xfront; p7[1] = yfront; p7[2] = zback; pushmatrix(); bgnpolygon(); /* xback */ v3f(p0); v3f(p1); v3f(p2); v3f(p3); endpolygon(); bgnpolygon(); /* yback */ v3f(p0); v3f(p1); v3f(p5); v3f(p4); endpolygon(); bgnpolygon(); /* zback */ v3f(p0); v3f(p4); v3f(p7); v3f(p3); endpolygon(); bgnpolygon(); /* xfront */ v3f(p4); v3f(p5); v3f(p6); v3f(p7); endpolygon(); bgnpolygon(); /* yfront */ v3f(p3); v3f(p2); v3f(p6); v3f(p7); endpolygon(); bgnpolygon(); /* zfront */ v3f(p1); v3f(p5); v3f(p6); v3f(p2); endpolygon(); popmatrix(); } /************************ sphere() ************************/ /****** Jeff Ventrella's Sphere tool, in C ***/ /**********************************************************/ sphere(center, radius, res) float center[3], radius; int res; { int i, resol; resol = (int)(1800.0/(float)(res)); pushmatrix(); translate(center[0], center[1], center[2]); pushmatrix(); for(i=1; i < res; i++) { rotate(resol, 'x'); circ(0.0, 0.0, radius); } popmatrix(); pushmatrix(); for(i=1; i < res; i++) { rotate(resol, 'y'); circ(0.0, 0.0, radius); } popmatrix(); rotate(900, 'x'); pushmatrix(); for(i=1; i < res; i++) { rotate(resol, 'y'); circ(0.0, 0.0, radius); } popmatrix(); popmatrix(); } /* La finis, c'est la vie! */