示例#1
0
def draw():
	glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT) #Clean the frame

	setViewport()
	setProjection()
	setCamera()

	#Game status control
	global steps, running, counter

	frame = controller.frame()

	if running:
		drawText("Hold Ok gesture to close")
		for hand in frame.hands:

			if gesture.detectRunGesture(hand, tolerance): #If a step is detected, count it
				steps = steps + 1

			#If ok gesture is detected for 60 frames, close the game

			if gesture.detectOKGesture(hand, tolerance): 
				counter = counter + 1
			else:
				counter = 0

			if counter > 60:
				sys.exit(0)



	else:
		drawText("Ok gesture to start")

		for hand in frame.hands:
			if gesture.detectOKGesture(hand, tolerance):
				running = True
				pygame.mixer.music.play(-1)
			

	drawLeap()
	drawHands(frame.hands)
	drawSteps(str(steps))

	glutSwapBuffers() #Change this frame and the old frame
示例#2
0
def init(arguments, newController, newTolerance):
	global controller
	controller = newController #Set the controller

	global tolerance
	tolerance = newTolerance #Set the tolerance


	#Tutorial
	pygame.init()
	img = pygame.image.load(os.path.abspath('utils/images/tutorial1.jpg'))
	screen = pygame.display.set_mode((1024,800))
	screen.blit(img,(0,0))
	pygame.display.flip()

	img = pygame.image.load(os.path.abspath('utils/images/tutorial2.jpg'))
	screen.blit(img,(0,0))
	time.sleep(5)
	pygame.display.flip()

	img = pygame.image.load(os.path.abspath('utils/images/tutorial3.jpg'))
	screen.blit(img,(0,0))

	waitingOk = True

	# Wait gesture "OK" to start the game
	while waitingOk:
		time.sleep(0.02)
		frame = controller.frame()

		for hand in frame.hands:

			if gesture.detectOKGesture(hand, tolerance) == 1:
				waitingOk = False

	pygame.display.flip()

	time.sleep(3)

	pygame.display.quit()

	#Load music
	pygame.mixer.init()
	pygame.mixer.music.load(os.path.abspath('utils/epic_music.mp3'))

	#Set OpenGL
	initGlut(arguments)
	initOpenGL()

	#Start OpenGL loop
	glutMainLoop()