annotate pytouhou/utils/matrix.pyx @ 276:754ff6452d7e

Fix spellcard number 0. Spellcard number 0 was evaluated as False in truth checks. Now, the spellcard is a tuple, with (number, name) and will always evaluate as True.
author Thibaut Girka <thib@sitedethib.com>
date Sun, 05 Feb 2012 23:45:41 +0100
parents fab7ad2f0d8b
children 74471afbac37
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
16
4
787d2eb13c2d Add buggy stageviewer!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
18 cdef class Matrix:
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
19 def __init__(Matrix self, data=None):
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
20 self.data = data or [[0] * 4 for i in xrange(4)]
4
787d2eb13c2d Add buggy stageviewer!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
21
787d2eb13c2d Add buggy stageviewer!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
22
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
23 cpdef flip(Matrix self):
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
24 data = self.data
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
25 a, b, c, d = data[0]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
26 data[0] = [-a, -b, -c, -d]
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
27
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
28
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
29 cpdef scale(Matrix self, x, y, z):
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
30 d1 = self.data
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
31 d1[0] = [a * x for a in d1[0]]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
32 d1[1] = [a * y for a in d1[1]]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
33 d1[2] = [a * z for a in d1[2]]
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
34
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
35
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
36 cpdef scale2d(Matrix self, x, y):
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
37 data = self.data
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
38 d1a, d1b, d1c, d1d = data[0]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
39 d2a, d2b, d2c, d2d = data[1]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
40 data[0] = [d1a * x, d1b * x, d1c * x, d1d * x]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
41 data[1] = [d2a * y, d2b * y, d2c * y, d2d * y]
31
55973a3f1222 Some more optimization!
Thibaut Girka <thib@sitedethib.com>
parents: 30
diff changeset
42
55973a3f1222 Some more optimization!
Thibaut Girka <thib@sitedethib.com>
parents: 30
diff changeset
43
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
44 cpdef translate(Matrix self, x, y, z):
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
45 data = self.data
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
46 a, b, c = data[3][:3]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
47 a, b, c = a * x, b * y, c * z
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
48 d1a, d1b, d1c, d1d = data[0]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
49 d2a, d2b, d2c, d2d = data[1]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
50 d3a, d3b, d3c, d3d = data[2]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
51 data[0] = [d1a + a, d1b + a, d1c + a, d1d + a]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
52 data[1] = [d2a + b, d2b + b, d2c + b, d2d + b]
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
53 data[2] = [d3a + c, d3b + c, d3c + c, d3d + c]
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
54
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
55
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
56 cpdef rotate_x(Matrix self, angle):
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
57 d1 = self.data
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
58 cos_a = cos(angle)
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
59 sin_a = sin(angle)
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
60 d1[1], d1[2] = ([cos_a * d1[1][i] - sin_a * d1[2][i] for i in range(4)],
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
61 [sin_a * d1[1][i] + cos_a * d1[2][i] for i in range(4)])
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
62
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
63
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
64 cpdef rotate_y(Matrix self, angle):
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
65 d1 = self.data
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
66 cos_a = cos(angle)
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
67 sin_a = sin(angle)
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
68 d1[0], d1[2] = ([cos_a * d1[0][i] + sin_a * d1[2][i] for i in range(4)],
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
69 [- sin_a * d1[0][i] + cos_a * d1[2][i] for i in range(4)])
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
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
72 cpdef rotate_z(Matrix self, angle):
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
73 d1 = self.data
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
74 cos_a = cos(angle)
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 4
diff changeset
75 sin_a = sin(angle)
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
76 d1[0], d1[1] = ([cos_a * d1[0][i] - sin_a * d1[1][i] for i in range(4)],
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
77 [sin_a * d1[0][i] + cos_a * d1[1][i] for i in range(4)])
4
787d2eb13c2d Add buggy stageviewer!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
78