Add import to pyworlds to avoid errors.
[pyworlds.git] / tests / traveling-camera-1.py
blob2aa4b12606fd9c89a2c8f01296361f34f82d3973
1 #!/usr/bin/python
2 import sys,os
3 sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '..', 'src')))
5 import pyworlds.worlds as worlds
6 from pyworlds.worlds import sdlconst,soya
7 worlds.init()
9 head = worlds.Body("sword")
11 new_springfactor = springfactor = 16
13 pieces = {}
14 previous = head
15 for i in range(100):
16 pieces[i] = worlds.FollowBody("sword",previous)
17 pieces[i].set_springfactor(new_springfactor)
18 previous = pieces[i]
20 #worlds.camera = soya.TravelingCamera(worlds.scene)
22 #traveling = soya.ThirdPersonTraveling(pieces[5])
23 #traveling.distance = 35.0
24 #traveling.offset_y = 20.0
25 #traveling.offset_y2 = 10.0
26 worlds.camera.y=40
27 #worlds.camera.add_traveling(traveling)
28 #worlds.camera.speed = 0.05
29 vel = 0
31 def mainloop():
32 global head, new_springfactor, springfactor, vel
34 if sdlconst.K_UP in worlds.KEY:
35 head.velocity.z=-vel*2
36 #vel *= 1.001
37 vel += .05
38 else:
39 head.velocity.z/=1.1
40 vel = 2
41 if sdlconst.K_DOWN in worlds.KEY:
42 head.velocity.z=0.2
43 if sdlconst.K_LEFT in worlds.KEY: head.rotation[1]+=vel+1
44 if sdlconst.K_RIGHT in worlds.KEY: head.rotation[1]-=vel+1
46 head.rotation[1]/=1.05
48 if sdlconst.K_1 in worlds.KEY: new_springfactor=1
49 if sdlconst.K_2 in worlds.KEY: new_springfactor=2
50 if sdlconst.K_3 in worlds.KEY: new_springfactor=4
51 if sdlconst.K_4 in worlds.KEY: new_springfactor=8
52 if sdlconst.K_5 in worlds.KEY: new_springfactor=16
53 if sdlconst.K_6 in worlds.KEY: new_springfactor=32
54 if sdlconst.K_7 in worlds.KEY: new_springfactor=64
55 if sdlconst.K_8 in worlds.KEY: new_springfactor=80
56 if sdlconst.K_0 in worlds.KEY: new_springfactor=0
58 if new_springfactor != springfactor:
59 global pieces
60 for i in pieces:
61 pieces[i].set_springfactor(new_springfactor)
62 springfactor = new_springfactor
64 def renderloop(proportion):
65 global head
66 worlds.look_at_elastic(worlds.camera, head, sqrt_from=360, factor=0.1)
67 pass
73 worlds.begin_loop(mainloop, renderloop)