AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Aire::Boid Class Reference

A Boid that can swarm in a flock. More...

#include <ai.h>

Collaboration diagram for Aire::Boid:
Collaboration graph
[legend]

Public Member Functions

 Boid (Terrain *terrain, RigidbodyHandler *rigidbodyHandler)
 Create a new boid.
 
void setTargetDirection (glm::vec2 direction)
 Setter for targetDirection.
 
void updateDirection (float speed, float transition)
 Updates the direction of the boid towards the target direction.
 
std::vector< Boid * > findNeighbours (std::vector< Boid * > totalBoids, float radius, float visionAngle)
 Finds the neighbouring boids within a given radius and vision angle.
 
glm::vec2 applyCohesion (std::vector< Boid * >neighbours, float strength) const
 Creates a direction vector towards the average position of the neighbouring boids.
 
glm::vec2 applyAlignment (std::vector< Boid * >neighbours, float strength) const
 Creates a direction vector towards the average direction of the neighbouring boids.
 
glm::vec2 applySeparation (std::vector< Boid * > neighbours, float strength, float radius) const
 Creates a direction vector away from the neighbouring boids.
 
glm::vec2 avoidEdges (float strength)
 Creates a direction vector away from the edges of the simulation space.
 
glm::vec2 avoidObstacles (RigidbodyHandler *rigidbodyHandler, float strength)
 Creates a direction vector away from the obstacles in the simulation space.
 
void setRigidbody (float radius, glm::vec3 pos)
 Sets the rigidbody of the boid.
 

Public Attributes

glm::vec2 currentDirection
 
glm::vec2 currentPosition
 
glm::mat4 model2world
 
Rigidbodyrigidbody
 

Detailed Description

A Boid that can swarm in a flock.

Constructor & Destructor Documentation

◆ Boid()

Aire::Boid::Boid ( Terrain * terrain,
RigidbodyHandler * rigidbodyHandler )
inline

Create a new boid.

Parameters
terrainThe terrain to set the boid's height
rigidbodyHandlerThe rigidbody handler to create the boid's rigidbody
Here is the call graph for this function:

Member Function Documentation

◆ applyAlignment()

glm::vec2 Boid::applyAlignment ( std::vector< Boid * > neighbours,
float strength ) const

Creates a direction vector towards the average direction of the neighbouring boids.

Parameters
neighbours- A vector of pointers to the neighbouring boids.
strength- The strength of the alignment rule.
Returns
glm::vec2 The direction vector created by the alignment rule.

◆ applyCohesion()

glm::vec2 Boid::applyCohesion ( std::vector< Boid * > neighbours,
float strength ) const

Creates a direction vector towards the average position of the neighbouring boids.

Parameters
neighbours- A vector of pointers to the neighbouring boids.
strength- The strength of the cohesion rule.
Returns
glm::vec2 The direction vector created by the cohesion rule.

◆ applySeparation()

glm::vec2 Boid::applySeparation ( std::vector< Boid * > neighbours,
float strength,
float radius ) const

Creates a direction vector away from the neighbouring boids.

Parameters
neighbours- A vector of pointers to the neighbouring boids.
strength- The strength of the separation rule.
radius- The radius within which to apply the separation rule.
Returns
glm::vec2 The direction vector created by the separation rule.

◆ avoidEdges()

glm::vec2 Boid::avoidEdges ( float strength)

Creates a direction vector away from the edges of the simulation space.

Parameters
strength- The strength of the rule.
Returns
glm::vec2 The direction vector created by the rule.
Here is the call graph for this function:

◆ avoidObstacles()

glm::vec2 Boid::avoidObstacles ( RigidbodyHandler * rigidbodyHandler,
float strength )

Creates a direction vector away from the obstacles in the simulation space.

Parameters
rigidbodyHandler- The rigidbody handler to get the obstacles from.
strength- The strength of the rule.
Returns
glm::vec2 The direction vector created by the rule.
Here is the call graph for this function:

◆ findNeighbours()

std::vector< Boid * > Boid::findNeighbours ( std::vector< Boid * > totalBoids,
float radius,
float visionAngle )

Finds the neighbouring boids within a given radius and vision angle.

Parameters
totalBoids- A vector of pointers to all boids in the simulation space.
radius- The radius within which to search for neighbours.
visionAngle- The angle within which to search for neighbours.
Returns
std::vector<Boid*> A vector of pointers to the neighbouring boids.

◆ setRigidbody()

void Boid::setRigidbody ( float radius,
glm::vec3 pos )

Sets the rigidbody of the boid.

Parameters
radius- The radius of the boid.
pos- The position of the boid.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTargetDirection()

void Aire::Boid::setTargetDirection ( glm::vec2 direction)
inline

Setter for targetDirection.

Parameters
direction- Given direction to set targetDirection to.

◆ updateDirection()

void Boid::updateDirection ( float speed,
float transition )

Updates the direction of the boid towards the target direction.

Parameters
speed- The speed at which the boid moves.
transition- The transition speed between the current and target direction.

Member Data Documentation

◆ currentDirection

glm::vec2 Aire::Boid::currentDirection

Current 2D direction the boid is moving to

◆ currentPosition

glm::vec2 Aire::Boid::currentPosition

Current 2D position of the boid

◆ model2world

glm::mat4 Aire::Boid::model2world

Model matrix

◆ rigidbody

Rigidbody* Aire::Boid::rigidbody

Rigidbody of the boid


The documentation for this class was generated from the following files: