# Path: spyce/vector.py
# class Mat4:
#     def __init__(self, v=None):
#         if v is None:
#             self.v = [
#                 [1, 0, 0, 0],
#                 [0, 1, 0, 0],
#                 [0, 0, 1, 0],
#                 [0, 0, 0, 1]
#             ]
#         else:
#             self.v = v
# 
#     def __sub__(A, B):
#         return Mat4([x - y for a, b in zip(A, B) for x, y in zip(a, b)])
# 
#     def __abs__(A):
#         """Maximum metric (see Chebyshev distance)"""
#         return max(abs(a) for a in A)
# 
#     def transpose(self):
#         return Mat4(list(zip(*self.v)))
# 
#     def __matmul__(self, other):
#         if isinstance(other, Mat4):  # matrix-matrix multiplication
#             m = other.transpose()
#             return Mat4([m @ row for row in self.v])
#         else:  # matrix-vector multiplication
#             return [sum(a * b for a, b in zip(row, other)) for row in self.v]
# 
#     def row_major(self):
#         return [v for row in self.v for v in row]
# 
#     def column_major(self):
#         return [v for col in zip(*self.v) for v in col]
# 
#     @classmethod
#     def translate(cls, x, y, z):
#         """Rotation matrix of given angle (radians) around axis (x,y,z)"""
#         return cls([
#             [1, 0, 0, x],
#             [0, 1, 0, y],
#             [0, 0, 1, z],
#             [0, 0, 0, 1],
#         ])
# 
#     @classmethod
#     def scale(cls, x, y, z):
#         """Rotation matrix of given angle (radians) around axis (x,y,z)"""
#         return cls([
#             [x, 0, 0, 0],
#             [0, y, 0, 0],
#             [0, 0, z, 0],
#             [0, 0, 0, 1],
#         ])
# 
#     @classmethod
#     def rotate(cls, angle, x, y, z):
#         """Rotation matrix of given angle (radians) around axis (x,y,z)"""
#         s = math.sin(angle)
#         c = math.cos(angle)
#         d = math.sqrt(x*x + y*y + z*z)
#         x, y, z = x/d, y/d, z/d
#         return cls([
#             [x*x*(1-c)+c,   x*y*(1-c)-z*s, x*z*(1-c)+y*s, 0],
#             [y*x*(1-c)+z*s, y*y*(1-c)+c,   y*z*(1-c)-x*s, 0],
#             [z*x*(1-c)-y*s, z*y*(1-c)+x*s, z*z*(1-c)+c,   0],
#             [0, 0, 0, 1],
#         ])
# 
#     @classmethod
#     def frustrum(cls, left, right, bottom, top, near, far):
#         A = (right + left) / (right - left)
#         B = (top + bottom) / (top - bottom)
#         C = - (far + near) / (far - near)
#         D = - (2*far * near) / (far - near)
#         return cls([
#             [2 * near / (right - left), 0, A, 0],
#             [0, 2 * near / (top - bottom), B, 0],
#             [0, 0, C, D],
#             [0, 0, -1, 0],
#         ])
# 
#     @classmethod
#     def ortho(cls, left, right, bottom, top, near, far):
#         tx = - (right + left) / (right - left)
#         ty = - (top + bottom) / (top - bottom)
#         tz = - (far + near) / (far - near)
#         return cls([
#             [2 / (right - left), 0, 0, tx],
#             [0, 2 / (top - bottom), 0, ty],
#             [0, 0, -2 / (far - near), tz],
#             [0, 0, 0, 1],
#         ])


import sys
import math
import spyce.human
import gspyce.textures
import gspyce.skybox
import gspyce.picking
import gspyce.terminal
import gspyce.mesh
        import spyce.load
