def main(): global window, time, light, inc, whichTex, frame, fogEnd pygame.init() screen = pygame.display.set_mode((640,480), OPENGL|DOUBLEBUF)#|FULLSCREEN) pygame.display.set_caption('The Jade Palace') screentoggle = False clock = pygame.time.Clock() time = 0.0 light = N.array((10,10,10,0), dtype = N.float32) inc = 0.05 whichTex = 0 init() frame = Frame() fogEnd = 150.0 while True: for event in pygame.event.get(): if event.type == QUIT: return if event.type == KEYUP and event.key == K_ESCAPE: return if event.type == KEYDOWN: if event.key == K_s: if inc == 0.0: inc = 0.2 else: inc = 0.0 pressed = pygame.key.get_pressed() if pressed[K_UP]: frame.move(0.25) if pressed[K_DOWN]: frame.move(-0.25) if pressed[K_a]: frame.tilt(1.0) if pressed[K_z]: frame.tilt(-1.0) if pressed[K_LEFT]: if pressed[K_LSHIFT]: frame.strafe(0.25) else: frame.rotate(1.0) if pressed[K_RIGHT]: if pressed[K_LSHIFT]: frame.strafe(-0.25) else: frame.rotate(-1.0) if pressed[K_f]: fogEnd *= 1.1 if pressed[K_v]: fogEnd *= 0.9 clock.tick(30) time += inc display() pygame.display.flip()
def main(): global theWorld pygame.init() screen = pygame.display.set_mode((800,800), OPENGL|DOUBLEBUF) frame = Frame() have_joystick = False if pygame.joystick.get_count() > 0: have_joystick = True autoRotation = False joystick = pygame.joystick.Joystick(0) joystick.init() rot = 0 fwd = 1 stf = 2 tlt = 3 rotX, rotY, rotZ = 0.0,0.0,0.0 rotXmatrix = numpy.eye(4, dtype=numpy.float32) rotYmatrix = numpy.eye(4, dtype=numpy.float32) rotZmatrix = numpy.eye(4, dtype=numpy.float32) clock = pygame.time.Clock() init() near = 1.0 far = 50.0 depth = 2.0 while True: clock.tick(30) for event in pygame.event.get(): if event.type == QUIT: return if event.type == KEYUP and event.key == K_ESCAPE: return if event.type == KEYDOWN: if event.key == K_SPACE: n = theUniforms.items['showLines'] theUniforms.items['showLines'] = (n+1)%2 if event.key == K_l: if near < 2.0: near = 19.0 far = 21.0 else: near = 1.0 far = 50.0 if have_joystick: if event.type == pygame.JOYBUTTONUP: autoRotation = not(autoRotation) # Joystick polling: if have_joystick: factor = 1.0/30.0 frame.move(-joy(joystick, fwd)) frame.rotate(numpy.pi * -joy(joystick, rot)) frame.strafe(joy(joystick, stf)) frame.tilt(numpy.pi * joy(joystick, tlt)) theWorld.Update('translationMatrix', frame.translation) theWorld.Update('postRotationMatrix', frame.rotation) if autoRotation: rotX += 0.005 rotY += 0.005 rotZ += 0.005 # Keyboard polling: pressed = pygame.key.get_pressed() # observer movement: amt = 0.2 if pressed[K_DOWN]: frame.elevate(amt) if pressed[K_UP]: frame.elevate(-amt) if pressed[K_LEFT]: frame.strafe(-amt) if pressed[K_RIGHT]: frame.strafe(amt) if pressed[K_PAGEUP]: frame.move(amt) if pressed[K_PAGEDOWN]: frame.move(-amt) theWorld.Update('translationMatrix', frame.translation) theWorld.Update('postRotationMatrix', frame.rotation) # world rotation: if pressed[K_q]: rotZ -= 0.02 if pressed[K_e]: rotZ += 0.02 setRotationZ(rotZmatrix, rotZ) mat = numpy.dot(rotYmatrix, rotZmatrix) mat = numpy.dot(rotXmatrix, mat) theWorld.Update('preRotationMatrix', mat) # near/far manipulation: amt = 0.1 if pressed[K_j]: near += amt if pressed[K_k]: near -= amt if pressed[K_u]: far += amt if pressed[K_i]: far -= amt if pressed[K_o]: near += amt far += amt if pressed[K_p]: near -= amt far -= amt near = max(near, 0.001) #theWorld.Update('projectionMatrix', # projectionMatrix(near, far, near, near)) display() pygame.display.flip()