annotate bGrease/renderer/camera.py @ 131:d1c2d316cc25

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