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
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
def crash_one(delta, delta_inv, position_i, size, peak, extent, thing): is_hit = False min_time = 0.0 hit_normal = [] is_hit = False min_time = 1.0 bounds = thing["world_bounds"] if (len(thing["children"]) > 0.0): if (is_overlap_cuboids(extent["position"], extent["size"], extent["max"], bounds["position"], bounds["size"], bounds["max"]) == False): return is_hit, min_time, hit_normal for child in thing["children"]: child_is_hit, crash_time, child_hit_normal = crash_one( delta, delta_inv, position_i, size, peak, extent, child) if child_is_hit: if (crash_time < min_time): min_time = crash_time is_hit = True hit_normal = child_hit_normal else: is_hit, crash_time, hit_normal = crash_bounds(position_i, size, peak, delta, bounds) if is_hit: if (crash_time < min_time): min_time = crash_time return is_hit, min_time, hit_normal
def overlap_bounds_thing(position, size, max, thing): hit_thing = {} hit_thing = None thing_bounds = thing["world_bounds"] overlap = is_overlap_cuboids(position, size, max, thing_bounds["position"], thing_bounds["size"], thing_bounds["max"]) if (overlap == False): return hit_thing if (len(thing["children"]) > 0.0): for child in thing["children"]: child_hit_thing = overlap_bounds_thing(position, size, max, child) if (child_hit_thing != None): hit_thing = child_hit_thing return hit_thing else: hit_thing = thing return hit_thing
def touching_two(one_position, one_size, one_max, two): yes = False normals = [] two_bounds = two["world_bounds"] axis, sign = face_overlap(one_position, one_size, one_max, two_bounds["position"], two_bounds["size"], two_bounds["max"]) if (len(two["children"]) > 0.0): if (axis == None): if (is_overlap_cuboids(one_position, one_size, one_max, two_bounds["position"], two_bounds["size"], two_bounds["max"]) == False): return yes, normals for child in two["children"]: child_yes, child_normals = touching_two(one_position, one_size, one_max, child) if child_yes: yes = True normals.extend(child_normals) else: if (axis != None): yes = True normals.append(vector_axis_sign(axis, sign)) return yes, normals
def crash_one(delta, delta_inv, position_i, size, peak, extent, thing): is_hit = False min_time = 0.0 hit_normal = [] is_hit = False min_time = 1.0 bounds = thing["world_bounds"] if (len(thing["children"]) > 0.0): if (is_overlap_cuboids(extent["position"], extent["size"], extent["max"], bounds["position"], bounds["size"], bounds["max"]) == False): return is_hit, min_time, hit_normal for child in thing["children"]: child_is_hit, crash_time, child_hit_normal = crash_one(delta, delta_inv, position_i, size, peak, extent, child) if child_is_hit: if (crash_time < min_time): min_time = crash_time is_hit = True hit_normal = child_hit_normal else: is_hit, crash_time, hit_normal = crash_bounds(position_i, size, peak, delta, bounds) if is_hit: if (crash_time < min_time): min_time = crash_time return is_hit, min_time, hit_normal
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