comparison grease/controller/integrator.py @ 5:bc88f7d5ca8b

Added base files for grease
author KarstenBock@gmx.net
date Tue, 12 Jul 2011 10:16:48 +0200
parents
children
comparison
equal deleted inserted replaced
4:bf1dd9c24a7e 5:bc88f7d5ca8b
1 #############################################################################
2 #
3 # Copyright (c) 2010 by Casey Duncan and contributors
4 # All Rights Reserved.
5 #
6 # This software is subject to the provisions of the MIT License
7 # A copy of the license should accompany this distribution.
8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
11 #
12 #############################################################################
13
14 __version__ = '$Id$'
15
16
17 class EulerMovement(object):
18 """System that applies entity movement to position using Euler's method
19
20 :param position_component: Name of :class:`grease.component.Position`
21 component to update.
22 :param movement_component: Name of :class:`grease.component.Movement`
23 component used to update position.
24 """
25
26 def __init__(self, position_component='position', movement_component='movement'):
27 self.position_component = position_component
28 self.movement_component = movement_component
29
30 def set_world(self, world):
31 """Bind the system to a world"""
32 self.world = world
33
34 def step(self, dt):
35 """Apply movement to position"""
36 assert self.world is not None, "Cannot run with no world set"
37 for position, movement in self.world.components.join(
38 self.position_component, self.movement_component):
39 movement.velocity += movement.accel * dt
40 position.position += movement.velocity * dt
41 position.angle += movement.rotation * dt
42