comparison 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
comparison
equal deleted inserted replaced
40:2e3ab06a2f47 41:ff3e395abf91
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