next up previous
Next: thumb Up: Code Previous: palm

finger

void finger(int test, double x, double y) // draws, you guessed it, a finger
{
glPushMatrix();
  rotx(-90);
  glTranslatef(2.5-1.66666666*test, 0, 0);    // move to x position of finger
  double tempy = 2.85-.15*pow((test-1), 2);
  if(cyl[test])					// if told to (cyl == true)
    gluCylinder(gluNewQuadric(), 1.0, joint[test][0], tempy, F, F); // draws a cylinder connecting
								  // the base of the knuckle to the side of the hand
  glPushMatrix();
	glTranslatef(0, 0, tempy);  		// move to y position of finger
	glutSolidSphere(joint[test][0], F, F);		// draws the knuckle
	glPushMatrix();
	  //glRotatef(-5, 0, 0, 1.0);
	  rotx(angle[test][0]);
	  gluCylinder(gluNewQuadric(), joint[test][0], joint[test][1], dist[test][0], F, F); // -
      glTranslatef(0, 0, dist[test][0]);							// | first joint
	  glutSolidSphere(joint[test][1], F, F);						// -
	  glPushMatrix();									
		rotx(angle[test][1]);						                // -
		gluCylinder(gluNewQuadric(), joint[test][1], joint[test][2], dist[test][1], F, F);	// | second joint
		glTranslatef(0, 0, dist[test][1]);							// |
		glutSolidSphere(joint[test][2], F, F);							// -
		glPushMatrix();
		  rotx(angle[test][2]);						// -
		  gluCylinder(gluNewQuadric(), joint[test][2], joint[test][3], dist[test][2], F, F);	// | final digit
		  glTranslatef(0, 0, dist[test][2]);							// |
		  glutSolidSphere(joint[test][3], F, F);						// -
		glPopMatrix();
	  glPopMatrix();
	glPopMatrix();
  glPopMatrix();
glPopMatrix();
}
The finger was the most complicated functions simply because it had to cover for all 4. The number test is used to differentiate between the different fingers. double x and y are currently not used, although they would have been the position variables in earlier versions. Now, tough, the position is calculated in the finger function using the number test, or which finger is being drawn. This function draws the finger starting at the position calculated. cyl[] is an array that decides whether or not a cylinder is drawn to the palm from the knuckle,. This is done for the 2 outside fingers in order to make the hand appear realistic. The first 2 translate calls moves the drawing position to the start of the hand. The first sphere is drawn as the knuckle with a size determined by the array joint[]. every knuckle after it is determined through sixe by this 2 dimensional array. rotx is called to rotate the finger, with respect to the x asis, as much as the array angle[] tells it to. This is the bend in the finger itself. this array is modifiable in order to allow for the user to change the bend in the fingers and move the hand. the cylinder is then drawn that is the digit itself. The radius of the bottom of the finger is the same as the knuckle at the bas of the digit, and the raduis of the top of the digit is the same as the radius of the joint at the top of the digit. This amakes for smooth continuous bends in the finger without overy large knuckles. The position of the matrix, or where things are drawn, is then moved to the end of the digit, or cylinder. This process is repeated for all of the 3 digits of each finger, which by definition of the initialization of the arrays, get smaller the firther from the hand you get. A final sphere is drawn at the end of the third digit to cap the finger, so it doesnt appear hollow. The middle finger is the larges, both in length and in radius. The ring and index finger are the same size, and the pinkie is the smallest. This is determined through the earlier inital values given in the initialization function. At the end of the function, all of the matrices used for drawing are popped, kind of the way of ending that particular reference which built upon each other as the drawing moved out along the finger. These matrices create a reference that moves so that everything is drawn at its origin, which is moved to the different parts of the screen and rotated as to create the image desired. popping them resets the drawing perspective to the original coordinates of (0, 0, 0). This allows for other objects to be drawn later.


next up previous
Next: thumb Up: Code Previous: palm
Michael Hull 2003-06-11