annotate src/parpg/bGrease/renderer/camera.py @ 170:371b17bc9113

Added ReplaceItemAction, to dialogueactions, which replaces a single item in the players inventory.
author KarstenBock@gmx.net
date Sun, 09 Oct 2011 14:39:02 +0200
parents 96af64cf3b81
children
rev   line source
27
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
1 import pyglet
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
2
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
3 class Camera(object):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
4 """Sets the point of view for further renderers by altering the
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
5 model/view matrix when it is drawn. It does not actually perform
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
6 any drawing itself.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
7
09b581087d68 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.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
9 :type position: Vec2d
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
10 :param angle: Camera rotation in degrees about the z-axis.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
11 :type angle: float
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
12 :param zoom: Scaling vector for the coordinate axis.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
13 :type zoom: Vec2d
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
14 :param relative: Flag to indicate if the camera settings are relative
09b581087d68 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
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
16 setting the camera view by loading the identity model/view matrix.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
17
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
18 At runtime the camera may be manipulated via attributes with the
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
19 same names and functions as the parameters above.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
20 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
21
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
22 def __init__(self, position=None, angle=None, zoom=None, relative=False):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
23 self.position = position
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
24 self.angle = angle
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
25 self.zoom = zoom
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
26 self.relative = relative
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
27
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
28 def draw(self, gl=pyglet.gl):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
29 if not self.relative:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
30 gl.glLoadIdentity()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
31 if self.position is not None:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
32 px, py = self.position
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
33 gl.glTranslatef(px, py, 0)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
34 if self.angle is not None:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
35 gl.glRotatef(self.angle, 0, 0, 1)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
36 if self.zoom is not None:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
37 sx, sy = self.zoom
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
38 gl.glScalef(sx, sy ,0)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
39