예제 #1
0
def some_other():
    vectors = vectors_component(delta)
    unit_vectors = vectors_component_unit(delta)
    for i in range(int(len(vectors))):
            vector = vectors[int(i)]
            unit_vector = unit_vectors[int(i)]
            vector_inv = array_scaled(vector, -1.0)
            child_start = point_farthest(position, max, vector_inv)
            crash_time = time_denorm_point_plane(peak, child_start, vector)
            if ((crash_time >= 0.0) and (crash_time < 1.0)):
                        child_end = sum_arrays(child_start, unit_vector)
                        end_time = time_denorm_point_plane(peak, child_end, vector)
                        if (crash_time == end_time):
                                        print json.dumps(["Error crash_bounds crash_time same as end_time", child_start, child_end], cls=SyrupEncoder)
                        elif (crash_time > end_time):
                                        print json.dumps(["Error end_time greater than crash_time", crash_time, end_time], cls=SyrupEncoder)
                        else:
                                        test_time = ((crash_time + end_time) / 2.0)
                                        test_position = sum_arrays(position_i, array_scaled(delta, test_time))
                                        test_max = sum_arrays_3(test_position, size)
                                        if is_overlap_cuboids(test_position, size, test_max, dest_point, dest_size, bounds["max"]):
                                                            crash_time = crash_time
                                                            is_hit = True
                                                            hit_normal = unit_vector
                                                            break
    return 
예제 #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 
예제 #3
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
예제 #4
0
def position_delta(thing, dt):
    dp = []
    force = thing["force"]
    accel = array_scaled(force, (1.0 / thing["mass"]))
    accel = array_scaled(thing["force"], (1.0 / thing["mass"]))
    velocity_i = thing["velocity"]
    velocity_f = sum_arrays(array_scaled(accel, dt), velocity_i)
    velocity_avg = array_scaled(sum_arrays(velocity_f, velocity_i), (1.0 / 2.0))
    thing["velocity"] = velocity_f
    dp = array_scaled(velocity_avg, dt)
    return dp
예제 #5
0
def position_delta(thing, dt):
    dp = []
    force = thing["force"]
    accel = array_scaled(force, (1.0 / thing["mass"]))
    accel = array_scaled(thing["force"], (1.0 / thing["mass"]))
    velocity_i = thing["velocity"]
    velocity_f = sum_arrays(array_scaled(accel, dt), velocity_i)
    velocity_avg = array_scaled(sum_arrays(velocity_f, velocity_i),
                                (1.0 / 2.0))
    thing["velocity"] = velocity_f
    dp = array_scaled(velocity_avg, dt)
    return dp
예제 #6
0
def crash_bounds(position_i, size, peak, delta, bounds):
    is_hit = False
    crash_time = 0.0
    hit_normal = []
    dest_point = bounds["position"]
    dest_size = bounds["size"]
    for i in range(3):
            magnitude = delta[int(i)]
            if (magnitude == 0.0):
                        continue
            sign = 0.0
            if (magnitude > 0.0):
                        sign = 1.0
            b_peak = farthest_axis_sign(dest_point, bounds["max"], i, (1.0 - sign))
            crash_time = ((b_peak - peak[int(i)]) / magnitude)
            if ((crash_time >= 0.0) and (crash_time < 1.0)):
                        if (magnitude > 0.0):
                                        test = (b_peak + 0.5)
                        else:
                                        test = (b_peak - 0.5)
                        test_time = ((test - peak[int(i)]) / magnitude)
                        test_position = sum_arrays(position_i, array_scaled(delta, test_time))
                        test_max = sum_arrays_3(test_position, size)
                        if is_overlap_cuboids(test_position, size, test_max, dest_point, dest_size, bounds["max"]):
                                        crash_time = crash_time
                                        is_hit = True
                                        hit_normal = vector_axis_sign(i, sign)
                                        break
    return is_hit, crash_time, hit_normal
예제 #7
0
def crash_bounds(position_i, size, peak, delta, bounds):
    is_hit = False
    crash_time = 0.0
    hit_normal = []
    dest_point = bounds["position"]
    dest_size = bounds["size"]
    for i in range(3):
        magnitude = delta[int(i)]
        if (magnitude == 0.0):
            continue
        sign = 0.0
        if (magnitude > 0.0):
            sign = 1.0
        b_peak = farthest_axis_sign(dest_point, bounds["max"], i, (1.0 - sign))
        crash_time = ((b_peak - peak[int(i)]) / magnitude)
        if ((crash_time >= 0.0) and (crash_time < 1.0)):
            if (magnitude > 0.0):
                test = (b_peak + 0.5)
            else:
                test = (b_peak - 0.5)
            test_time = ((test - peak[int(i)]) / magnitude)
            test_position = sum_arrays(position_i,
                                       array_scaled(delta, test_time))
            test_max = sum_arrays_3(test_position, size)
            if is_overlap_cuboids(test_position, size, test_max, dest_point,
                                  dest_size, bounds["max"]):
                crash_time = crash_time
                is_hit = True
                hit_normal = vector_axis_sign(i, sign)
                break
    return is_hit, crash_time, hit_normal
예제 #8
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
예제 #9
0
def some_other():
    vectors = vectors_component(delta)
    unit_vectors = vectors_component_unit(delta)
    for i in range(int(len(vectors))):
        vector = vectors[int(i)]
        unit_vector = unit_vectors[int(i)]
        vector_inv = array_scaled(vector, -1.0)
        child_start = point_farthest(position, max, vector_inv)
        crash_time = time_denorm_point_plane(peak, child_start, vector)
        if ((crash_time >= 0.0) and (crash_time < 1.0)):
            child_end = sum_arrays(child_start, unit_vector)
            end_time = time_denorm_point_plane(peak, child_end, vector)
            if (crash_time == end_time):
                print json.dumps([
                    "Error crash_bounds crash_time same as end_time",
                    child_start, child_end
                ],
                                 cls=SyrupEncoder)
            elif (crash_time > end_time):
                print json.dumps([
                    "Error end_time greater than crash_time", crash_time,
                    end_time
                ],
                                 cls=SyrupEncoder)
            else:
                test_time = ((crash_time + end_time) / 2.0)
                test_position = sum_arrays(position_i,
                                           array_scaled(delta, test_time))
                test_max = sum_arrays_3(test_position, size)
                if is_overlap_cuboids(test_position, size, test_max,
                                      dest_point, dest_size, bounds["max"]):
                    crash_time = crash_time
                    is_hit = True
                    hit_normal = unit_vector
                    break
    return
예제 #10
0
def update_world_matrices():
    #print '_update_world_matrices 1'
    state = get_state()
    camera = state["camera"]
    placement = camera["placement"]
    position = placement["position"]
    orientation = placement["orientation"]
    front = orientation["front"]
    up = orientation_up(orientation)
    # OpenGL matrices are column major, so transpose it.
    projection_matrix = np.array(perspective_make(camera["fovy"], camera_aspect(camera), camera["near"] , camera["far"]), 'f')
    # OpenGL matrices are column major, so transpose it.
    modelview_matrix = np.array(look_at_make(position, sum_arrays(position, front), up), 'f')
    #print 'repositioning finished: {}\n {}'.format(self.projection_matrix, self.modelview_matrix)
    return modelview_matrix, projection_matrix
예제 #11
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