Testing rebasing Mat4 as a list subclass
@@ -50,25 +50,7 @@ def create_perspective(left, right, bottom, top, znear, zfar, fov=60):
0, 0, qn, 0))
-def rotate(matrix, angle=0, x=0, y=0, z=0):
- pass
-
-
-def scale(matrix, value):
- """Scale a matrix."""
- temp = list(matrix)
- temp[0] *= value
- temp[5] *= value
- temp[10] *= value
- return Mat4(temp)
-
-
-def translate(matrix, x=0, y=0, z=0):
- """Translate a matrix along x, y, and z axis."""
- return Mat4((*matrix[:12], matrix[12] + x, matrix[13] + y, matrix[14] + z, matrix[15]))
-
-
-class Mat4(tuple):
+class Mat4(list):
"""A 4x4 Matrix
`Mat4` is a simple immutable 4x4 Matrix, with a few operators.
@@ -79,12 +61,14 @@ class Mat4(tuple):
to OpenGL.
"""
- def __new__(cls, values=None):
+ __slots__ = []
+
+ def __init__(self, values=None):
"""Create a 4x4 Matrix
A Matrix can be created with list or tuple of 16 values.
If nothing is provided, an "identity Matrix" will be created
- (1.0 on the main diagonal). Matrix objects are immutable.
+ (1.0 on the main diagonal).
:Parameters:
`values` : tuple of float or int
@@ -95,7 +79,47 @@ class Mat4(tuple):
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0)
- return super().__new__(Mat4, values)
+ super().__init__(values)
+
+ def translate(self, x=0, y=0, z=0):
+ """Translate the Matrix along x, y, or z axis."""
+ self[12] += x
+ self[13] += y
+ self[14] += z
+
+ def scale(self, value):
+ """Scale the Matrix."""
+ self[0] *= value
+ self[5] *= value
+ self[10] *= value
+
+ def rotate(self, angle=0, x=0, y=0, z=0):
+ raise NotImplementedError
+ r = _math.radians(angle)
+ rc = _math.cos(r)
+ rs = _math.sin(r)
+
+ a = 0
+ b = 0
+ c = 0
+ d = 0
+
+ e = 0
+ f = 0
+ g = 0
+ h = 0
+
+ i = 0
+ j = 0
+ k = 0
+ l = 0
+
+ m = 0
+ n = 0
+ o = 0
+ p = 0
+
+ self[:] = a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p
def __add__(self, other):
assert isinstance(other, Mat4), "Only addition with Mat4 types is supported"
