diff bGrease/controller/integrator.py @ 41:ff3e395abf91

Renamed grease to bGrease (Basic Grease) to get rid of conflicts with an already installed grease.
author KarstenBock@gmx.net
date Mon, 05 Sep 2011 15:00:34 +0200
parents grease/controller/integrator.py@bc88f7d5ca8b
children a6bbb732b27b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bGrease/controller/integrator.py	Mon Sep 05 15:00:34 2011 +0200
@@ -0,0 +1,42 @@
+#############################################################################
+#
+# Copyright (c) 2010 by Casey Duncan and contributors
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the MIT License
+# A copy of the license should accompany this distribution.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+#
+#############################################################################
+
+__version__ = '$Id$'
+
+
+class EulerMovement(object):
+	"""System that applies entity movement to position using Euler's method
+
+	:param position_component: Name of :class:`grease.component.Position` 
+		component to update.
+	:param movement_component: Name of :class:`grease.component.Movement` 
+		component used to update position.
+	"""
+
+	def __init__(self, position_component='position', movement_component='movement'):
+		self.position_component = position_component
+		self.movement_component = movement_component
+	
+	def set_world(self, world):
+		"""Bind the system to a world"""
+		self.world = world
+	
+	def step(self, dt):
+		"""Apply movement to position"""
+		assert self.world is not None, "Cannot run with no world set"
+		for position, movement in self.world.components.join(
+			self.position_component, self.movement_component):
+			movement.velocity += movement.accel * dt
+			position.position += movement.velocity * dt
+			position.angle += movement.rotation * dt
+