Boids simulation with Kotlin and OPENRNDR

Описание к видео Boids simulation with Kotlin and OPENRNDR

Watch at 4k to avoid YouTube compresion!

Each agent is only aware of other agents in close proximity (range shown at 0:40) and follows the three basic rules first defined by Craig Reynolds:

Separation, steer to avoid crowding local agents
Alignment, steer towards the average heading of local agents
Cohesion, steer to move towards the average position (center of mass) of local agents

Aditionally the agents avoid walls, and predators (on their vision range). The predators simply avoid walls, other predators and chase the closest boid (on their vision range).

Performance is improved by using a quadtree for spatial partitioning (shown at 0:40). This way we don't need to check the distance of a boid against every other boid to determine which ones are in his interaction range. The data structure dynamically organizes the objects by their positions and the query is much more efficient. The quadtree divides the space aiming to keep a maximum amount of agents on each region, in the video the regions turn red as they reach max capacity.

Aditionally coroutines are used to parallelize the calculation of the interactions between the agents and the updates of the quadtree. Finally the angle of the velocity vector of the agents is cached since it needs to be used few times each update.

Note: the bucket size of the quadtree is not the most optimal on this demonstration, but the subdivision of the quadtree is more visible with smaller bucket sizes.

https://github.com/Jorkoh/openrndr-bo...

Resources:
https://www.red3d.com/cwr/boids/
https://openrndr.org/
https://gameprogrammingpatterns.com/s...
https://en.wikipedia.org/wiki/Quadtree

Комментарии

Информация по комментариям в разработке