Ejemplo n.º 1
0
def bump_thing(thing, others, dt):
    velocity_i = thing["velocity"]
    thing["collisions"] = []
    thing["dp"] = [0.0, 0.0, 0.0]
    dp = position_delta(thing, dt)
    thing["dv"] = subtract_arrays_3(thing["velocity"], velocity_i)
    if (((dp[0] == 0.0) and (dp[1] == 0.0)) and (dp[2] == 0.0)):
            return 
    bounds = thing["world_bounds"]
    position = bounds["position"]
    position_f = sum_arrays(position, dp)
    crash_position, hit_thing, hit_normal = crash_things(thing["id"], position, position_f, bounds["size"], bounds["max"], others)
    crash_delta = subtract_arrays_3(crash_position, position)
    if (((crash_delta[0] == 0.0) and (crash_delta[1] == 0.0)) and (crash_delta[2] == 0.0)):
            return 
    if (hit_thing != None):
            collision = {"thing" : hit_thing, "normal" : hit_normal}
            thing["collisions"].append(collision)
            thing["velocity"] = [0.0, 0.0, 0.0]
            thing["dv"] = subtract_arrays_3(thing["velocity"], velocity_i)
    thing["force"] = [0.0, 0.0, 0.0]
    last = sum_arrays(thing["position"], crash_delta)
    thing_set_position(thing, [last[0], last[1], last[2]])
    thing["dp"] = crash_delta
    return 
Ejemplo n.º 2
0
def bump_thing(thing, others, dt):
    velocity_i = thing["velocity"]
    thing["collisions"] = []
    thing["dp"] = [0.0, 0.0, 0.0]
    dp = position_delta(thing, dt)
    thing["dv"] = subtract_arrays_3(thing["velocity"], velocity_i)
    if (((dp[0] == 0.0) and (dp[1] == 0.0)) and (dp[2] == 0.0)):
        return
    bounds = thing["world_bounds"]
    position = bounds["position"]
    position_f = sum_arrays(position, dp)
    crash_position, hit_thing, hit_normal = crash_things(
        thing["id"], position, position_f, bounds["size"], bounds["max"],
        others)
    crash_delta = subtract_arrays_3(crash_position, position)
    if (((crash_delta[0] == 0.0) and (crash_delta[1] == 0.0))
            and (crash_delta[2] == 0.0)):
        return
    if (hit_thing != None):
        collision = {"thing": hit_thing, "normal": hit_normal}
        thing["collisions"].append(collision)
        thing["velocity"] = [0.0, 0.0, 0.0]
        thing["dv"] = subtract_arrays_3(thing["velocity"], velocity_i)
    thing["force"] = [0.0, 0.0, 0.0]
    last = sum_arrays(thing["position"], crash_delta)
    thing_set_position(thing, [last[0], last[1], last[2]])
    thing["dp"] = crash_delta
    return
Ejemplo n.º 3
0
def crash_things(thing_id, position_i, position_f, size, max, things):
    final = []
    hit_thing = {}
    hit_normal = []
    delta = subtract_arrays_3(position_f, position_i)
    delta_inv = array_scaled(delta, -1.0)
    peak = point_farthest(position_i, max, delta)
    e_position, e_size = bounds_cuboids(
        [cuboid_new(position_i, size),
         cuboid_new(position_f, size)])
    extent = cuboid_cached_new(e_position, e_size)
    min_time = 1.0
    hit_thing = None
    for thing in things:
        if (thing["id"] == thing_id):
            continue
        is_hit, thing_min_time, thing_hit_normal = crash_one(
            delta, delta_inv, position_i, size, peak, extent, thing)
        if is_hit:
            if (thing_min_time < min_time):
                min_time = thing_min_time
                hit_thing = thing
                hit_normal = thing_hit_normal
    scale = array_scaled(delta, min_time)
    final = sum_arrays(position_i, scale)
    return final, hit_thing, hit_normal
Ejemplo n.º 4
0
def crash_things(thing_id, position_i, position_f, size, max, things):
    final = []
    hit_thing = {}
    hit_normal = []
    delta = subtract_arrays_3(position_f, position_i)
    delta_inv = array_scaled(delta, -1.0)
    peak = point_farthest(position_i, max, delta)
    e_position, e_size = bounds_cuboids([cuboid_new(position_i, size), cuboid_new(position_f, size)])
    extent = cuboid_cached_new(e_position, e_size)
    min_time = 1.0
    hit_thing = None
    for thing in things:
            if (thing["id"] == thing_id):
                        continue
            is_hit, thing_min_time, thing_hit_normal = crash_one(delta, delta_inv, position_i, size, peak, extent, thing)
            if is_hit:
                        if (thing_min_time < min_time):
                                        min_time = thing_min_time
                                        hit_thing = thing
                                        hit_normal = thing_hit_normal
    scale = array_scaled(delta, min_time)
    final = sum_arrays(position_i, scale)
    return final, hit_thing, hit_normal