Exemple #1
0
def trback(endpos, d, theta, dims,exd = 0,fail = None, timestep = 1000, drawscreen = None):
    tnew = PhysicsTable(dims)
    v = (d+exd)/timestep * 1000
    tbch = int(1000*d/v)
    #print tbch, d, v
    vx = v * math.cos(theta)
    vy = v * math.sin(theta)
    b = tnew.addBall(endpos,(vx,vy))
    for i in range(timestep):
        tnew.physicsstep()
        if i == tbch: bn = b.bounces
        if fail and tnew.fails(fail): return None,None,None,None
        if drawscreen and (i % 20) == 0:
            drawscreen.blit(tnew.draw(),(0,0))
            pg.display.flip()
    pos = (b.x,b.y)
    # NOTE: Need to fix periodicity of pi here...
    tht = (math.atan(b.v[1]/b.v[0]) + math.pi)
    if b.v[0] < 0: tht += math.pi
    tht = tht % (2*math.pi)
    #bn = b.bounces
    runupsteps = tnew.sincecol
    runupd = v * runupsteps
    if drawscreen: time.sleep(2)
    return pos,tht,bn,runupd
def trback(endpos, d, theta, dims, timestep = 1000, drawscreen = None):
    tnew = PhysicsTable(dims)
    v = d/timestep * 1000
    vx = v * math.cos(theta)
    vy = v * math.sin(theta)
    b = tnew.addBall(endpos,(vx,vy))
    for i in range(timestep):
        tnew.physicsstep()
        if drawscreen and (timestep % 50) == 0:
            drawscreen.blit(tnew.draw(),(0,0))
            pg.display.flip()
    pos = (b.x,b.y)
    tht = (math.atan(b.v[1]/b.v[0]) + math.pi) % (2*math.pi)
    bn = b.bounces
    if drawscreen: time.sleep(2)
    return pos,tht,bn
Exemple #3
0
def trback(endpos, d, theta, dims,exd = 0,fail = None, timestep = 1000, drawscreen = None):
    tnew = PhysicsTable(dims, active = True)
    v = (d+exd)/timestep * 1000
    tbch = int(1000*d/v)
    #print tbch, d, v
    vx = v * math.cos(theta)
    vy = v * math.sin(theta)
    b = tnew.addBall(endpos,(vx,vy))
    for i in range(timestep):
        tnew.physicsstep()
        if i == tbch:
            bn = b.bounces
            tnew.deactivate()
            occpos = (b.x,b.y)
            occv = b.v
            tnew.sincecol = 0
        if fail and tnew.fails(fail): return None,None,None,None
        if drawscreen and (i % 20) == 0:
            drawscreen.blit(tnew.draw(),(0,0))
            pg.display.flip()
    pos = (b.x,b.y)
    # Find angle of velocity
    tht = (math.atan(b.v[1]/b.v[0]) + math.pi)
    if b.v[0] < 0: tht += math.pi
    tht = tht % (2*math.pi)
    # And for the velocity at occlusion
    occtht = (math.atan(occv[1]/occv[0]) + math.pi)
    if occv[0] < 0: occtht += math.pi
    occtht = occtht % (2*math.pi)

    # Find the number of bounces prior to occlusion
    postb = b.bounces - bn
    
    runupsteps = tnew.sincecol
    #print exd, runupsteps, (v*runupsteps/1000)
    runupd = exd - (v * runupsteps)/1000
    if drawscreen: time.sleep(2)
    return pos,tht,bn,runupd, occpos, occtht, postb