comparison pytouhou/utils/matrix.py @ 30:e3ba2fa966f6

Various optimizations
author Thibaut Girka <thib@sitedethib.com>
date Fri, 12 Aug 2011 23:47:34 +0200
parents f405b947624d
children 55973a3f1222
comparison
equal deleted inserted replaced
29:afa91be769ae 30:e3ba2fa966f6
34 34
35 def rotate_x(self, angle): 35 def rotate_x(self, angle):
36 d1 = self.data 36 d1 = self.data
37 cos_a = cos(angle) 37 cos_a = cos(angle)
38 sin_a = sin(angle) 38 sin_a = sin(angle)
39 a = [cos_a * d1[1][i] - sin_a * d1[2][i] for i in range(4)] 39 d1[1][:], d1[2][:] = ([cos_a * d1[1][i] - sin_a * d1[2][i] for i in range(4)],
40 b = [sin_a * d1[1][i] + cos_a * d1[2][i] for i in range(4)] 40 [sin_a * d1[1][i] + cos_a * d1[2][i] for i in range(4)])
41 d1[1][:] = a
42 d1[2][:] = b
43 41
44 42
45 def rotate_y(self, angle): 43 def rotate_y(self, angle):
46 #TODO: check 44 #TODO: check
47 d1 = self.data 45 d1 = self.data
48 cos_a = cos(angle) 46 cos_a = cos(angle)
49 sin_a = sin(angle) 47 sin_a = sin(angle)
50 a = [cos_a * d1[0][i] - sin_a * d1[2][i] for i in range(4)] 48 d1[0][:], d1[2][:] = ([cos_a * d1[0][i] - sin_a * d1[2][i] for i in range(4)],
51 b = [sin_a * d1[0][i] + cos_a * d1[2][i] for i in range(4)] 49 [sin_a * d1[0][i] + cos_a * d1[2][i] for i in range(4)])
52 d1[0][:] = a
53 d1[2][:] = b
54 50
55 51
56 def rotate_z(self, angle): 52 def rotate_z(self, angle):
57 d1 = self.data 53 d1 = self.data
58 cos_a = cos(angle) 54 cos_a = cos(angle)
59 sin_a = sin(angle) 55 sin_a = sin(angle)
60 a = [cos_a * d1[0][i] - sin_a * d1[1][i] for i in range(4)] 56 d1[0][:], d1[1][:] = ([cos_a * d1[0][i] - sin_a * d1[1][i] for i in range(4)],
61 b = [sin_a * d1[0][i] + cos_a * d1[1][i] for i in range(4)] 57 [sin_a * d1[0][i] + cos_a * d1[1][i] for i in range(4)])
62 d1[0][:] = a
63 d1[1][:] = b
64 58
65 59
66 @classmethod 60 @classmethod
67 def get_translation_matrix(cls, x, y, z): 61 def get_translation_matrix(cls, x, y, z):
68 return cls([[1., 0., 0., x], 62 return cls([[1., 0., 0., x],