Mercurial > touhou
annotate pytouhou/utils/matrix.pyx @ 524:7f016dfbdfb1
Make vector a struct, allocate it directly on the stack, and thus pass it by copy, which is much less expensive than a python allocation.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 18 Dec 2013 18:15:40 +0100 |
parents | 6e3b3d5d4691 |
children | db28538cd399 |
rev | line source |
---|---|
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
2 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
4 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
8 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
12 ## GNU General Public License for more details. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
13 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
44
diff
changeset
|
14 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
15 from libc.math cimport sin, cos |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
417
diff
changeset
|
16 from libc.stdlib cimport malloc, free |
493
26c082870dcf
Use a cached static float[16] instead of a list for default Matrix data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
17 from libc.string cimport memcpy |
26c082870dcf
Use a cached static float[16] instead of a list for default Matrix data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
18 |
26c082870dcf
Use a cached static float[16] instead of a list for default Matrix data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
19 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
20 cdef Matrix identity |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
21 identity = Matrix(1, 0, 0, 0, |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
22 0, 1, 0, 0, |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
23 0, 0, 1, 0, |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
24 0, 0, 0, 1) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
417
diff
changeset
|
25 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
417
diff
changeset
|
26 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
27 cdef Matrix *new_matrix(Matrix *data) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
28 mat = <Matrix*> malloc(sizeof(Matrix)) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
29 memcpy(mat, data, sizeof(Matrix)) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
30 return mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
31 |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
32 |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
33 cdef Matrix *new_identity() nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
34 return new_matrix(&identity) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
417
diff
changeset
|
35 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
417
diff
changeset
|
36 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
37 cdef void mul(Matrix *mat1, Matrix *mat2) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
38 cdef float *d3 |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
131
diff
changeset
|
39 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
40 out = <Matrix*> malloc(sizeof(Matrix)) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
41 d1 = <float*>mat1 |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
42 d2 = <float*>mat2 |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
43 d3 = <float*>out |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
44 for i in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
45 for j in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
46 d3[4*i+j] = 0 |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
47 for k in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
48 d3[4*i+j] += d1[4*i+k] * d2[4*k+j] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
49 memcpy(mat1, out, sizeof(Matrix)) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
50 free(out) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
131
diff
changeset
|
51 |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
131
diff
changeset
|
52 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
53 cdef void flip(Matrix *mat) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
54 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
55 for i in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
56 data[i] = -data[i] |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
57 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
58 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
59 cdef void scale(Matrix *mat, float x, float y, float z) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
60 cdef float coordinate[3] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
61 |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
62 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
63 coordinate[0] = x |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
64 coordinate[1] = y |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
65 coordinate[2] = z |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
66 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
67 for i in xrange(3): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
68 for j in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
69 data[4*i+j] *= coordinate[i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
70 |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
71 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
72 cdef void scale2d(Matrix *mat, float x, float y) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
73 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
74 for i in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
75 data[ i] *= x |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
76 data[4+i] *= y |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
77 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
78 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
79 cdef void translate(Matrix *mat, float x, float y, float z) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
80 cdef float offset[3], item[3] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
81 |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
82 offset[0] = x |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
83 offset[1] = y |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
84 offset[2] = z |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
85 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
86 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
87 for i in xrange(3): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
88 item[i] = data[12+i] * offset[i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
89 |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
90 for i in xrange(3): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
91 for j in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
92 data[4*i+j] += item[i] |
31 | 93 |
94 | |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
95 cdef void translate2d(Matrix *mat, float x, float y) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
96 translate(mat, x, y, 0) |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
97 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
98 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
99 cdef void rotate_x(Matrix *mat, float angle) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
100 cdef float cos_a, sin_a |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
101 cdef float lines[8] |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
102 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
103 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
104 cos_a = cos(angle) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
105 sin_a = sin(angle) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
106 for i in xrange(8): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
107 lines[i] = data[i+4] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
108 for i in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
109 data[4+i] = cos_a * lines[i] - sin_a * lines[4+i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
110 data[8+i] = sin_a * lines[i] + cos_a * lines[4+i] |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
111 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
112 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
113 cdef void rotate_y(Matrix *mat, float angle) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
114 cdef float cos_a, sin_a |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
115 cdef float lines[8] |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
116 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
117 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
118 cos_a = cos(angle) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
119 sin_a = sin(angle) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
120 for i in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
121 lines[i] = data[i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
122 lines[i+4] = data[i+8] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
123 for i in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
124 data[ i] = cos_a * lines[i] + sin_a * lines[4+i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
125 data[8+i] = -sin_a * lines[i] + cos_a * lines[4+i] |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
126 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
127 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
128 cdef void rotate_z(Matrix *mat, float angle) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
129 cdef float cos_a, sin_a |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
130 cdef float lines[8] |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
131 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
132 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
133 cos_a = cos(angle) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
134 sin_a = sin(angle) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
135 for i in xrange(8): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
136 lines[i] = data[i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
137 for i in xrange(4): |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
138 data[ i] = cos_a * lines[i] - sin_a * lines[4+i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
139 data[4+i] = sin_a * lines[i] + cos_a * lines[4+i] |