Changeset 34
- Timestamp:
- 09/03/08 08:11:52 (10 months ago)
- Files:
-
- 1 modified
-
muckaround/pyode/test.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
muckaround/pyode/test.py
r33 r34 13 13 14 14 world = WorldRenderable() 15 world.set_gravity((0, 0, -10 0))15 world.set_gravity((0, 0, -10)) 16 16 world.add_floor() 17 17 … … 20 20 21 21 def drop_object(): 22 """Drop an object into the scene.""" 23 24 global bodies, counter, objcount 25 26 body = world.add_box(1000, 1.0, 0.2, 0.2) 27 body.setPosition( (random.gauss(0,0.1), random.gauss(0,0.1), 5) ) 22 if random.random() < .5: 23 body = world.add_box(1000, 1.0, 0.2, 0.2) 24 else: 25 body = world.add_sphere(100, random.random() * 0.3 + 0.1) 26 body.setPosition( (random.gauss(-1, 1), random.gauss(-1, 1), 5) ) 28 27 theta = random.uniform(0,2 * math.pi) 29 28 ct = math.cos(theta) … … 33 32 running = True 34 33 a = 1 35 frame_time = 1. / 3034 frame_time = 1. / 60 36 35 37 36 done_steps = 0 … … 39 38 while not win.has_exit: 40 39 41 if random.random() < 0. 1:40 if random.random() < 0.01: 42 41 drop_object() 43 42 … … 48 47 world.think(frame_time) 49 48 done_steps += 1 50 print 'step', random.random()51 49 52 50 win.dispatch_events() … … 54 52 world.render() 55 53 win.flip() 56 print 'render'57 54 58 55 class World: … … 74 71 # Create contact joints 75 72 for c in contacts: 76 c.setBounce(0. 2)73 c.setBounce(0.6) 77 74 c.setMu(5000) 78 75 j = ode.ContactJoint(self.world, self.contact_group, c) … … 85 82 self.floor = ode.GeomPlane(self.space, (0, 0, 1), 0) 86 83 87 def add_sphere(self, pos, mass, rad): 88 pass 89 84 def add_sphere(self, density, rad): 85 body = ode.Body(self.world) 86 mass = ode.Mass() 87 mass.setSphere(density, rad) 88 body.setMass(mass) 89 90 body.shape = "sphere" 91 body.rad = rad 92 93 geom = ode.GeomSphere(self.space, radius=rad) 94 geom.setBody(body) 95 96 self.bodies.append(body) 97 98 return body 90 99 def add_box(self, density, lx, ly, lz): 91 100 body = ode.Body(self.world) … … 160 169 glScalef(sx, sy, sz) 161 170 glutSolidCube(1) 171 172 def draw_sphere(self, body): 173 r = body.rad 174 glScalef(r, r, r) 175 q = gluNewQuadric() 176 gluSphere(q, 1, 8, 5) 162 177 163 178 def draw_body(self, body): … … 176 191 if body.shape == "box": 177 192 self.draw_box(body) 193 if body.shape == "sphere": 194 self.draw_sphere(body) 178 195 glPopMatrix() 179 196