from spyce.vector import Mat4
from gspyce.graphics import *

        # textures
        gspyce.textures.init()
        texture_directory = self.system._texture_directory
        for body in self.bodies:
            filename = "%s.jpg" % body.name
            body.texture = gspyce.textures.load(texture_directory, filename)

    @classmethod
    def from_cli_args(cls):
        """Load the system given in command-line arguments"""

        try:
            name = sys.argv[1]
        except IndexError:
            name = 'Kerbin'

        try:
            body = spyce.load.from_name(name)
        except KeyError:
            print("Unknwon body '%s'" % name, file=sys.stderr)
            sys.exit(1)

        return cls(body)

    def draw_body(self, body):
        """Draw a CelestialBody"""

        transform = (
            self.modelview_matrix @

# Path: spyce/vector.py
# class Mat4:
#     def __init__(self, v=None):
#         if v is None:
#             self.v = [
#                 [1, 0, 0, 0],
#                 [0, 1, 0, 0],
#                 [0, 0, 1, 0],
#                 [0, 0, 0, 1]
#             ]
#         else:
#             self.v = v
# 
#     def __sub__(A, B):
#         return Mat4([x - y for a, b in zip(A, B) for x, y in zip(a, b)])
# 
#     def __abs__(A):
#         """Maximum metric (see Chebyshev distance)"""
#         return max(abs(a) for a in A)
# 
#     def transpose(self):
#         return Mat4(list(zip(*self.v)))
# 
#     def __matmul__(self, other):
#         if isinstance(other, Mat4):  # matrix-matrix multiplication
#             m = other.transpose()
#             return Mat4([m @ row for row in self.v])
#         else:  # matrix-vector multiplication
#             return [sum(a * b for a, b in zip(row, other)) for row in self.v]
# 
#     def row_major(self):
#         return [v for row in self.v for v in row]
# 
#     def column_major(self):
#         return [v for col in zip(*self.v) for v in col]
# 
#     @classmethod
#     def translate(cls, x, y, z):
#         """Rotation matrix of given angle (radians) around axis (x,y,z)"""
#         return cls([
#             [1, 0, 0, x],
#             [0, 1, 0, y],
#             [0, 0, 1, z],
#             [0, 0, 0, 1],
#         ])
# 
#     @classmethod
#     def scale(cls, x, y, z):
#         """Rotation matrix of given angle (radians) around axis (x,y,z)"""
#         return cls([
#             [x, 0, 0, 0],
#             [0, y, 0, 0],
#             [0, 0, z, 0],
#             [0, 0, 0, 1],
#         ])
# 
#     @classmethod
#     def rotate(cls, angle, x, y, z):
#         """Rotation matrix of given angle (radians) around axis (x,y,z)"""
#         s = math.sin(angle)
#         c = math.cos(angle)
#         d = math.sqrt(x*x + y*y + z*z)
#         x, y, z = x/d, y/d, z/d
#         return cls([
#             [x*x*(1-c)+c,   x*y*(1-c)-z*s, x*z*(1-c)+y*s, 0],
#             [y*x*(1-c)+z*s, y*y*(1-c)+c,   y*z*(1-c)-x*s, 0],
#             [z*x*(1-c)-y*s, z*y*(1-c)+x*s, z*z*(1-c)+c,   0],
#             [0, 0, 0, 1],
#         ])
# 
#     @classmethod
#     def frustrum(cls, left, right, bottom, top, near, far):
#         A = (right + left) / (right - left)
#         B = (top + bottom) / (top - bottom)
#         C = - (far + near) / (far - near)
#         D = - (2*far * near) / (far - near)
#         return cls([
#             [2 * near / (right - left), 0, A, 0],
#             [0, 2 * near / (top - bottom), B, 0],
#             [0, 0, C, D],
#             [0, 0, -1, 0],
#         ])
# 
#     @classmethod
#     def ortho(cls, left, right, bottom, top, near, far):
#         tx = - (right + left) / (right - left)
#         ty = - (top + bottom) / (top - bottom)
#         tz = - (far + near) / (far - near)
#         return cls([
#             [2 / (right - left), 0, 0, tx],
#             [0, 2 / (top - bottom), 0, ty],
#             [0, 0, -2 / (far - near), tz],
#             [0, 0, 0, 1],
#         ])


# Path: gspyce/system.py
import sys
import math
import spyce.human
import gspyce.textures
import gspyce.skybox
import gspyce.picking
import gspyce.terminal
import gspyce.mesh
        import spyce.load
from spyce.vector import Mat4
from gspyce.graphics import *


        # textures
        gspyce.textures.init()
        texture_directory = self.system._texture_directory
        for body in self.bodies:
            filename = "%s.jpg" % body.name
            body.texture = gspyce.textures.load(texture_directory, filename)

    @classmethod
    def from_cli_args(cls):
        """Load the system given in command-line arguments"""

        try:
            name = sys.argv[1]
        except IndexError:
            name = 'Kerbin'

        try:
            body = spyce.load.from_name(name)
        except KeyError:
            print("Unknwon body '%s'" % name, file=sys.stderr)
            sys.exit(1)

        return cls(body)

    def draw_body(self, body):
        """Draw a CelestialBody"""

        transform = (
            self.modelview_matrix @

            Mat4.translate(*body._relative_position)