Ejemplo n.º 1
0
 def __init__(self, target = Vector(), radius, strength):
     '''
     Constructor
     '''
     self.delta = Vector()
     self.target = target
     self.strength = strength
     self.setRadius(radius)
Ejemplo n.º 2
0
class Attraction(Behaviour):
    '''
    classdocs
    '''

    delta = Vector()
    target = Vector()
    radius = 0
    radiusSq = 0
    strength = 0
    
    def __init__(self, target = Vector(), radius, strength):
        '''
        Constructor
        '''
        self.delta = Vector()
        self.target = target
        self.strength = strength
        self.setRadius(radius)
        
        
    def setRadius(self, radius):
        self.radius = radius
        self.radiusSq = radius * radius
        
    def apply(self, p, dt, index):
        
        #call base(s)
        super(Attraction, self).apply(*args, **kw)
        
        # Vector pointing from particle to target.
        self.delta.copy(self.target).sub(p.pos)

        # Squared distance to target.
        distSq = self.delta.magSq()
         # Limit force to behaviour radius.
        if ( distSq < self.radiusSq and distSq > 0.000001):

            # Calculate force vector.
            self.delta.norm().scale(1.0 - distSq / self.radiusSq)

            #Apply force.
            p.acc.add (self.delta.scale(strength))