comparison 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
comparison
equal deleted inserted replaced
422:52829ebe2561 423:d8630c086926
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 from libc.math cimport sin, cos 15 from libc.math cimport sin, cos
16 from ctypes import c_float 16 from ctypes import c_float
17 from libc.stdlib cimport malloc, free
18
19
20 cdef float* matrix_to_floats(Matrix self):
21 for i in xrange(4):
22 for j in xrange(4):
23 self.c_data[i*4+j] = self.data[i][j]
24 return self.c_data
17 25
18 26
19 cdef class Matrix: 27 cdef class Matrix:
28 def __cinit__(self):
29 self.c_data = <float*>malloc(16 * sizeof(float))
30
31
20 def __init__(self, data=None): 32 def __init__(self, data=None):
21 self.data = data or [[1, 0, 0, 0], 33 self.data = data or [[1, 0, 0, 0],
22 [0, 1, 0, 0], 34 [0, 1, 0, 0],
23 [0, 0, 1, 0], 35 [0, 0, 1, 0],
24 [0, 0, 0, 1]] 36 [0, 0, 0, 1]]
37
38
39 def __dealloc__(self):
40 free(self.c_data)
25 41
26 42
27 def __mul__(self, Matrix other): 43 def __mul__(self, Matrix other):
28 out = Matrix() 44 out = Matrix()
29 d1 = self.data 45 d1 = self.data