Beispiel #1
0
 def cohere(self, others):
     #find average point of all other Boids
     centerPoint = others.pop(0).position
     for other in others:
         centerPoint = Point3d.Add(centerPoint, other.position)
     centerPoint = Point3d.Divide(centerPoint, numBoids - 1)
     #find direction from Boid to average point of all other Boids
     direction = Point3d.Subtract(centerPoint, self.position)
     #remove magnitude from average-seeking vector
     direction = Vector3d.Divide(direction, direction.Length)
     #adapt heading to new direction
     self.heading = Vector3d.Add(direction, self.heading)
Beispiel #2
0
 def align(self, others):
     #generate list of other Boid headings
     headings = [other.heading for other in others]
     #empty vector creation
     uberVector = Vector3d(0.0, 0.0, 0.0)
     #add up all headings
     for heading in headings:
         uberVector = Vector3d.Add(uberVector, heading)
     #remove magnitude from sum of all headings
     uberVector = Vector3d.Divide(uberVector, uberVector.Length)
     #set Boids heading to aligned vector
     self.heading = uberVector