示例#1
0
 def get_vertices(self):
     all_points = []
     i = 0
     for p1 in self.planes:
         i += 1
         p1_points = []
         j = 0
         for p2 in self.planes:
             j += 1
             # if i > j:
             #    continue
             k = 0
             for p3 in self.planes:
                 k += 1
                 if j > k:
                     continue
                 point = p1.intersect_point(p2, p3)
                 if point is not None and self.point_in_brush(point):
                     # print(i,j,k)
                     p1_points.append(point)
         if len(p1_points) < 3:
             continue
         com = center_of_mass(p1_points)
         vals = []
         tangent_vec = norm_vec3(p1_points[0] - com)
         quad_1 = []
         quad_2 = []
         quad_3 = []
         quad_4 = []
         for i in range(0, len(p1_points)):
             point = norm_vec3(p1_points[i] - com)
             values = (p1.point_dist(np.cross(tangent_vec, point) + com),
                       tangent_vec.dot(point))
             if values[0] >= 0:
                 if values[1] >= 0:
                     quad_1.append(i)
                 else:
                     quad_2.append(i)
             else:
                 if values[1] < 0:
                     quad_3.append(i)
                 else:
                     quad_4.append(i)
             vals.append(values)
         quad_1.sort(key=lambda x: (-1
                                    if vals[x][0] < 0 else 1) * vals[x][1],
                     reverse=True)
         quad_2.sort(key=lambda x: (-1
                                    if vals[x][0] < 0 else 1) * vals[x][1],
                     reverse=True)
         quad_3.sort(key=lambda x: (-1
                                    if vals[x][0] < 0 else 1) * vals[x][1],
                     reverse=True)
         quad_4.sort(key=lambda x: (-1
                                    if vals[x][0] < 0 else 1) * vals[x][1],
                     reverse=True)
         all_points.append(
             [p1_points[p] for p in quad_1 + quad_2 + quad_3 + quad_4])
     return all_points
示例#2
0
def look_at(position, target, up):
    zaxis = vertex_math.norm_vec3(target - position)
    xaxis = vertex_math.norm_vec3(
        vertex_math.cross_array(vertex_math.norm_vec3(up), zaxis))
    yaxis = vertex_math.cross_array(zaxis, xaxis)  # quick maths
    rotation = create_rotation_matrix_euler(xaxis, yaxis, zaxis)
    translation = create_translation_matrix(position * -1)
    #rotation[3] = [-np.dot(xaxis, position), -np.dot(zaxis, position), -np.dot(yaxis, position), 1]
    return translation * rotation
示例#3
0
def trace(start_point: np.ndarray, end_point: np.ndarray, aabb: AABB):
    og_aabb = aabb
    aabb = aabb.translate_new_aabb(start_point - aabb.center)
    diff = end_point - start_point
    direction = norm_vec3(diff)
    end_aabb = aabb.translate_new_aabb(diff)
    intersected_brushes = []
    for brush in world:
        if brush.point_in_brush(end_aabb.min_extent):
            intersected_brushes.append(brush)
            continue
        if brush.point_in_brush(end_aabb.max_extent):
            intersected_brushes.append(brush)
            continue
        for point in end_aabb.other_verts:
            if brush.point_in_brush(point):
                if brush not in intersected_brushes:
                    intersected_brushes.append(brush)
    new_aabbs = []
    for brush in intersected_brushes:
        for plane in brush.planes:
            t = end_aabb.sit_against_plane(plane)
            if t is not None:
                new_aabbs.append((t, plane, brush))
    min_move = 1E9
    min_aabb = None
    min_plane = None
    min_brush = None
    for bb, plane, brush in new_aabbs:
        center_move = bb.aabb_center_distance(aabb)
        if min_move > center_move:
            min_move = center_move
            min_aabb = bb
            min_plane = plane
            min_brush = brush
    if min_aabb is None:
        return TraceResult(False, end_aabb.center, 1.0, None, None, None)
    else:
        r_e = magnitude_vec3(min_aabb.center - start_point)
        w_e = magnitude_vec3(end_point - start_point)
        if r_e / w_e > 1:
            print("WTF! %f %f %f" % (r_e / w_e, r_e, w_e))
            print(start_point)
            print(end_point)
            print(start_point + (r_e / w_e) * (end_point - start_point))
        return TraceResult(True, min_aabb.center, (r_e / w_e), min_plane, min_brush, min_plane.normal)
示例#4
0
 def plane_from_points(v0: np.ndarray, v1: np.ndarray,
                       v2: np.ndarray) -> "Plane":
     n = norm_vec3(np.cross((v1 - v0), (v2 - v0)))
     return Plane(v0, n)
示例#5
0
 def __init__(self, point: np.ndarray, normal: np.ndarray):
     self.point = point
     self.normal = norm_vec3(normal)
示例#6
0
 def plane_from_points_quake_style(points) -> "Plane":
     n = norm_vec3(np.cross((points[2] - points[0]), (points[1] - points[0])))
     return Plane(points[0], n)