Key movement using OpenGL
Here is a tiny piece of code that will let you do the following:
a.) Use the Up and Down arrow keys to move forward and backward in the arena
b.) Use the Left and Right arrow keys to turn left and right. No movement as such.
c.) Use F2 and F1 to move sideways right and left.
NOTE: Change the value 10 to any other value depending on how fast you want to move.
As of now the eye movement is controlled using the keyboard. It will be better to do that with the mouse. Should implement it sometime.
Here is a tiny piece of code that will let you do the following:
a.) Use the Up and Down arrow keys to move forward and backward in the arena
b.) Use the Left and Right arrow keys to turn left and right. No movement as such.
c.) Use F2 and F1 to move sideways right and left.
void keyboardHandler(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_UP:
gzDistance = gzDistance + 10*cos(gyAngle*PI/180);
gxDistance = gxDistance - 10*sin(gyAngle*PI/180);
break;
case GLUT_KEY_DOWN:
gzDistance = gzDistance - 10*cos(gyAngle*PI/180);
gxDistance = gxDistance + 10*sin(gyAngle*PI/180);
break;
case GLUT_KEY_F2:
gxDistance = gxDistance - 10*cos(gyAngle*PI/180);
gzDistance = gzDistance - 10*sin(gyAngle*PI/180);
break;
case GLUT_KEY_F1:
gxDistance = gxDistance + 10*cos(gyAngle*PI/180);
gzDistance = gzDistance + 10*sin(gyAngle*PI/180);
break;
case GLUT_KEY_LEFT:
gyAngle = gyAngle - 10;
break;
case GLUT_KEY_RIGHT:
gyAngle = gyAngle + 10;
break;
}
glutPostRedisplay();
}
{
switch(key)
{
case GLUT_KEY_UP:
gzDistance = gzDistance + 10*cos(gyAngle*PI/180);
gxDistance = gxDistance - 10*sin(gyAngle*PI/180);
break;
case GLUT_KEY_DOWN:
gzDistance = gzDistance - 10*cos(gyAngle*PI/180);
gxDistance = gxDistance + 10*sin(gyAngle*PI/180);
break;
case GLUT_KEY_F2:
gxDistance = gxDistance - 10*cos(gyAngle*PI/180);
gzDistance = gzDistance - 10*sin(gyAngle*PI/180);
break;
case GLUT_KEY_F1:
gxDistance = gxDistance + 10*cos(gyAngle*PI/180);
gzDistance = gzDistance + 10*sin(gyAngle*PI/180);
break;
case GLUT_KEY_LEFT:
gyAngle = gyAngle - 10;
break;
case GLUT_KEY_RIGHT:
gyAngle = gyAngle + 10;
break;
}
glutPostRedisplay();
}
NOTE: Change the value 10 to any other value depending on how fast you want to move.
As of now the eye movement is controlled using the keyboard. It will be better to do that with the mouse. Should implement it sometime.

