-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBouncingBallController.py
More file actions
26 lines (21 loc) · 1.09 KB
/
BouncingBallController.py
File metadata and controls
26 lines (21 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
import BouncingBallModel
from OpenGL.GLUT import *
pause = False
def keyEvent(key, x, y):
#Press the space bar to pause or unpause the boucning ball
if key == chr(32):
BouncingBallModel.setPause(not BouncingBallModel.pause)
def specialKeyEvent(key,x,y):
#Left arrow to decrease x velocity
if key == GLUT_KEY_LEFT:
BouncingBallModel.changeVelocity('glutSolidSphere', BouncingBallModel.objects['glutSolidSphere']['velocity'][0] - .01, 0)
#Right arrow to increase x velocity
elif key == GLUT_KEY_RIGHT:
BouncingBallModel.changeVelocity('glutSolidSphere', BouncingBallModel.objects['glutSolidSphere']['velocity'][0] + .01, 0)
#Up arrow to increase y velocity
elif key == GLUT_KEY_UP:
BouncingBallModel.changeVelocity('glutSolidSphere', BouncingBallModel.objects['glutSolidSphere']['velocity'][1] + .01, 1)
#Down arrow to decrease y velocity
elif key == GLUT_KEY_DOWN:
BouncingBallModel.changeVelocity('glutSolidSphere', BouncingBallModel.objects['glutSolidSphere']['velocity'][1] - .01, 1)