bird-oid
Version:
A 3D boid system with accompanying emergent behaviors. Implementation mostly based on Craig Reynolds paper Steering Behaviors For Autonomous Characters.
62 lines (61 loc) • 1.97 kB
TypeScript
export default System;
export type SystemOptions = {
/**
* A global scale for the system.
*/
scale?: number;
/**
* A maximum speed for the boids in the system. Can be tweaked individually via `boid.maxSpeed`.
*/
maxSpeed?: number;
/**
* A maximum force for each behavior of a boid. Can be tweaked individually via `boid.maxForce` or via `behaviors.options.maxForce`.
*/
maxForce?: number;
/**
* A center point for the system.
*/
center?: import("gl-matrix").vec3;
/**
* Positives bounds x/y/z for the system expanding from the center point.
*/
bounds?: import("gl-matrix").vec3;
};
/**
* @typedef {Object} SystemOptions
* @property {number} [scale=1] A global scale for the system.
* @property {number} [maxSpeed=scale] A maximum speed for the boids in the system. Can be tweaked individually via `boid.maxSpeed`.
* @property {number} [maxForce=scale] A maximum force for each behavior of a boid. Can be tweaked individually via `boid.maxForce` or via `behaviors.options.maxForce`.
* @property {import("gl-matrix").vec3} [center=[0, 0, 0]] A center point for the system.
* @property {import("gl-matrix").vec3} [bounds=[scale, scale, scale]] Positives bounds x/y/z for the system expanding from the center point.
*/
/**
* Handle common boids update and global state.
*/
declare class System {
/**
* @param {SystemOptions} options
*/
constructor(options: SystemOptions);
boids: any[];
scale: number;
maxSpeed: number;
maxForce: number;
center: number[];
bounds: number[];
/**
* Get a position within the system's bounds.
* @returns {number[]}
*/
getRandomPosition(): number[];
/**
* Push a new boid to the system.
* @param {Boid} boid
*/
addBoid(boid: Boid): void;
/**
* Update all behaviours in the system.
* @param {number} dt
*/
update(dt: number): void;
}