| 1 | #!/usr/bin/env python |
|---|
| 2 | import soy |
|---|
| 3 | import blocks |
|---|
| 4 | from time import sleep |
|---|
| 5 | |
|---|
| 6 | sce = soy.scenes.Scene() |
|---|
| 7 | cam = soy.bodies.Camera(sce) |
|---|
| 8 | cam.position = (0.0, 0.0, 2.0) |
|---|
| 9 | lig = soy.bodies.Light(sce) |
|---|
| 10 | lig.position = (-10.0,10.0,2.0) |
|---|
| 11 | |
|---|
| 12 | lava = soy.transports.File('media/lava.soy')['gimp'] |
|---|
| 13 | lava.animate=(.125,0,0) |
|---|
| 14 | dot3 = soy.transports.File('media/fieldstone-dot3.soy')['gimp'] |
|---|
| 15 | dot3.animate=(.25,0,0) |
|---|
| 16 | colors = { |
|---|
| 17 | 'Marble' : (soy.materials.Textured(colormap=lava, bumpmap=dot3), |
|---|
| 18 | soy.materials.Material(ambient=soy.colors.black, |
|---|
| 19 | diffuse=soy.colors.Color('#222'), |
|---|
| 20 | specular=soy.colors.Color('#222'), |
|---|
| 21 | shininess=5.0), |
|---|
| 22 | (0,0,0)), |
|---|
| 23 | } |
|---|
| 24 | bks = blocks.blocks(sce, colors) |
|---|
| 25 | |
|---|
| 26 | fps = soy.textures.Print() |
|---|
| 27 | |
|---|
| 28 | scr = soy.Screen() |
|---|
| 29 | win = soy.Window(scr, 'TexBlocks', background=soy.colors.cyan) |
|---|
| 30 | pro = soy.widgets.Projector(win, camera=cam) |
|---|
| 31 | can = soy.widgets.Canvas(win, texture=fps) |
|---|
| 32 | |
|---|
| 33 | def wireframeToggle() : |
|---|
| 34 | if cam.wireframe : |
|---|
| 35 | cam.wireframe = False |
|---|
| 36 | else : |
|---|
| 37 | cam.wireframe = True |
|---|
| 38 | |
|---|
| 39 | def fullscreenToggle() : |
|---|
| 40 | if scr.fullscreen : |
|---|
| 41 | scr.fullscreen = None |
|---|
| 42 | else : |
|---|
| 43 | scr.fullscreen = win |
|---|
| 44 | |
|---|
| 45 | def moreLight() : |
|---|
| 46 | lig.diffuse = lig.diffuse + 1.0 |
|---|
| 47 | print lig.diffuse |
|---|
| 48 | |
|---|
| 49 | def lessLight() : |
|---|
| 50 | lig.diffuse = lig.diffuse - 1.0 |
|---|
| 51 | print lig.diffuse |
|---|
| 52 | |
|---|
| 53 | key = soy.controllers.Keyboard(win) |
|---|
| 54 | marble = bks['Marble'] |
|---|
| 55 | key['Q'] = soy.actions.Force(marble, soy.atoms.Vector((-100, 0, 0))) |
|---|
| 56 | key['R'] = soy.actions.Force(marble, soy.atoms.Vector(( 0, 100, 0))) |
|---|
| 57 | key['S'] = soy.actions.Force(marble, soy.atoms.Vector(( 100, 0, 0))) |
|---|
| 58 | key['T'] = soy.actions.Force(marble, soy.atoms.Vector(( 0, -100, 0))) |
|---|
| 59 | key['U'] = soy.actions.Force(marble, soy.atoms.Vector(( 0, 0, -100))) |
|---|
| 60 | key['V'] = soy.actions.Force(marble, soy.atoms.Vector(( 0, 0, 100))) |
|---|
| 61 | key['q'] = soy.actions.Quit() |
|---|
| 62 | key[ 1 ] = soy.actions.Quit() # 9 = esc key |
|---|
| 63 | key['f'] = fullscreenToggle |
|---|
| 64 | key['w'] = wireframeToggle |
|---|
| 65 | key['['] = lessLight |
|---|
| 66 | key[']'] = moreLight |
|---|
| 67 | wcn = soy.controllers.Window(win) |
|---|
| 68 | wcn['close'] = soy.actions.Quit() |
|---|
| 69 | |
|---|
| 70 | if __name__ == '__main__' : |
|---|
| 71 | while True: |
|---|
| 72 | sleep(.1) |
|---|
| 73 | fps.text = '%sfps' % str(int(cam.fps)).zfill(4) |
|---|
| 74 | for bk in bks : |
|---|
| 75 | p = bks[bk].position |
|---|
| 76 | v = bks[bk].velocity |
|---|
| 77 | v = [v[0], v[1], v[2]] |
|---|
| 78 | if abs(p[0]) > 5 and ((p[0]>0 and v[0]>0) or (p[0]<0 and v[0]< 0)) : |
|---|
| 79 | v[0] = v[0]*-1 |
|---|
| 80 | if abs(p[1]) > 5 and ((p[1]>0 and v[1]>0) or (p[1]<0 and v[1]< 0)) : |
|---|
| 81 | v[1] = v[1]*-1 |
|---|
| 82 | if abs(p[2]) > 5 and ((p[2]>0 and v[2]>0) or (p[2]<0 and v[2]< 0)) : |
|---|
| 83 | v[2] = v[2]*-1 |
|---|
| 84 | bks[bk].velocity = v |
|---|