next up previous
Next: motion Up: Code Previous: mouse

keyboard

bool isnum(unsigned char key)
{
	return (int(key) < 59 && int(key) > 47);
	/*(key == '0' ||  // if its a number
	key == '1' ||
	key == '2' ||
	key == '3' ||
	key == '4' ||
	key == '5' ||
	key == '6' ||
	key == '7' ||
	key == '8' ||
	key == '9')*/
	}

int tonum(unsigned char key)
{
	return ((int(key) - 48) * 10);
	/*switch(key){
	case '0': return 0; break;
	case '1': return 10; break;
	case '2': return 20; break;
	case '3': return 30; break;
	case '4': return 40; break;
	case '5': return 50; break;
	case '6': return 60; break;
	case '7': return 70; break;
	case '8': return 80; break;
	case '9': return 90; break;
	}*/
	}

void key(unsigned char key, int g, int h)	// my keyboard function
{
  int temp = int(key);
  if(isnum(key)) // if key is a number
  {
	temp = tonum(key); // set temp
	for(int x=0; x<5; x++)
		   for(int y=0; y<3; y++)	
		      angle[x][y]=temp;  // set angle of all joints
  }
	
	else if(((key>=65)&&(key<=90))||((key>=97)&&(key<=122))) // if a letter is pressed
	{
		motion(key);
	}
	
	glutPostRedisplay();
}
This is my main keyboard function. It is also very compllicated because the keyboard is used to modify the hand position for every little thing. If the key pressed is a number (the isnum function retursn true if it is and false if it isnt) then temp equals the number of the key times ten (tonum returns the number of the key). Using askii, I was able to come up with a formula that does exactly the same thing as the commented switch statement, returning the corrent key. When a number is pressed, the angle of every single joint is set to the number temp, or ten times the number pressed. This makes for easy modification of the entire hand quickly. Otherwise, if the key pressed is a number, it is sent to the motion function.



Michael Hull 2003-06-11