From 8ba9d4ae100be129b255230790149f488032fa3c Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 07 Mar 2014 19:44:11 +0000 Subject: elements cleanup --- (limited to 'elements/camera.py') diff --git a/elements/camera.py b/elements/camera.py index c45b27d..7fdf975 100644 --- a/elements/camera.py +++ b/elements/camera.py @@ -8,7 +8,7 @@ Home: http://elements.linuxuser.at IRC: #elements on irc.freenode.org Code: http://www.assembla.com/wiki/show/elements - svn co http://svn2.assembla.com/svn/elements + svn co http://svn2.assembla.com/svn/elements License: GPLv3 | See LICENSE for the full text This program is free software: you can redistribute it and/or modify @@ -22,28 +22,31 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program. If not, see . +along with this program. If not, see . """ from locals import * + class Camera: """ The Camera class. We will see :) Please also see: http://www.assembla.com/spaces/elements/tickets/31 - + This class currently handles: - Scaling factor - Screen Offset from the World Coordinate System - + Inputs from the user have to be checked for them. - Places to check for it: elements.py, drawing.py, add_objects.py - """ - scale_factor = 1.0 # All coords to the renderer are multiplied with the scale factor in elements.draw() - track_body = None # Body which means to be tracked. Offset is set at each elements.draw() - + # All coords to the renderer are multiplied with the scale factor + # in elements.draw() + scale_factor = 1.0 + # Body which means to be tracked. Offset is set at each elements.draw() + track_body = None + def __init__(self, parent): self.parent = parent - + def track(self, body): """ Start tracking a specific body """ @@ -53,17 +56,17 @@ class Camera: """ Stop tracking a body """ self.track_body = None - + def center(self, pos, screenCoord=True, stopTrack=True): """ Centers the camera at given screen coordinates -- in pixel Typical call: world.camera.center(event.pos) - + Problem: Works ONLY WITH screenCoord now! - """ + """ x, y = pos x -= self.parent.display_width / 2 - y -= self.parent.display_height / 2 + y -= self.parent.display_height / 2 if screenCoord: x /= self.scale_factor @@ -71,25 +74,30 @@ class Camera: # Set the offset self.inc_offset((x, y), screenCoord, stopTrack) - + def set_offset(self, offset, screenCoord=True, stopTrack=True): - """ Set an offset from the screen to the world cs + """ Set an offset from the screen to the world cs -- in screen (or world) coordinates and in pixel """ # Stop tracking of an object - if stopTrack: self.track_stop() + if stopTrack: + self.track_stop() # If screenCoords, we have to bring them to the world cs - if screenCoord: x, y = self.parent.to_world(offset) - else: x, y = offset + if screenCoord: + x, y = self.parent.to_world(offset) + else: + x, y = offset self._set_offset((x/self.parent.ppm, y/self.parent.ppm)) def inc_offset(self, offset, screenCoord=True, stopTrack=True): - """ Increment an offset from the screen to the world cs -- in world coordinates and in pixel + """ Increment an offset from the screen to the world cs -- in world + coordinates and in pixel """ # Stop tracking of an object - if stopTrack: self.track_stop() + if stopTrack: + self.track_stop() # Get Current Offset x, y = self.parent.screen_offset_pixel @@ -97,28 +105,30 @@ class Camera: # Bring the directions into the world coordinate system if screenCoord: - if self.parent.inputAxis_x_left: dx *= -1 - if self.parent.inputAxis_y_down: dy *= -1 - + if self.parent.inputAxis_x_left: + dx *= -1 + if self.parent.inputAxis_y_down: + dy *= -1 + # Set New Offset - self._set_offset(((x+dx)/self.parent.ppm, (y+dy)/self.parent.ppm)) - + self._set_offset(((x + dx) / self.parent.ppm, + (y + dy) / self.parent.ppm)) + def _set_offset(self, offset): """ Set the screen offset to the world coordinate system (using meters and the world coordinate system's orientation) """ - x, y = offset + x, y = offset self.parent.screen_offset = (x, y) - self.parent.screen_offset_pixel = (x*self.parent.ppm, y*self.parent.ppm) - + self.parent.screen_offset_pixel = (x * self.parent.ppm, + y * self.parent.ppm) + def set_scale_factor(self, factor=1.0): """ Zoom factor for the renderer 1.0 = 1:1 (original) """ self.scale_factor = factor - + def inc_scale_factor(self, factor=0.0): """ Increases the zooms for the renderer a given factor """ self.scale_factor += factor - - \ No newline at end of file -- cgit v0.9.1