Sections
Timeline
Sub-Sections
Download
Unified Diff
Zip Archive
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

Changeset 34

Show
Ignore:
Timestamp:
09/03/08 08:11:52 (10 months ago)
Author:
gak
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • muckaround/pyode/test.py

    r33 r34  
    1313 
    1414    world = WorldRenderable() 
    15     world.set_gravity((0, 0, -100)) 
     15    world.set_gravity((0, 0, -10)) 
    1616    world.add_floor() 
    1717 
     
    2020 
    2121    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) ) 
    2827        theta = random.uniform(0,2 * math.pi) 
    2928        ct = math.cos(theta) 
     
    3332    running = True 
    3433    a = 1 
    35     frame_time = 1. / 30 
     34    frame_time = 1. / 60 
    3635 
    3736    done_steps = 0 
     
    3938    while not win.has_exit: 
    4039 
    41         if random.random() < 0.1: 
     40        if random.random() < 0.01: 
    4241            drop_object() 
    4342 
     
    4847            world.think(frame_time) 
    4948            done_steps += 1 
    50             print 'step', random.random() 
    5149 
    5250        win.dispatch_events() 
     
    5452        world.render() 
    5553        win.flip() 
    56         print 'render' 
    5754 
    5855class World: 
     
    7471        # Create contact joints 
    7572        for c in contacts: 
    76             c.setBounce(0.2) 
     73            c.setBounce(0.6) 
    7774            c.setMu(5000) 
    7875            j = ode.ContactJoint(self.world, self.contact_group, c) 
     
    8582        self.floor = ode.GeomPlane(self.space, (0, 0, 1), 0) 
    8683 
    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 
    9099    def add_box(self, density, lx, ly, lz): 
    91100        body = ode.Body(self.world) 
     
    160169        glScalef(sx, sy, sz) 
    161170        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) 
    162177 
    163178    def draw_body(self, body): 
     
    176191        if body.shape == "box": 
    177192            self.draw_box(body) 
     193        if body.shape == "sphere": 
     194            self.draw_sphere(body) 
    178195        glPopMatrix() 
    179196