Mercurial > parpg-source
comparison grease/renderer/camera.py @ 5:bc88f7d5ca8b
Added base files for grease
author | KarstenBock@gmx.net |
---|---|
date | Tue, 12 Jul 2011 10:16:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:bf1dd9c24a7e | 5:bc88f7d5ca8b |
---|---|
1 import pyglet | |
2 | |
3 class Camera(object): | |
4 """Sets the point of view for further renderers by altering the | |
5 model/view matrix when it is drawn. It does not actually perform | |
6 any drawing itself. | |
7 | |
8 :param position: The position vector for the camera. Sets the center of the view. | |
9 :type position: Vec2d | |
10 :param angle: Camera rotation in degrees about the z-axis. | |
11 :type angle: float | |
12 :param zoom: Scaling vector for the coordinate axis. | |
13 :type zoom: Vec2d | |
14 :param relative: Flag to indicate if the camera settings are relative | |
15 to the previous view state. If ``False`` the view state is reset before | |
16 setting the camera view by loading the identity model/view matrix. | |
17 | |
18 At runtime the camera may be manipulated via attributes with the | |
19 same names and functions as the parameters above. | |
20 """ | |
21 | |
22 def __init__(self, position=None, angle=None, zoom=None, relative=False): | |
23 self.position = position | |
24 self.angle = angle | |
25 self.zoom = zoom | |
26 self.relative = relative | |
27 | |
28 def draw(self, gl=pyglet.gl): | |
29 if not self.relative: | |
30 gl.glLoadIdentity() | |
31 if self.position is not None: | |
32 px, py = self.position | |
33 gl.glTranslatef(px, py, 0) | |
34 if self.angle is not None: | |
35 gl.glRotatef(self.angle, 0, 0, 1) | |
36 if self.zoom is not None: | |
37 sx, sy = self.zoom | |
38 gl.glScalef(sx, sy ,0) | |
39 |