root / trunk / pysoy / examples / AnimBlock.py

Revision 1350, 2.6 kB (checked in by ArcRiley, 4 months ago)

Tickets #898 #915 :

  • added docs to soy.actions.Action .Callback & .Force
  • changed soy.actions.Force to take a Vector as second argument
  • updated examples to new Force API
  • added Id keyword to Locomotive and Rotate classes
  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2import soy
3import blocks
4from time import sleep
5
6sce = soy.scenes.Scene()
7cam = soy.bodies.Camera(sce)
8cam.position = (0.0, 0.0, 2.0)
9lig = soy.bodies.Light(sce)
10lig.position = (-10.0,10.0,2.0)
11
12lava = soy.transports.File('media/lava.soy')['gimp']
13lava.animate=(.125,0,0)
14dot3 = soy.transports.File('media/fieldstone-dot3.soy')['gimp']
15dot3.animate=(.25,0,0)
16colors = {
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}
24bks = blocks.blocks(sce, colors)
25
26fps = soy.textures.Print()
27
28scr = soy.Screen()
29win = soy.Window(scr, 'TexBlocks', background=soy.colors.cyan)
30pro = soy.widgets.Projector(win, camera=cam)
31can = soy.widgets.Canvas(win, texture=fps)
32
33def wireframeToggle() :
34  if cam.wireframe :
35    cam.wireframe = False
36  else :
37    cam.wireframe = True
38
39def fullscreenToggle() :
40  if scr.fullscreen :
41    scr.fullscreen = None
42  else :
43    scr.fullscreen = win
44
45def moreLight() :
46  lig.diffuse = lig.diffuse + 1.0
47  print lig.diffuse 
48
49def lessLight() :
50  lig.diffuse = lig.diffuse - 1.0
51  print lig.diffuse 
52
53key = soy.controllers.Keyboard(win)
54marble = bks['Marble']
55key['Q'] = soy.actions.Force(marble, soy.atoms.Vector((-100,    0,    0)))
56key['R'] = soy.actions.Force(marble, soy.atoms.Vector((   0,  100,    0)))
57key['S'] = soy.actions.Force(marble, soy.atoms.Vector(( 100,    0,    0)))
58key['T'] = soy.actions.Force(marble, soy.atoms.Vector((   0, -100,    0)))
59key['U'] = soy.actions.Force(marble, soy.atoms.Vector((   0,    0, -100)))
60key['V'] = soy.actions.Force(marble, soy.atoms.Vector((   0,    0,  100)))
61key['q'] = soy.actions.Quit()
62key[ 1 ] = soy.actions.Quit() # 9 = esc key
63key['f'] = fullscreenToggle
64key['w'] = wireframeToggle
65key['['] = lessLight
66key[']'] = moreLight
67wcn = soy.controllers.Window(win)
68wcn['close'] = soy.actions.Quit()
69
70if __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
Note: See TracBrowser for help on using the browser.