-
Notifications
You must be signed in to change notification settings - Fork 6
/
camera.py
43 lines (33 loc) · 1.06 KB
/
camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import pyglet
from pyglet.gl import *
class Camera(object):
def __init__(self, win, x=0.0, y=0.0, rot=0.0, zoom=100.0):
self.win = win
self.x = x
self.y = y
self.rot = rot
self.zoom = zoom
def worldProjection(self):
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
widthRatio = self.win.width / self.win.height
look = 0, self.win.width, 0, self.win.height
look = self.scale(look, 1)
gluOrtho2D(*look)
glMatrixMode(GL_MODELVIEW)
'''
-self.zoom * widthRatio,
self.zoom * widthRatio,
-self.zoom,
self.zoom)
'''
def scale(self, look, scale):
w = look[1]-look[0]
h = look[3]-look[2]
m = (look[1]+look[0])/2.0, (look[3]+look[2])/2.0
return m[0] - w*scale/2, m[0] + w*scale/2, m[1] - h*scale/2, m[1] + h*scale/2
def hudProjection(self):
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0, self.win.width, 0, self.win.height)