Exemplo n.º 1
0
def intersect_ray_bounds_unused(origin, direction, thing, faces, offset):
    hit_thing = {}
    hit_face = {}
    hit_point = []
    hit_point = None
    matrix = matrix_placement(thing["position"], thing["rotates"])
    new_offset = product_matrices(offset, matrix)
    new_position, new_size = cuboid_transformed(new_offset,
                                                thing["bounds"]["position"],
                                                bounds["size"])
    for face in faces:
        hit_point = intersect_ray_cuboid_face(origin, direction,
                                              thing["bounds"]["position"],
                                              thing["bounds"]["size"],
                                              face["axis"], face["sign"])
        if (hit_point != None):
            hit_thing = thing
            hit_face = face
            break
    if (hit_point == None):
        hit_thing = None
        return hit_thing, hit_face, hit_point
    else:
        if (len(thing["cubes"]) == 0.0):
            for child in thing["children"]:
                hit_thing, hit_face, hit_point = intersect_ray_bounds(
                    origin, direction, child, faces)
                if (hit_thing != None):
                    return hit_thing, hit_face, hit_point
            hit_thing = None
            return hit_thing, hit_face, hit_point
        else:
            return hit_thing, hit_face, hit_point
    return hit_thing, hit_face, hit_point
Exemplo n.º 2
0
def intersect_ray_bounds_unused(origin, direction, thing, faces, offset):
    hit_thing = {}
    hit_face = {}
    hit_point = []
    hit_point = None
    matrix = matrix_placement(thing["position"], thing["rotates"])
    new_offset = product_matrices(offset, matrix)
    new_position, new_size = cuboid_transformed(new_offset, thing["bounds"]["position"], bounds["size"])
    for face in faces:
            hit_point = intersect_ray_cuboid_face(origin, direction, thing["bounds"]["position"], thing["bounds"]["size"], face["axis"], face["sign"])
            if (hit_point != None):
                        hit_thing = thing
                        hit_face = face
                        break
    if (hit_point == None):
            hit_thing = None
            return hit_thing, hit_face, hit_point
    else:
            if (len(thing["cubes"]) == 0.0):
                        for child in thing["children"]:
                                        hit_thing, hit_face, hit_point = intersect_ray_bounds(origin, direction, child, faces)
                                        if (hit_thing != None):
                                                            return hit_thing, hit_face, hit_point
                        hit_thing = None
                        return hit_thing, hit_face, hit_point
            else:
                        return hit_thing, hit_face, hit_point
    return hit_thing, hit_face, hit_point
Exemplo n.º 3
0
def thing_set_world_bounds(thing, offset):
    thing["matrix"] = offset
    matrix = matrix_placement(thing["position"], thing["rotates"])
    offset = product_matrices(offset, matrix)
    bounds = thing["bounds"]
    if (bounds != None):
            position, size = cuboid_transformed(offset, bounds["position"], bounds["size"])
            thing["world_bounds"] = cuboid_cached_new(position, size)
            for child in thing["children"]:
                        thing_set_world_bounds(child, offset)
    return 
Exemplo n.º 4
0
def thing_set_world_bounds(thing, offset):
    thing["matrix"] = offset
    matrix = matrix_placement(thing["position"], thing["rotates"])
    offset = product_matrices(offset, matrix)
    bounds = thing["bounds"]
    if (bounds != None):
        position, size = cuboid_transformed(offset, bounds["position"],
                                            bounds["size"])
        thing["world_bounds"] = cuboid_cached_new(position, size)
        for child in thing["children"]:
            thing_set_world_bounds(child, offset)
    return
Exemplo n.º 5
0
def intersect_ray_thing_faces(origin, direction, thing, offset, faces):
    hit_thing = {}
    hit_face = {}
    hit_offset = []
    min_distance = 0.0
    hit_thing = None
    min_distance = 0.0
    matrix = matrix_placement(thing["position"], thing["rotates"])
    new_offset = product_matrices(offset, matrix)
    if (thing["bounds"] == None):
        for child in thing["children"]:
            child_hit_thing, child_hit_face, child_hit_offset, child_min_distance = intersect_ray_thing_faces(
                origin, direction, child, new_offset, faces)
            if (child_hit_thing != None):
                if (hit_thing == None):
                    hit_thing = child_hit_thing
                    hit_face = child_hit_face
                    min_distance = child_min_distance
                    hit_offset = child_hit_offset
                else:
                    if (child_min_distance < min_distance):
                        hit_thing = child_hit_thing
                        hit_face = child_hit_face
                        min_distance = child_min_distance
                        hit_offset = child_hit_offset
    else:
        bounds = thing["bounds"]
        new_position, new_size = cuboid_transformed(new_offset,
                                                    bounds["position"],
                                                    bounds["size"])
        for face in faces:
            intersect_point = intersect_ray_cuboid_face(
                origin, direction, new_position, new_size, face["axis"],
                face["sign"])
            if (intersect_point != None):
                min_distance = magnitude_vector(
                    subtract_arrays(intersect_point, origin))
                hit_thing = thing
                hit_face = face
                hit_offset = new_offset
                return hit_thing, hit_face, hit_offset, min_distance
    return hit_thing, hit_face, hit_offset, min_distance
Exemplo n.º 6
0
def intersect_ray_thing_faces(origin, direction, thing, offset, faces):
    hit_thing = {}
    hit_face = {}
    hit_offset = []
    min_distance = 0.0
    hit_thing = None
    min_distance = 0.0
    matrix = matrix_placement(thing["position"], thing["rotates"])
    new_offset = product_matrices(offset, matrix)
    if (thing["bounds"] == None):
            for child in thing["children"]:
                        child_hit_thing, child_hit_face, child_hit_offset, child_min_distance = intersect_ray_thing_faces(origin, direction, child, new_offset, faces)
                        if (child_hit_thing != None):
                                        if (hit_thing == None):
                                                            hit_thing = child_hit_thing
                                                            hit_face = child_hit_face
                                                            min_distance = child_min_distance
                                                            hit_offset = child_hit_offset
                                        else:
                                                            if (child_min_distance < min_distance):
                                                                                    hit_thing = child_hit_thing
                                                                                    hit_face = child_hit_face
                                                                                    min_distance = child_min_distance
                                                                                    hit_offset = child_hit_offset
    else:
            bounds = thing["bounds"]
            new_position, new_size = cuboid_transformed(new_offset, bounds["position"], bounds["size"])
            for face in faces:
                        intersect_point = intersect_ray_cuboid_face(origin, direction, new_position, new_size, face["axis"], face["sign"])
                        if (intersect_point != None):
                                        min_distance = magnitude_vector(subtract_arrays(intersect_point, origin))
                                        hit_thing = thing
                                        hit_face = face
                                        hit_offset = new_offset
                                        return hit_thing, hit_face, hit_offset, min_distance
    return hit_thing, hit_face, hit_offset, min_distance