Mercurial > touhou
annotate pytouhou/utils/matrix.pyx @ 516:577c3a88fb67
Merge the lists Game.texts and Game.native_texts into the Game.texts dict.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 11 May 2014 20:25:07 +0200 |
parents | 26c082870dcf |
children | 6e3b3d5d4691 |
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 |
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
|
20 cdef float[16] identity |
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
|
21 identity[:] = [1, 0, 0, 0, |
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
|
22 0, 1, 0, 0, |
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
|
23 0, 0, 1, 0, |
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
|
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 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
123
diff
changeset
|
27 cdef class Matrix: |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
28 def __init__(self, data=None): |
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
|
29 if data is not None: |
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
|
30 for i in xrange(16): |
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
|
31 self.data[i] = data[i] |
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
|
32 else: |
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
|
33 memcpy(self.data, identity, 16 * sizeof(float)) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
417
diff
changeset
|
34 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
417
diff
changeset
|
35 |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
36 def __mul__(Matrix self, Matrix other): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
37 cdef float *d1, *d2, *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
|
38 |
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 out = Matrix() |
411
2428296cccab
Remove indirect access to Matrix values.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
40 d1 = self.data |
2428296cccab
Remove indirect access to Matrix values.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
41 d2 = other.data |
2428296cccab
Remove indirect access to Matrix values.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
42 d3 = out.data |
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
|
43 for i in xrange(4): |
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
|
44 for j in xrange(4): |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
45 d3[4*i+j] = 0 |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
46 for k in xrange(4): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
47 d3[4*i+j] += d1[4*i+k] * d2[4*k+j] |
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
|
48 return out |
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
|
49 |
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 |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
51 cdef void flip(self) nogil: |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
52 cdef float *data |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
53 |
123 | 54 data = self.data |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
55 for i in xrange(4): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
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 |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
59 cdef void scale(self, float x, float y, float z) nogil: |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
60 cdef float *data, coordinate[3] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
61 |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
62 data = self.data |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
63 coordinate[0] = x |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
64 coordinate[1] = y |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
65 coordinate[2] = z |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
66 |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
67 for i in xrange(3): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
68 for j in xrange(4): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
69 data[4*i+j] *= coordinate[i] |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
70 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
71 |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
72 cdef void scale2d(self, float x, float y) nogil: |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
73 cdef float *data |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
74 |
123 | 75 data = self.data |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
76 for i in xrange(4): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
77 data[ i] *= x |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
78 data[4+i] *= y |
31 | 79 |
80 | |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
81 cdef void translate(self, float x, float y, float z) nogil: |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
82 cdef float *data, coordinate[3], item[3] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
83 |
123 | 84 data = self.data |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
85 coordinate[0] = x |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
86 coordinate[1] = y |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
87 coordinate[2] = z |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
88 for i in xrange(3): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
89 item[i] = data[12+i] * coordinate[i] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
90 |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
91 for i in xrange(3): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
92 for j in xrange(4): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
93 data[4*i+j] += item[i] |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
94 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
95 |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
96 cdef void rotate_x(self, float angle) nogil: |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
97 cdef float cos_a, sin_a |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
98 cdef float lines[8], *data |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
99 |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
100 data = self.data |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
101 cos_a = cos(angle) |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
102 sin_a = sin(angle) |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
103 for i in xrange(8): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
104 lines[i] = data[i+4] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
105 for i in xrange(4): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
106 data[4+i] = cos_a * lines[i] - sin_a * lines[4+i] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
107 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
|
108 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
109 |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
110 cdef void rotate_y(self, float angle) nogil: |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
111 cdef float cos_a, sin_a |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
112 cdef float lines[8], *data |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
113 |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
114 data = self.data |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
115 cos_a = cos(angle) |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
116 sin_a = sin(angle) |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
117 for i in xrange(4): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
118 lines[i] = data[i] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
119 lines[i+4] = data[i+8] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
120 for i in xrange(4): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
121 data[ i] = cos_a * lines[i] + sin_a * lines[4+i] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
122 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
|
123 |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
124 |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
125 cdef void rotate_z(self, float angle) nogil: |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
126 cdef float cos_a, sin_a |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
127 cdef float lines[8], *data |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
128 |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
129 data = self.data |
28
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
130 cos_a = cos(angle) |
f405b947624d
Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents:
4
diff
changeset
|
131 sin_a = sin(angle) |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
132 for i in xrange(8): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
133 lines[i] = data[i] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
134 for i in xrange(4): |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
135 data[ i] = cos_a * lines[i] - sin_a * lines[4+i] |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
136 data[4+i] = sin_a * lines[i] + cos_a * lines[4+i] |