Mercurial > touhou
comparison pytouhou/utils/matrix.pyx @ 493:26c082870dcf
Use a cached static float[16] instead of a list for default Matrix data.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 05 Oct 2013 22:00:53 +0200 |
parents | 878273a984c4 |
children | 6e3b3d5d4691 |
comparison
equal
deleted
inserted
replaced
492:887de1309491 | 493:26c082870dcf |
---|---|
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 libc.stdlib cimport malloc, free | 16 from libc.stdlib cimport malloc, free |
17 from libc.string cimport memcpy | |
18 | |
19 | |
20 cdef float[16] identity | |
21 identity[:] = [1, 0, 0, 0, | |
22 0, 1, 0, 0, | |
23 0, 0, 1, 0, | |
24 0, 0, 0, 1] | |
17 | 25 |
18 | 26 |
19 cdef class Matrix: | 27 cdef class Matrix: |
20 def __init__(self, data=None): | 28 def __init__(self, data=None): |
21 if data is None: | 29 if data is not None: |
22 data = [1, 0, 0, 0, | 30 for i in xrange(16): |
23 0, 1, 0, 0, | 31 self.data[i] = data[i] |
24 0, 0, 1, 0, | 32 else: |
25 0, 0, 0, 1] | 33 memcpy(self.data, identity, 16 * sizeof(float)) |
26 for i in xrange(4): | |
27 for j in xrange(4): | |
28 self.data[i*4+j] = data[4*i+j] | |
29 | 34 |
30 | 35 |
31 def __mul__(Matrix self, Matrix other): | 36 def __mul__(Matrix self, Matrix other): |
32 cdef float *d1, *d2, *d3 | 37 cdef float *d1, *d2, *d3 |
33 | 38 |