comparison eclviewer.py @ 45:e01e88b06a13

Fix camera handling, should be much closer to the original, now
author Thibaut Girka <thib@sitedethib.com>
date Mon, 22 Aug 2011 09:11:16 +0200
parents a10e3f44a883
children cbe1cb50f2fd
comparison
equal deleted inserted replaced
44:c435e83a8e70 45:e01e88b06a13
87 enemy_manager.update(frame) 87 enemy_manager.update(frame)
88 background.update(frame) 88 background.update(frame)
89 89
90 # Draw everything 90 # Draw everything
91 # glClearColor(0.0, 0.0, 1.0, 0) 91 # glClearColor(0.0, 0.0, 1.0, 0)
92 # glClear(GL_COLOR_BUFFER_BIT) 92 glClear(GL_DEPTH_BUFFER_BIT)
93 93
94 fog_b, fog_g, fog_r, _, fog_start, fog_end = background.fog_interpolator.values 94 fog_b, fog_g, fog_r, _, fog_start, fog_end = background.fog_interpolator.values
95 x, y, z = background.position_interpolator.values 95 x, y, z = background.position_interpolator.values
96 unknownx, dy, dz = background.position2_interpolator.values 96 dx, dy, dz = background.position2_interpolator.values
97 97
98 glFogi(GL_FOG_MODE, GL_LINEAR) 98 glFogi(GL_FOG_MODE, GL_LINEAR)
99 glFogf(GL_FOG_START, fog_start) 99 glFogf(GL_FOG_START, fog_start)
100 glFogf(GL_FOG_END, fog_end) 100 glFogf(GL_FOG_END, fog_end)
101 glFogfv(GL_FOG_COLOR, (fog_r / 255., fog_g / 255., fog_b / 255., 1.)) 101 glFogfv(GL_FOG_COLOR, (fog_r / 255., fog_g / 255., fog_b / 255., 1.))
107 # 192. = 384. / 2. = width / 2. 107 # 192. = 384. / 2. = width / 2.
108 # 224. = 448. / 2. = height / 2. 108 # 224. = 448. / 2. = height / 2.
109 # 835.979370 = 224./math.tan(math.radians(15)) = (height/2.)/math.tan(math.radians(fov/2)) 109 # 835.979370 = 224./math.tan(math.radians(15)) = (height/2.)/math.tan(math.radians(fov/2))
110 # This is so that objects on the (O, x, y) plane use pixel coordinates 110 # This is so that objects on the (O, x, y) plane use pixel coordinates
111 gluLookAt(192., 224., - 835.979370 * dz, 111 gluLookAt(192., 224., - 835.979370 * dz,
112 192., 224. - dy, 750 - 835.979370 * dz, 0., -1., 0.) #TODO: 750 might not be accurate 112 192. + dx, 224. - dy, 0., 0., -1., 0.)
113 #print(glGetFloat(GL_MODELVIEW_MATRIX)) 113 #print(glGetFloat(GL_MODELVIEW_MATRIX))
114 glTranslatef(-x, -y, -z) 114 glTranslatef(-x, -y, -z)
115 115
116 glEnable(GL_DEPTH_TEST)
116 for texture_key, (nb_vertices, vertices, uvs, colors) in background.objects_by_texture.items(): 117 for texture_key, (nb_vertices, vertices, uvs, colors) in background.objects_by_texture.items():
117 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) 118 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key])
118 glVertexPointer(3, GL_FLOAT, 0, vertices) 119 glVertexPointer(3, GL_FLOAT, 0, vertices)
119 glTexCoordPointer(2, GL_FLOAT, 0, uvs) 120 glTexCoordPointer(2, GL_FLOAT, 0, uvs)
120 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors) 121 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors)
121 glDrawArrays(GL_QUADS, 0, nb_vertices) 122 glDrawArrays(GL_QUADS, 0, nb_vertices)
123 glDisable(GL_DEPTH_TEST)
122 124
123 #TODO 125 #TODO
124 glMatrixMode(GL_MODELVIEW) 126 glMatrixMode(GL_MODELVIEW)
125 glLoadIdentity() 127 glLoadIdentity()
126 # Some explanations on the magic constants: 128 # Some explanations on the magic constants:
127 # 192. = 384. / 2. = width / 2. 129 # 192. = 384. / 2. = width / 2.
128 # 224. = 448. / 2. = height / 2. 130 # 224. = 448. / 2. = height / 2.
129 # 835.979370 = 224./math.tan(math.radians(15)) = (height/2.)/math.tan(math.radians(fov/2)) 131 # 835.979370 = 224./math.tan(math.radians(15)) = (height/2.)/math.tan(math.radians(fov/2))
130 # This is so that objects on the (O, x, y) plane use pixel coordinates 132 # This is so that objects on the (O, x, y) plane use pixel coordinates
131 gluLookAt(192., 224., - 835.979370, 133 gluLookAt(192., 224., - 835.979370,
132 192., 224., 750 - 835.979370, 0., -1., 0.) #TODO: 750 might not be accurate 134 192., 224., 0., 0., -1., 0.)
133 135
134 glDisable(GL_FOG) 136 glDisable(GL_FOG)
135 for texture_key, (nb_vertices, vertices, uvs, colors) in enemy_manager.objects_by_texture.items(): 137 for texture_key, (nb_vertices, vertices, uvs, colors) in enemy_manager.objects_by_texture.items():
136 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) 138 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key])
137 glVertexPointer(3, GL_FLOAT, 0, vertices) 139 glVertexPointer(3, GL_FLOAT, 0, vertices)