annotate bGrease/renderer/camera.py @ 173:3abd31885f0f

Added a method to the ScriptingSystem that returns the environment(locals, globals) in which scripts are run.
author Beliar <KarstenBock@gmx.net>
date Thu, 01 Mar 2012 14:49:09 +0100
parents a6bbb732b27b
children
rev   line source
166
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
1 import pyglet
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
2
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
3 class Camera(object):
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
4 """Sets the point of view for further renderers by altering the
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
5 model/view matrix when it is drawn. It does not actually perform
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
6 any drawing itself.
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
7
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
8 :param position: The position vector for the camera. Sets the center of the view.
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
9 :type position: Vec2d
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
10 :param angle: Camera rotation in degrees about the z-axis.
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
11 :type angle: float
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
12 :param zoom: Scaling vector for the coordinate axis.
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
13 :type zoom: Vec2d
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
14 :param relative: Flag to indicate if the camera settings are relative
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
15 to the previous view state. If ``False`` the view state is reset before
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
16 setting the camera view by loading the identity model/view matrix.
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
17
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
18 At runtime the camera may be manipulated via attributes with the
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
19 same names and functions as the parameters above.
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
20 """
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
21
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
22 def __init__(self, position=None, angle=None, zoom=None, relative=False):
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
23 self.position = position
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
24 self.angle = angle
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
25 self.zoom = zoom
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
26 self.relative = relative
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
27
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
28 def draw(self, gl=pyglet.gl):
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
29 if not self.relative:
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
30 gl.glLoadIdentity()
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
31 if self.position is not None:
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
32 px, py = self.position
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
33 gl.glTranslatef(px, py, 0)
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
34 if self.angle is not None:
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
35 gl.glRotatef(self.angle, 0, 0, 1)
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
36 if self.zoom is not None:
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
37 sx, sy = self.zoom
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
38 gl.glScalef(sx, sy ,0)
a6bbb732b27b Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents: 41
diff changeset
39