Flocking¶
If you have the VastPark Player installed, download the example IMML file below and open the demo in the VastPark Player.
Overview¶
Demonstrates use of the flocking plugin for flocking behaviors. The red boxes are the ‘flock’.
Instructions¶
Drag the blue sphere. The flock is bound to the region defined by the blue plane and are attracted to the blue sphere. Click the black box to scatter the flock. The flock has a tendency to perch on the green platform.
Further reading¶
One of our developers posted a blog about this plugin which is worth reading here: http://theparkisvast.com/2010/04/13/flocking-algorithm-in-vastpark/
Here's a summary:¶
- Any IPositionalElement (Model, Primitive, Sound, Camera, Light, etc) would be supported
- Implement Rule 1 – “Boids try to fly towards the centre of mass of neighbouring boids”
- Implement Rule 2 – “Boids try to keep a small distance away from other objects (including other boids)”
- Implement Rule 3 – “Boids try to match velocity with near boids”
- For bonus points I’d implement “Tendency towards a particular place”, “Limiting the speed”, “Bounding the position”, “Perching” and “Scattering the flock”
This translates into these plugin properties:¶
- SmallDistance
- MaxVelocity
- MinVelocity
- EnableBounds
- MaxBounds
- MinBounds
- EnablePerching
- MinPerchTime
- MaxPerchTime
- PerceivedCentre (get only)
The following callbacks:¶
- ElementPerched
- ElementLeftPerch
The following methods:¶
- SetPointOfInterest
- AddPlaceToAvoid
- AddPerch
- Scatter
The class diagrams look like this:
How does it work?¶
Put quite simply, the plugin works like this:
- AddElement(ImmlElement element) creates a boid instance for the positional element passed
- The plugin Update method (called once each update by the VastPark framework) proceeds to calculate the rules, one at a time for each boid to work out the new velocity and position for the element it represents
- Scatter requests made during runtime are dealt with during the next update
Downloads¶
Here is some sample IMML and the source code to the plugin, enjoy! Let me know if you decide to implement any of the other rules or do something cool with it :)
Sample IMML: flocking.imml
Source code to plugin: Plugin.Flocking.zip
Note: The source code will probably complain about some missing references. Install the Player from www.vastpark.com and link against the relevant binaries included with it.