Mercurial > touhou
annotate pytouhou/utils/matrix.pyx @ 617:a6af3ff86612
Change all “void except *” function into “bint except True”, to prevent PyErr_Occurred() from being called at each call.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 29 Mar 2015 00:08:20 +0100 |
parents | 560b45a7d014 |
children | e5361b74b9ad |
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 |
613
560b45a7d014
Don’t uselessly malloc() a matrix for multiply, the stack is here for that!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
590
diff
changeset
|
39 cdef Matrix 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
|
40 |
523
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 |
613
560b45a7d014
Don’t uselessly malloc() a matrix for multiply, the stack is here for that!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
590
diff
changeset
|
43 d3 = <float*>&out |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
44 for i in range(4): |
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
45 for j in range(4): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
46 d3[4*i+j] = 0 |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
47 for k in range(4): |
523
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] |
613
560b45a7d014
Don’t uselessly malloc() a matrix for multiply, the stack is here for that!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
590
diff
changeset
|
49 memcpy(mat1, &out, sizeof(Matrix)) |
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
|
50 |
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 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
52 cdef void flip(Matrix *mat) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
53 data = <float*>mat |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
54 for i in range(4): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
55 data[i] = -data[i] |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
56 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
57 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
58 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
|
59 cdef float coordinate[3] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
60 |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
61 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
62 coordinate[0] = x |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
63 coordinate[1] = y |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
64 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
|
65 |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
66 for i in range(3): |
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
67 for j in range(4): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
68 data[4*i+j] *= coordinate[i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
69 |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
70 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
71 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
|
72 data = <float*>mat |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
73 for i in range(4): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
74 data[ i] *= x |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
75 data[4+i] *= y |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
76 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
77 |
527
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
523
diff
changeset
|
78 cdef void translate(Matrix *mat, float[3] offset) nogil: |
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
523
diff
changeset
|
79 cdef float item[3] |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
80 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
81 data = <float*>mat |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
82 for i in range(3): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
83 item[i] = data[12+i] * offset[i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
84 |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
85 for i in range(3): |
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
86 for j in range(4): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
87 data[4*i+j] += item[i] |
31 | 88 |
89 | |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
90 cdef void translate2d(Matrix *mat, float x, float y) nogil: |
527
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
523
diff
changeset
|
91 cdef float[3] offset |
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
523
diff
changeset
|
92 |
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
523
diff
changeset
|
93 offset[0] = x |
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
523
diff
changeset
|
94 offset[1] = y |
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
523
diff
changeset
|
95 offset[2] = 0 |
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
523
diff
changeset
|
96 |
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
523
diff
changeset
|
97 translate(mat, offset) |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
98 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
99 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
100 cdef void rotate_x(Matrix *mat, float angle) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
101 cdef float cos_a, sin_a |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
102 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
|
103 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
104 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
105 cos_a = cos(angle) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
106 sin_a = sin(angle) |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
107 for i in range(8): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
108 lines[i] = data[i+4] |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
109 for i in range(4): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
110 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
|
111 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
|
112 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
113 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
114 cdef void rotate_y(Matrix *mat, float angle) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
115 cdef float cos_a, sin_a |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
116 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
|
117 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
118 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
119 cos_a = cos(angle) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
120 sin_a = sin(angle) |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
121 for i in range(4): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
122 lines[i] = data[i] |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
123 lines[i+4] = data[i+8] |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
124 for i in range(4): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
125 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
|
126 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
|
127 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
128 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
129 cdef void rotate_z(Matrix *mat, float angle) nogil: |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
130 cdef float cos_a, sin_a |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
131 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
|
132 |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
133 data = <float*>mat |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
134 cos_a = cos(angle) |
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
135 sin_a = sin(angle) |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
136 for i in range(8): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
137 lines[i] = data[i] |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
138 for i in range(4): |
523
6e3b3d5d4691
Make matrix a struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
493
diff
changeset
|
139 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
|
140 data[4+i] = sin_a * lines[i] + cos_a * lines[4+i] |