PDA

View Full Version : Auto-movement



negative_pi
02-23-2002, 01:58 PM
I want to be able to move to a certain position with just a simple press of a key. My problem is that I don't know how to go about doing something like this. Any help?

nexusone
02-23-2002, 04:03 PM
You can use glutKeyboardFunc to read for a key on the keyboard to be pressed.
The when the key you have selected has been press just change the varible holding the location of the object to where you want it to go.


Originally posted by negative_pi:
I want to be able to move to a certain position with just a simple press of a key. My problem is that I don't know how to go about doing something like this. Any help?

negative_pi
02-23-2002, 05:25 PM
Can you give me an example of how to use the glutKeyboardFunc? I'm kinda new to it.

nexusone
02-24-2002, 05:10 AM
Here is a example

glutKeyboardFunc(keyboard); // Tells glut to start the keyboard function
glutMainLoop(); //last call in your main() loop


void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 'W': // Example pressing 'W' changes my scale value.
wscale = wscale + 0.01f;
if (wscale > 10) wscale = 0;
glutPostRedisplay();
break;
case 27: // on pressing the "ESC" key quit program.
exit(0);
break;
default:
break;
}


}



Originally posted by negative_pi:
Can you give me an example of how to use the glutKeyboardFunc? I'm kinda new to it.

negative_pi
02-24-2002, 05:33 AM
Thanks.