def drawBox(pos, r): glColor4f(1, 1, 1, 1) glBegin(GL_LINE_LOOP) vtx = ((-r, r), (r, r), (r, -r), (-r, -r)) map(glVertex, [worldVecToScreen(os.Vec3(v[0], 0, v[1]) + pos) for v in vtx]) glEnd()
def initializeWorld(): global worldRad boids.createWorld(worldRad) for n in xrange(numBoids): addBoid() # big box that encloses the world #box = BoxObstacle(worldRad-2,worldRad-2,worldRad-2) r = worldRad - 2 box = BoxObstacle(r * 2, r * 2, r * 2) box.setSeenFrom(box.inside) box.setPosition(os.Vec3(0, 0, 0)) boids.obstacles.append(box) box = BoxObstacle(20, 20, 20) box.setSeenFrom(box.outside) box.setPosition(os.Vec3(40, -20, 0)) boids.obstacles.append(box)
def updateAndDraw(currentTime, elapsedTime): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) for b in boids.flock: b.update(currentTime, elapsedTime) b.draw() drawBox(os.Vec3.zero, worldRad - 2) drawBox(os.Vec3(40, -20, 0), 10)
def moveTo(self,x,y,z): self.setPosition(os.Vec3(x,y,z)) # notify proximity database that our position has changed self._proximityToken.updateForNewPosition(self.position())
def createWorld(worldRadius): global _worldRadius, _db _worldRadius = worldRadius _db = os.ProximityDatabase(os.Vec3(0,0,0), os.Vec3(worldRadius,worldRadius,worldRadius), os.Vec3(100,100,100))
def bumpBoids(): for b in boids.flock: b.applySteeringForce(os.Vec3(randint(-2, 2), 0, randint(-2, 2)), 1.0)