Example #1
0
    def __init__(self):
        self.my_type = "mesh"
        self.points = [
            Vector3(-10, -10, -10),
            Vector3(10, -10, -10),
            Vector3(10, 10, -10),
            Vector3(-10, 10, -10),
            Vector3(-10, -10, 10),
            Vector3(10, -10, 10),
            Vector3(10, 10, 10),
            Vector3(-10, 10, 10),
        ]

        self.scaling_factor = 1

        self.connecting_sequence = [
            (0, 4),
            (1, 5),
            (2, 6),
            (3, 7),
            (0, 1),
            (1, 2),
            (2, 3),
            (3, 0),
            (4, 5),
            (5, 6),
            (6, 7),
            (7, 4),
        ]
Example #2
0
 def setScalingFactor(self, factor):
     self.scaling_factor = factor
     for i in range(len(self.points)):
         p = self.points[i]
         self.points[i] = Vector3(p.x * self.scaling_factor,
                                  p.y * self.scaling_factor,
                                  p.z * self.scaling_factor)
Example #3
0
def rotate_y(point: Vector3, angle: float) -> Vector3:
    rotation_x = [
        [math.cos(angle), 0, math.sin(angle)],
        [0, 1, 0],
        [-math.sin(angle), 0, math.cos(angle)]
    ]
    m = matmult(rotation_x, [[point.x], [point.y], [point.z]])
    return Vector3(m[0][0], m[1][0], m[2][0])
Example #4
0
    def readFromObjFile(self, filename):
        self.points = []
        self.connecting_sequence = []
        f = open(filename, "r")
        content = f.readlines()
        f.close()
        content = [x.strip() for x in content]
        content = [x.split() for x in content]
        for i in content:
            if i[0] == "v":
                self.points.append(Vector3(i[1], i[2], i[3]))
            if i[0] == "f":
                p = []
                for j in i:
                    p.append(j.split("/"))

                for k in range(1, len(p)):
                    if k == len(p) - 1:
                        self.connecting_sequence.append(
                            (int(p[k][0]) - 1, int(p[1][0]) - 1))
                    else:
                        self.connecting_sequence.append(
                            (int(p[k][0]) - 1, int(p[k + 1][0]) - 1))
        self.setScalingFactor(self.scaling_factor)
Example #5
0
from clge.GameMath import Matrix
from clge import AltScreen
from clge.Behaviour.Behaviour import Behaviour

w = 100
h = w / 2

scr = AltScreen(int(w), int(h), True)
scr.auto_clear_objects_list_setter(True)
scr.change_coordinate_system(CoordinateSystems.MIDDLE_MIDDLE)
scr.set_timeout(.05)

angle = 0

points = [
    Vector3(-10, -10, -10),
    Vector3(10, -10, -10),
    Vector3(10, 10, -10),
    Vector3(-10, 10, -10),
    Vector3(-10, -10, 10),
    Vector3(10, -10, 10),
    Vector3(10, 10, 10),
    Vector3(-10, 10, 10),
]


def update():
    global angle
    projected: list[Vector2] = []
    for i in points:
        r = Matrix.rotate_x(i, angle)