Mercurial > touhou
comparison stageviewer.py @ 5:aa201d8cfc19
Fix camera handling, thanks, elghinn!
Camera handling is done using a few magical values,
which were obtained by dumping matrices using a modified wine installation,
and then doing some maths.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 02 Aug 2011 00:43:12 +0200 |
parents | 787d2eb13c2d |
children | 9159fa222923 |
comparison
equal
deleted
inserted
replaced
4:787d2eb13c2d | 5:aa201d8cfc19 |
---|---|
91 if 1 in properties: | 91 if 1 in properties: |
92 tx, ty, tw, th = anim.sprites[struct.unpack('<I', properties[1])[0]] | 92 tx, ty, tw, th = anim.sprites[struct.unpack('<I', properties[1])[0]] |
93 width, height = 1., 1. | 93 width, height = 1., 1. |
94 if 2 in properties: | 94 if 2 in properties: |
95 width, height = struct.unpack('<ff', properties[2]) | 95 width, height = struct.unpack('<ff', properties[2]) |
96 width = width_override or width * 16. | 96 width = width_override or width * 16. #TODO: something is wrong here |
97 height = height_override or height * 16. | 97 height = height_override or height * 16. #TODO: something is wrong here |
98 transform = Matrix.get_scaling_matrix(width, height, 1.) | 98 transform = Matrix.get_scaling_matrix(width, height, 1.) |
99 if 7 in properties: | 99 if 7 in properties: |
100 transform = Matrix.get_scaling_matrix(-1., 1., 1.).mult(transform) | 100 transform = Matrix.get_scaling_matrix(-1., 1., 1.).mult(transform) |
101 if 9 in properties: | 101 if 9 in properties: |
102 rx, ry, rz = struct.unpack('<fff', properties[9]) | 102 rx, ry, rz = struct.unpack('<fff', properties[9]) |
134 # Initialize pygame | 134 # Initialize pygame |
135 pygame.init() | 135 pygame.init() |
136 window = pygame.display.set_mode((384, 448), pygame.OPENGL | pygame.DOUBLEBUF) | 136 window = pygame.display.set_mode((384, 448), pygame.OPENGL | pygame.DOUBLEBUF) |
137 | 137 |
138 # Initialize OpenGL | 138 # Initialize OpenGL |
139 glMatrixMode(GL_PROJECTION) | |
140 glLoadIdentity() | |
141 gluPerspective(30, float(window.get_width())/window.get_height(), 20, 2000) | |
142 | |
139 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) | 143 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) |
140 glEnable(GL_DEPTH_TEST) | 144 glEnable(GL_DEPTH_TEST) |
141 glEnable(GL_BLEND) | 145 glEnable(GL_BLEND) |
142 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) | 146 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
143 glEnable(GL_TEXTURE_2D) | 147 glEnable(GL_TEXTURE_2D) |
218 x1, y1, z1 = struct.unpack('<fff', last_message[2]) | 222 x1, y1, z1 = struct.unpack('<fff', last_message[2]) |
219 x2, y2, z2 = struct.unpack('<fff', next_message[2]) | 223 x2, y2, z2 = struct.unpack('<fff', next_message[2]) |
220 | 224 |
221 truc = (float(frame) - last_message[0]) / (next_message[0] - last_message[0]) | 225 truc = (float(frame) - last_message[0]) / (next_message[0] - last_message[0]) |
222 | 226 |
223 #TODO: find proper coordinates (get rid of arbitrary values) | 227 x = x1 + (x2 - x1) * truc |
224 x = x1 + (x2 - x1) * truc + 170. | |
225 y = y1 + (y2 - y1) * truc | 228 y = y1 + (y2 - y1) * truc |
226 z = z1 + (z2 - z1) * truc - 720. | 229 z = z1 + (z2 - z1) * truc |
227 | 230 |
228 glMatrixMode(GL_PROJECTION) | |
229 glLoadIdentity() | |
230 gluPerspective(degrees(fov), float(window.get_width())/window.get_height(), 20, 2000) | |
231 | 231 |
232 glMatrixMode(GL_MODELVIEW) | 232 glMatrixMode(GL_MODELVIEW) |
233 glLoadIdentity() | 233 glLoadIdentity() |
234 gluLookAt(x, y, z, x, y - dy, 0., 0., -1., 0.) | 234 gluLookAt(192., 224., - 835.979370 * fov, |
235 192., 224. - dy, 750 - 835.979370 * fov, 0., -1., 0.) #TODO: 750 might not be accurate | |
236 #print(glGetFloat(GL_MODELVIEW_MATRIX)) | |
237 glTranslatef(-x, -y, -z) | |
235 | 238 |
236 glDrawArrays(GL_QUADS, 0, nb_vertices) | 239 glDrawArrays(GL_QUADS, 0, nb_vertices) |
237 | 240 |
238 pygame.display.flip() | 241 pygame.display.flip() |
239 clock.tick(120) | 242 clock.tick(120) |