root / trunk / pysoy / examples / TexBlocks.py

Revision 1351, 2.5 kB (checked in by ArcRiley, 4 months ago)

Tickets #916 and #927 :

  • renamed soy.actions.Rotate → soy.actions.Torque
  • more soy.atoms and soy.actions documentation
  • soy.atoms.Axis now inherits soy.atoms.Vector as a rotational vector
  • soy.actions.Torque now uses soy.atoms.Axis
  • TexBlocks? example now uses cursor keys to change rotation
  • 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
12mrbl = soy.transports.File('media/marble.soy')['gimp']
13dot3 = soy.transports.File('media/fieldstone-dot3.soy')['gimp']
14colors = {
15  'Marble' : (soy.materials.Textured(colormap=mrbl, bumpmap=dot3),
16              soy.materials.Material(ambient=soy.colors.black,
17                                     diffuse=soy.colors.Color('#222'),
18                                     specular=soy.colors.Color('#222'),
19                                     shininess=5.0),
20              (0,0,0)),
21}
22bks = blocks.blocks(sce, colors)
23
24fps = soy.textures.Print()
25
26scr = soy.Screen()
27win = soy.Window(scr, 'TexBlocks', background=soy.colors.cyan)
28pro = soy.widgets.Projector(win, camera=cam)
29can = soy.widgets.Canvas(win, texture=fps)
30
31def wireframeToggle() :
32  if cam.wireframe :
33    cam.wireframe = False
34  else :
35    cam.wireframe = True
36
37def fullscreenToggle() :
38  if scr.fullscreen :
39    scr.fullscreen = None
40  else :
41    scr.fullscreen = win
42
43def moreLight() :
44  lig.diffuse = lig.diffuse + 1.0
45  print lig.diffuse 
46
47def lessLight() :
48  lig.diffuse = lig.diffuse - 1.0
49  print lig.diffuse 
50
51key = soy.controllers.Keyboard(win)
52marble = bks['Marble']
53key['Q'] = soy.actions.Torque(marble, soy.atoms.Axis((-100,    0,    0)))
54key['R'] = soy.actions.Torque(marble, soy.atoms.Axis((   0,  100,    0)))
55key['S'] = soy.actions.Torque(marble, soy.atoms.Axis(( 100,    0,    0)))
56key['T'] = soy.actions.Torque(marble, soy.atoms.Axis((   0, -100,    0)))
57key['U'] = soy.actions.Torque(marble, soy.atoms.Axis((   0,    0, -100)))
58key['V'] = soy.actions.Torque(marble, soy.atoms.Axis((   0,    0,  100)))
59key['q'] = soy.actions.Quit()
60key[ 1 ] = soy.actions.Quit() # 9 = esc key
61key['f'] = fullscreenToggle
62key['w'] = wireframeToggle
63key['['] = lessLight
64key[']'] = moreLight
65wcn = soy.controllers.Window(win)
66wcn['close'] = soy.actions.Quit()
67
68if __name__ == '__main__' :
69  while True:
70    sleep(.1)
71    fps.text = '%sfps' % str(int(cam.fps)).zfill(4)
72    for bk in bks :
73      p = bks[bk].position
74      v = bks[bk].velocity
75      v = [v[0], v[1], v[2]]
76      if abs(p[0]) > 5 and ((p[0]>0 and v[0]>0) or (p[0]<0 and v[0]< 0)) : 
77        v[0] = v[0]*-1
78      if abs(p[1]) > 5 and ((p[1]>0 and v[1]>0) or (p[1]<0 and v[1]< 0)) : 
79        v[1] = v[1]*-1
80      if abs(p[2]) > 5 and ((p[2]>0 and v[2]>0) or (p[2]<0 and v[2]< 0)) : 
81        v[2] = v[2]*-1
82      bks[bk].velocity = v
Note: See TracBrowser for help on using the browser.