From d577decc9f49bac76c410a12b62e26ec582c5c81 Mon Sep 17 00:00:00 2001 From: Sai Vineet Date: Wed, 11 Dec 2013 19:36:41 +0000 Subject: Add a Pen tool to Physics Also took out the Elements package from the .egg and brought it out so that it can be edited. The Export to csv functionality has also been changed to reflect pygame coords only. Previously the coords were Box2d meters. --- (limited to 'physics.py') diff --git a/physics.py b/physics.py index 64e4ae1..f7ef867 100644 --- a/physics.py +++ b/physics.py @@ -40,7 +40,8 @@ sys.path.append("lib/") import pkg_resources # If your architecture is different, comment these lines and install # the modules in your system. -sys.path.append("lib/Elements-0.13-py2.5.egg") +# Elements is now inside the source itself. No need for the egg. +# sys.path.append("lib/Elements-0.13-py2.5.egg") sys.path.append("lib/Box2D-2.0.2b1-py2.5-linux-i686.egg") import Box2D as box2d import elements @@ -136,19 +137,25 @@ class PhysicsGame: if type(body.userData) == type({}): if body.userData.has_key('track_index'): trackdex = body.userData['track_index'] - - def round_to_3(n): - return math.ceil(n * 1000) / 1000.0 - - roundx = round_to_3(body.position.x) - roundy = round_to_3(body.position.y) - tupled_pos = (roundx, roundy) + + def to_screen(pos): + px = self.world.meter_to_screen( + pos[0]) + py = self.world.meter_to_screen( + pos[1]) + py = self.world.renderer.get_surface() \ + .get_height() - py + return (px, py) + + x = body.position.x + y = body.position.y + tupled_pos = to_screen((x, y)) posx = tupled_pos[0] posy = tupled_pos[1] try: self.full_pos_list[trackdex].append(posx) self.full_pos_list[trackdex].append(posy) - except: + except IndexError: self.full_pos_list.append([posx, posy]) if type(body.userData) == type({}): -- cgit v0.9.1