comparison pytouhou/utils/matrix.pyx @ 370:74471afbac37

Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 27 Jul 2012 18:43:48 +0200
parents fab7ad2f0d8b
children 2428296cccab
comparison
equal deleted inserted replaced
369:f305cdd6f6c5 370:74471afbac37
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 17
17 18
18 cdef class Matrix: 19 cdef class Matrix:
19 def __init__(Matrix self, data=None): 20 def __init__(Matrix self, data=None):
20 self.data = data or [[0] * 4 for i in xrange(4)] 21 self.data = data or [[1, 0, 0, 0],
22 [0, 1, 0, 0],
23 [0, 0, 1, 0],
24 [0, 0, 0, 1]]
25
26
27 def __getitem__(Matrix self, key):
28 return self.data[key]
29
30
31 def __mul__(Matrix self, Matrix other):
32 out = Matrix()
33 for i in xrange(4):
34 for j in xrange(4):
35 out[i][j] = sum(self[i][k] * other[k][j] for k in xrange(4))
36 return out
37
38
39 def get_c_data(Matrix self):
40 data = sum(self.data, [])
41 return (c_float * 16)(*data)
21 42
22 43
23 cpdef flip(Matrix self): 44 cpdef flip(Matrix self):
24 data = self.data 45 data = self.data
25 a, b, c, d = data[0] 46 a, b, c, d = data[0]