Mercurial > touhou
comparison pytouhou/game/sprite.py @ 28:f405b947624d
Massive sprite updating/matrix handling optimizations
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Fri, 12 Aug 2011 21:40:26 +0200 |
parents | b65d6bc55793 |
children | afa91be769ae |
comparison
equal
deleted
inserted
replaced
27:b65d6bc55793 | 28:f405b947624d |
---|---|
28 self._uvs = [] | 28 self._uvs = [] |
29 self._vertices = [] | 29 self._vertices = [] |
30 | 30 |
31 | 31 |
32 def update_uvs_vertices(self, override_width=0, override_height=0): | 32 def update_uvs_vertices(self, override_width=0, override_height=0): |
33 vertmat = Matrix() | 33 vertmat = Matrix([[-.5, .5, .5, -.5], |
34 vertmat.data[0][0] = -.5 | 34 [-.5, -.5, .5, .5], |
35 vertmat.data[1][0] = -.5 | 35 [ .0, .0, .0, .0], |
36 | 36 [ 1., 1., 1., 1.]]) |
37 vertmat.data[0][1] = .5 | |
38 vertmat.data[1][1] = -.5 | |
39 | |
40 vertmat.data[0][2] = .5 | |
41 vertmat.data[1][2] = .5 | |
42 | |
43 vertmat.data[0][3] = -.5 | |
44 vertmat.data[1][3] = .5 | |
45 | |
46 for i in range(4): | |
47 vertmat.data[2][i] = 0. | |
48 vertmat.data[3][i] = 1. | |
49 | 37 |
50 tx, ty, tw, th = self.texcoords | 38 tx, ty, tw, th = self.texcoords |
51 sx, sy = self.rescale | 39 sx, sy = self.rescale |
52 width = override_width or (tw * sx) | 40 width = override_width or (tw * sx) |
53 height = override_height or (th * sy) | 41 height = override_height or (th * sy) |
54 | 42 |
55 transform = Matrix.get_scaling_matrix(width, height, 1.) | 43 vertmat.scale(width, height, 1.) |
56 if self.mirrored: | 44 if self.mirrored: |
57 transform = Matrix.get_scaling_matrix(-1., 1., 1.).mult(transform) | 45 vertmat.flip() |
58 if self.rotations_3d != (0., 0., 0.): | 46 if self.rotations_3d != (0., 0., 0.): |
59 rx, ry, rz = self.rotations_3d | 47 rx, ry, rz = self.rotations_3d |
60 transform = Matrix.get_rotation_matrix(-rx, 'x').mult(transform) | 48 if rx: |
61 transform = Matrix.get_rotation_matrix(ry, 'y').mult(transform) | 49 vertmat.rotate_x(-rx) |
62 transform = Matrix.get_rotation_matrix(-rz, 'z').mult(transform) #TODO: minus, really? | 50 if ry: |
51 vertmat.rotate_y(ry) | |
52 if rz: | |
53 vertmat.rotate_z(-rz) #TODO: minus, really? | |
63 if self.corner_relative_placement: # Reposition | 54 if self.corner_relative_placement: # Reposition |
64 transform = Matrix.get_translation_matrix(width / 2., height / 2., 0.).mult(transform) | 55 vertmat.translate(width / 2., height / 2., 0.) |
65 vertmat = transform.mult(vertmat) | |
66 | 56 |
67 uvs = [(tx / self.anm.size[0], 1. - (ty / self.anm.size[1])), | 57 uvs = [(tx / self.anm.size[0], 1. - (ty / self.anm.size[1])), |
68 ((tx + tw) / self.anm.size[0], 1. - (ty / self.anm.size[1])), | 58 ((tx + tw) / self.anm.size[0], 1. - (ty / self.anm.size[1])), |
69 ((tx + tw) / self.anm.size[0], 1. - ((ty + th) / self.anm.size[1])), | 59 ((tx + tw) / self.anm.size[0], 1. - ((ty + th) / self.anm.size[1])), |
70 (tx / self.anm.size[0], 1. - ((ty + th) / self.anm.size[1]))] | 60 (tx / self.anm.size[0], 1. - ((ty + th) / self.anm.size[1]))] |