Ejemplo n.º 1
0
    def __init__(self, renderer):
        NEAR = renderer.camera.near_plane
        FAR = renderer.camera.far_plane
        RIGHT = math.tan(renderer.camera.h_fov / 2)
        LEFT = -RIGHT
        TOP = math.tan(renderer.camera.v_fov / 2)
        BOTTOM = -TOP

        self.m00 = 2 / (RIGHT - LEFT)
        self.m11 = 2 / (TOP - BOTTOM)
        self.m22 = (FAR + NEAR) / (FAR - NEAR)
        self.m32 = -2 * NEAR * FAR / (FAR - NEAR)
        self.ProjectionMatrix = Matrix4x4(self.m00, 0, 0, 0, 0, self.m11, 0, 0,
                                          0, 0, self.m22, self.m32, 0, 0, 1, 0)

        self.HW, self.HH = renderer.H_WIDTH, renderer.H_HEIGHT
        self.ScreenMatrix = Matrix4x4(self.HW, 0, 0, self.HW, 0, -self.HH, 0,
                                      self.HH, 0, 0, 1, 0, 0, 0, 0, 1)
Ejemplo n.º 2
0
 def getScaleMatrix(self):
     return Matrix4x4.scale(self.scale.x, self.scale.y, self.scale.z)
Ejemplo n.º 3
0
 def getRotationMatrix(self):
     rotate_x = Matrix4x4.rotate_x(self.rotation.x)
     rotate_y = Matrix4x4.rotate_y(self.rotation.y)
     rotate_z = Matrix4x4.rotate_z(self.rotation.z)
     return rotate_z @ rotate_y @ rotate_x
Ejemplo n.º 4
0
 def getTranslationMatrix(self):
     return Matrix4x4.translate(self.position.x, self.position.y,
                                self.position.z)
Ejemplo n.º 5
0
 def camera_pitch(self, angle):
     rotate = Matrix4x4.rotate_y(angle)
     self.forward = rotate @ self.forward
     self.right = rotate @ self.right
     self.up = rotate @ self.up
Ejemplo n.º 6
0
 def camera_yaw(self, angle):
     rotate = Matrix4x4.rotate_x(angle)
     self.forward = rotate @ self.forward
     self.right = rotate @ self.right
     self.up = rotate @ self.up
Ejemplo n.º 7
0
 def rotate_matrix(self):
     fx, fy, fz = self.forward.coords()
     rx, ry, rz = self.right.coords()
     ux, uy, uz = self.up.coords()
     return Matrix4x4(rx, ry, rz, 0, ux, uy, uz, 0, fx, fy, fz, 0, 0, 0, 0,
                      1)
Ejemplo n.º 8
0
 def translate_matrix(self):
     x, y, z = self.position.coords()
     return Matrix4x4(1, 0, 0, -x, 0, 1, 0, -y, 0, 0, 1, -z, 0, 1, 0, 1)