diff pytouhou/utils/matrix.pyx @ 423:d8630c086926

Replace Pyglet with our own Cython OpenGL wrapper.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 16 Jul 2013 21:07:15 +0200
parents efae61ad6efe
children f4d76d3d6f2a
line wrap: on
line diff
--- a/pytouhou/utils/matrix.pyx
+++ b/pytouhou/utils/matrix.pyx
@@ -14,9 +14,21 @@
 
 from libc.math cimport sin, cos
 from ctypes import c_float
+from libc.stdlib cimport malloc, free
+
+
+cdef float* matrix_to_floats(Matrix self):
+    for i in xrange(4):
+        for j in xrange(4):
+            self.c_data[i*4+j] = self.data[i][j]
+    return self.c_data
 
 
 cdef class Matrix:
+    def __cinit__(self):
+        self.c_data = <float*>malloc(16 * sizeof(float))
+
+
     def __init__(self, data=None):
         self.data = data or [[1, 0, 0, 0],
                              [0, 1, 0, 0],
@@ -24,6 +36,10 @@ cdef class Matrix:
                              [0, 0, 0, 1]]
 
 
+    def __dealloc__(self):
+        free(self.c_data)
+
+
     def __mul__(self, Matrix other):
         out = Matrix()
         d1 = self.data