/******************************************************************* Support Routines for a Simple Hand Model ******************************************************************** Author: Stan Sclaroff Date: October 2, 2006 Comments: This is just meant for demonstration. You can extend/rewrite this code for the assignment. ********************************************************************/ #include #include #include #include #include #include #include #include "const.h" #include "types.h" static GLint hand_object; /* You will need to modify this routine! */ void updateHandObject(GLint hand_object, handType *hand) { glNewList(hand_object,GL_COMPILE); glColor3f(0.8,0.5,0.2); /* create an ellipsoid by scaling a sphere */ glScalef(0.5,1.0,2.0); glutSolidSphere(hand->scale,36,18); glEndList(); } /* create the hand geometry */ GLint createHandObject(handType *hand) { GLint hand_object; hand_object = glGenLists(1); updateHandObject(hand_object,hand); return(hand_object); } /* draw the OpenGL object for the hand */ void drawHandObject(handType *hand) { static GLint hand_object; /* if the hand object does not exist, create it */ /* then create/recreate the hand object with updated info */ if(!hand_object) hand_object = createHandObject(hand); else updateHandObject(hand_object,hand); /* call the hand's OpenGL object */ glCallList(hand_object); } /* Hand structure maint. functions*/ /* create a hand */ handType *createHand(float scale) { handType *h; int i; h = calloc(sizeof(handType),1); h->scale = scale; h->active_rotation_axis = AXIS_X; h->active_joint = JOINT_DISTAL; h->angles[0] = h->angles[1] = 0.0; for(i=0;i<5;++i) h->active_fingers[i] = FALSE; return(h); } /* Toggle which fingers are active */ void toggleFinger(handType *hand, int finger) { if(hand && finger >= 0 && finger < 5) { if(hand->active_fingers[finger] == FALSE) hand->active_fingers[finger] = TRUE; else hand->active_fingers[finger] = FALSE; } } /* select axis (x,y,z) is used for rotation */ void selectRotationAxis(handType *hand, int axis_num) { if(hand) hand->active_rotation_axis = axis_num; } /* select which of three finger joints is active */ void selectJoint(handType *hand, int joint_id) { if(hand) hand->active_joint = joint_id; } /* increment/decrement the rotation angle */ void incrementAngle(handType *hand, float delta) { /* you will need to completely rewrite this function */ if(hand) hand->angles[hand->active_rotation_axis]+=delta; }