Example #1
0
def substep_tree():
    particle_id = 0
    while particle_id < particle_table_len[None]:
        acceleration = get_tree_gravity_at(particle_pos[particle_id])
        particle_vel[particle_id] += acceleration * dt
        # well... seems our tree inserter will break if particle out-of-bound:
        particle_vel[particle_id] = tl.boundReflect(particle_pos[particle_id],
                                                    particle_vel[particle_id],
                                                    0, 1)
        particle_id = particle_id + 1
    for i in range(particle_table_len[None]):
        particle_pos[i] += particle_vel[i] * dt
Example #2
0
def substep():
    for i in x:
        x[i] += v[i] * dt
        u[i] = v[i]
        for j in range(N):
            if i == j: continue
            r = x[i] - x[j]
            if r.norm_sqr() <= (radius * 2)**2 and r.dot(v[i] - v[j]) < 0:
                u[i], _ = tl.momentumExchange(u[i], v[j], r.normalized(), 1.0,
                                              1.0, 0.9)
    for i in x:
        v[i] = u[i]
        v[i].z -= gravity * dt
        v[i] = tl.boundReflect(x[i], v[i], radius - bound, bound - radius,
                               0.87, 0.92)
Example #3
0
 def on_advance(self):
     for i in self.pos:
         acc = ts.vec(0.0, -1.0)
         if any(self.iKeyDirection):  # ASWD?
             acc = self.iKeyDirection
         if any(self.iMouseButton):
             dir = ts.normalize(self.iMouse - self.pos[i]) * 2
             if self.iMouseButton[0]:  # LMB pressed?
                 acc += dir
             if self.iMouseButton[1]:  # RMB pressed?
                 acc -= dir
         self.vel[i] += acc * self.dt
     for i in self.pos:
         self.vel[i] = ts.boundReflect(self.pos[i], self.vel[i], 0, 1, 0.8)
     for i in self.pos:
         self.pos[i] += self.vel[i] * self.dt