All Projects → Cultrarius → Swarmz

Cultrarius / Swarmz

Licence: unlicense
A free, header-only C++ swarming (flocking) library for real-time applications

Projects that are alternatives of or similar to Swarmz

Blui
Rich HTML UI engine for UE4
Stars: ✭ 753 (+597.22%)
Mutual labels:  game, unreal-engine
Polysnap
A work in progress polygon operations library with integer snap-rounding
Stars: ✭ 14 (-87.04%)
Mutual labels:  algorithm, library
Randompicker
一个动态权重的随机算法
Stars: ✭ 24 (-77.78%)
Mutual labels:  algorithm, game
Lambdahack
Haskell game engine library for roguelike dungeon crawlers; please offer feedback, e.g., after trying out the sample game with the web frontend at
Stars: ✭ 439 (+306.48%)
Mutual labels:  game, library
Libqsbr
QSBR and EBR library
Stars: ✭ 76 (-29.63%)
Mutual labels:  algorithm, library
Solid
🎯 A comprehensive gradient-free optimization framework written in Python
Stars: ✭ 546 (+405.56%)
Mutual labels:  algorithm, library
Librg
🚀 Making multi-player gamedev simpler since 2017
Stars: ✭ 813 (+652.78%)
Mutual labels:  game, library
Gb
gb single-file public domain libraries for C & C++
Stars: ✭ 363 (+236.11%)
Mutual labels:  public-domain, library
Actionroguelike
Third-person Action Roguelike made in Unreal Engine C++ (for Stanford CS193U 2020)
Stars: ✭ 1,121 (+937.96%)
Mutual labels:  game, unreal-engine
Thmap
Concurrent trie-hash map library
Stars: ✭ 51 (-52.78%)
Mutual labels:  algorithm, library
React Native Blurhash
🖼️ A library to show colorful blurry placeholders while your content loads.
Stars: ✭ 430 (+298.15%)
Mutual labels:  algorithm, library
Buoyancysystem
A system for buoyancy and boat physics in Unreal Engine 4.
Stars: ✭ 87 (-19.44%)
Mutual labels:  game, unreal-engine
Aigames
use AI to play some games.
Stars: ✭ 422 (+290.74%)
Mutual labels:  algorithm, game
Arabiccompetitiveprogramming
The repository contains the ENGLISH description files attached to the video series in my ARABIC algorithms channel.
Stars: ✭ 675 (+525%)
Mutual labels:  algorithm, library
Linux Steam Integration
Helper for enabling better Steam integration on Linux
Stars: ✭ 386 (+257.41%)
Mutual labels:  game, library
Apos.input
Polling input library for MonoGame.
Stars: ✭ 25 (-76.85%)
Mutual labels:  game, library
Towel
Throw in the towel.
Stars: ✭ 333 (+208.33%)
Mutual labels:  algorithm, library
Delaunay Triangulation
C++ version the delaunay triangulation
Stars: ✭ 339 (+213.89%)
Mutual labels:  algorithm, library
Rhashmap
Robin Hood hash map library
Stars: ✭ 33 (-69.44%)
Mutual labels:  algorithm, library
Snake
Artificial intelligence for the Snake game.
Stars: ✭ 1,241 (+1049.07%)
Mutual labels:  algorithm, game

Swarmz

A free, header-only C++ swarming (flocking) library for real-time applications.

An example usage can be seen in this particle editor plugin for the Unreal Engine 4.

Usage

Just include the header file to start:

#include "swarmz.h"

using namespace sw;

To create a new swarm, a pointer to the list of Boids is required. A boid is a single member of the swarm. Each boid has a position and a velocity:

// define our swarm members
vector<Boid> boids;
boids.push_back(Boid(Vec3(1, 0, 0), Vec3(1, 0, 0)));
boids.push_back(Boid(Vec3(1.5, 0, 0), Vec3(1, 1, 0)));
boids.push_back(Boid(Vec3(1, 0.5, 0.5), Vec3(0, 1, 0)));
boids.push_back(Boid(Vec3(4, 4, -2), Vec3(1, 0, 0)));

//create the swarm!
Swarm swarm(&boids);

The swarm has a lot of different settings, but the most important ones are the following:

  • PerceptionRadius - determines the vision radius of each boid. Only boids within this distance influence each other.
  • SeparationWeight - how much boids repel each other
  • AlignmentWeight - how much boids want go in the same direction
  • CohesionWeight - how much boids want to be in the center of the swarm
  • MaxAcceleration - how fast each boid can change its direction
  • MaxVelocity - how fast each boid can move

Each setting has a sensible default parameter, but playing around with them is half the fun:

// configure swarm
swarm.PerceptionRadius = 100;
swarm.CohesionWeight = 0.2;

To calculate the swarm movement, you usually update the swarm a few times a second in a loop. The swarm does not automatically move the boids, it just updates the velocity and acceleration for each boid. The position has to be updated by you.

// your tick/update loop
while (true) {
  swarm.Update(deltaSeconds);
  
  // each boid now has an updated velocity
  for (auto& boid : boids) {
    // update position
    boid.Position += boid.Velocity * deltaSeconds;
    
    // draw boid
  }
}

If you do not want the swarm to even update the boids velocity automatically (because you want to debug the result or you want to scale the acceleration per boid), then you can just call UpdateAcceleration() instead of the Update(deltaSeconds) on the swarm.

You can of course adjust the swarm parameters as well as the boid list during the loop to change the swarm behaviour over time. The library is, however, not thread-safe (so please no changes during the swarm update)!

That's basically it, have fun! :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].