コード例 #1
0
ファイル: Screen.py プロジェクト: Elgirhath/Game-engine
def should_face_be_backwards_culled(face):
    return vector3.dot(
        vector3.subtract(
            face.vertex[0],
            Local_to_world_space(camera.main_camera.transform.position,
                                 camera.main_camera.parent.transform)),
        face.normal) > 0
コード例 #2
0
def _sort_faces_():
    #TODO: FIX THIS
    switch = True
    while switch:
        switch = False
        for i in range(0, len(all_faces) - 1):
            if vector3.dot(all_faces[i].normal,
                           Screen.main_camera.global_transform.forward) < 0:
                vc = all_faces[i].normal
            else:
                vc = vector3.scale(all_faces[i].normal, -1)
            above = True
            below = True
            for vertex in all_faces[i + 1].vertex:
                if Geometry.Axis_view(
                        vc, vector3.subtract(vertex,
                                             all_faces[i].vertex[0])) >= 0:
                    below = False
                else:
                    above = False
            if not above and not below:
                if vector3.dot(
                        all_faces[i + 1].normal,
                        Screen.main_camera.global_transform.forward) < 0:
                    vc = all_faces[i + 1].normal
                else:
                    vc = vector3.scale(all_faces[i + 1].normal, -1)
                above = True
                below = True
                for vertex in all_faces[i].vertex:
                    if Geometry.Axis_view(
                            vc,
                            vector3.subtract(vertex,
                                             all_faces[i + 1].vertex[0])) >= 0:
                        below = False
                    else:
                        above = False
                if above:
                    all_faces[i], all_faces[i + 1] = all_faces[i +
                                                               1], all_faces[i]
                    switch = True
            elif below:
                all_faces[i], all_faces[i + 1] = all_faces[i + 1], all_faces[i]
                switch = True
コード例 #3
0
ファイル: Geometry.py プロジェクト: Elgirhath/Game-engine
    def get_signed_distance_to_point(self, point):
        """
            Returns:
                0 if point lays on the plane
                distance from the plane if point is on positive side of plane
                Negative distance if point is on negative side of plane
        """
        if self.factors[2] != 0.0:
            plane_point = (0.0, 0.0, -self.factors[3] / self.factors[2])
        elif self.factors[1] != 0.0:
            plane_point = (0.0, -self.factors[3] / self.factors[1], 0.0)
        else:
            plane_point = (-self.factors[3] / self.factors[0], 0.0, 0.0)

        points_diff = vector3.subtract(point, plane_point)
        return vector3.dot(points_diff, self.normal())
コード例 #4
0
def convert_to_different_space(vector, component_vector1, component_vector2,
                               component_vector3):
    """
        Returns scalars of the new R3 basis describing vector
    """
    x = vector3.dot(vector, component_vector1) / vector3.dot(
        component_vector1, component_vector1)
    y = vector3.dot(vector, component_vector2) / vector3.dot(
        component_vector2, component_vector2)
    z = vector3.dot(vector, component_vector3) / vector3.dot(
        component_vector3, component_vector3)

    return (x, y, z)
コード例 #5
0
ファイル: Collider.py プロジェクト: Elgirhath/Game-engine
def SAT_collision(collider1, collider2):
    points1 = list(collider1.points)
    center1 = vector3.add(
        collider1.parent.transform.position,
        Quaternion.rotate_vector(collider1.center,
                                 collider1.parent.transform.rotation))
    for i in range(0, len(points1)):
        points1[i] = Quaternion.rotate_vector(
            points1[i], collider1.parent.transform.rotation)
        points1[i] = vector3.add(points1[i], center1)

    points2 = list(collider2.points)
    center2 = vector3.add(
        collider2.parent.transform.position,
        Quaternion.rotate_vector(collider2.center,
                                 collider2.parent.transform.rotation))
    for i in range(0, len(points2)):
        points2[i] = Quaternion.rotate_vector(
            points2[i], collider2.parent.transform.rotation)
        points2[i] = vector3.add(points2[i], center2)

    for normal in collider1.normals:
        rotated_normal = Quaternion.rotate_vector(
            Quaternion.rotate_vector(normal, collider1.rotation),
            collider1.parent.transform.rotation)
        min1 = None
        max1 = None
        for point in points1:
            axis_view = vector3.dot(rotated_normal, point)
            if min1 == None or min1 > axis_view:
                min1 = axis_view
            if max1 == None or max1 < axis_view:
                max1 = axis_view

        min2 = None
        max2 = None
        for point in points2:
            axis_view = vector3.dot(rotated_normal, point)
            if min2 == None or min2 > axis_view:
                min2 = axis_view
            if max2 == None or max2 < axis_view:
                max2 = axis_view

        if min1 > max2 or max1 < min2:
            return False

    for normal in collider2.normals:
        rotated_normal = Quaternion.rotate_vector(
            Quaternion.rotate_vector(normal, collider2.rotation),
            collider2.parent.transform.rotation)
        min1 = None
        max1 = None
        for point in points1:
            axis_view = vector3.dot(rotated_normal, point)
            if min1 == None or min1 > axis_view:
                min1 = axis_view
            if max1 == None or max1 < axis_view:
                max1 = axis_view

        min2 = None
        max2 = None
        for point in points2:
            axis_view = vector3.dot(rotated_normal, point)
            if min2 == None or min2 > axis_view:
                min2 = axis_view
            if max2 == None or max2 < axis_view:
                max2 = axis_view

        if max1 < min2 or min1 > max2:
            return False
    return True
コード例 #6
0
ファイル: Geometry.py プロジェクト: Elgirhath/Game-engine
 def Switch_normal_by_vector(self, vector):
     if vector3.dot(self.normal(), vector) < 0:
         self.Invert_normal()
コード例 #7
0
ファイル: Geometry.py プロジェクト: Elgirhath/Game-engine
def Axis_view(point, axis):
    k = vector3.dot(point, axis) / vector3.magnitude(point)**2
    return k
コード例 #8
0
def is_point_behind_camera_clip(point, camera):
    tr = camera.transform.get_global_transform()
    clip_position = vector3.add(tr.position,
                                vector3.scale(tr.forward, camera.clip_min))
    return vector3.dot(vector3.subtract(point, clip_position),
                       tr.forward) < 0.0