Steeriously  0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
Classes | Typedefs | Enumerations | Functions | Variables
steer Namespace Reference

All steering functions are templated for easy application to objects inheriting from Agent. Because of this, it is easy to add into any type of design - be it a class hierarchy or a more advanced data structure or system (such as an entity component system). All functions return a steer::steer::Vector2 that can be used to calculate a force with which the entity should be moved given each type of behavior. Combine each calculated force with a weight (any scalar value - but keep it sane or behavior could become strange). Simply multiply each weight, or weights, by the force generated by each behavior's return value to fine-tune it. In addition to the steering functions themselves, this file contains various utilities used by them to perform their work. More...

Classes

class  Agent
 The invisible, but highly necessary, automaton which drives your *game entity/graphical representation's motion. Getters and Setters are provided, *however it will always be easier to just use the data - since it is all public. More...
 
struct  BehaviorParameters
 Data table with default values used to define variables for guiding steerable objects (agents). More...
 
class  ArriveComponent
 An example implementation of the arrive steering behavior. The agent will seek the target with a dampened arrival. More...
 
class  EvadeComponent
 An example implementation of the evasion steering behavior. The agent will flee from the target while predicting it's trajectory. More...
 
class  FleeComponent
 An example implementation of the flee steering behavior. The agent will flee from the target when it enters its threat range. More...
 
class  FlockingComponent
 An example implementation of the flocking steering behavior. The agent will interact with other members of the flock utilizing alignment, separation, cohesion, and wandering behaviors. More...
 
class  HideComponent
 An example implementation of the hiding steering behavior. More...
 
class  InterposeComponent
 An example implementation of the interpose steering behavior. More...
 
class  OffsetPursuitComponent
 An example implementation of the offset pursuit steering behavior. More...
 
class  PathFollowingComponent
 An example implementation of the path following steering behavior. More...
 
class  PursuitComponent
 An example implementation of the pursuit steering behavior. More...
 
class  SeekComponent
 An example implementation of the seek steering behavior. More...
 
class  SuperComponent
 An example implementation of the an agent with every steering behavior implemented. More...
 
class  WanderComponent
 An example implementation of the wander steering behavior. More...
 
class  Matrix2D
 A class for 2D matrices and related operations. More...
 
class  Path
 Class providing the necessary structure for path following behavior. More...
 
class  SphereObstacle
 Class to aid in obstacle avoidance routine. More...
 
struct  Vector2
 A 2D vector struct used in many steering calculations. More...
 
class  VectorMath
 Stateless VectorMath class utilizing static methods to manipulate vectors.
Copies of Vector2 are cheap, therefore all functions are "pass by value" at this time. More...
 
class  Wall
 A class for constructing 2D walls for wall avoidance behaviors. More...
 

Typedefs

typedef signed char Int8
 < Useful typedefs for signed/unsigned integers.
 
typedef unsigned char Uint8
 
typedef signed short Int16
 
typedef unsigned short Uint16
 
typedef signed int Int32
 
typedef unsigned int Uint32
 
typedef signed long long Int64
 
typedef unsigned long long Uint64
 Useful constants for minimum and maximum values.
 

Enumerations

enum  behaviorType {
  none = 0x00000, seek = 0x00002, flee = 0x00004, arrive = 0x00008,
  wander = 0x00010, cohesion = 0x00020, separation = 0x00040, alignment = 0x00080,
  obstacleAvoidance = 0x00100, wallAvoidance = 0x00200, followPath = 0x00400, pursuit = 0x00800,
  evade = 0x01000, interpose = 0x02000, hide = 0x04000, flock = 0x08000,
  offsetPursuit = 0x10000
}
 Bitfield for behavior types. Useful as a representation for combining behaviors.
 
enum  Deceleration { slow = 3, normal = 2, fast = 1 }
 Useful for applying a scaling factor to deceleration.
 
enum  summingMethod { weightedSum = 1, prioritized = 2, dithered = 3 }
 Useful for indicating what type of summation method to use for steering forces.
 
enum  { clockwise = 1, anticlockwise = -1 }
 

Functions

template<class T , class conT >
void TagVehiclesWithinViewRange (const T &entity, const conT &neighbors, float viewDistance)
 
template<class T , class conT >
void TagObstaclesWithinViewRange (const T &entity, const conT &obstacles, float boxLength)
 
template<class T , class conT >
void TagNeighbors (const T &entity, const conT &neighbors, float radius)
 
template<class T , class conT >
void TagObstacles (const T &entity, const conT &obstacles, float radius)
 
bool TwoCirclesOverlapped (float x1, float y1, float r1, float x2, float y2, float r2)
 Tests for circle-to-circle overlap.
 
bool TwoCirclesOverlapped (Vector2 c1, float r1, Vector2 c2, float r2)
 Tests for circle-to-circle overlap.
 
template<class T , class conT >
bool Overlapped (const T *ob, const conT &conOb, float MinDistBetweenObstacles)
 
bool LineIntersection2D (steer::Vector2 A, steer::Vector2 B, steer::Vector2 C, steer::Vector2 D, float &dist, steer::Vector2 &point)
 Checks for an intersection between two lines, given beginning and end points for both lines.
 
void WrapAround (steer::Vector2 &pos, int MaxX, int MaxY)
 Calculates the vector useful for wrapping around the steering vector of an agent to fit in the bounds of a rectangle (the screen, for example).
 
template<class T , class N >
steer::Vector2 calculateTarget (const T &agent, const N &other)
 
template<class T , class N , class P >
steer::Vector2 calculateTarget (const T &agent, const N &otherA, const P &otherB)
 
template<class T >
steer::Vector2 Seek (const T &agent)
 
template<class T >
steer::Vector2 Seek (const T &agent, steer::Vector2 target)
 A function returning the value necessary to steer an agent towards a target.
 
template<class T , class conT >
steer::Vector2 Alignment (const T &agent, const conT &neighbors)
 
template<class T , class conT >
steer::Vector2 Separation (const T &agent, const conT &neighbors)
 
template<class T , class conT >
steer::Vector2 Cohesion (const T &agent, const conT &neighbors)
 
template<class T >
steer::Vector2 Arrive (const T &agent, Uint32 deceleration)
 
template<class T , class N >
steer::Vector2 Pursuit (const T &agent, const N &evader)
 
template<class T , class N >
steer::Vector2 OffsetPursuit (const T &agent, const N &leader, const steer::BehaviorParameters &parameters)
 
template<class T >
steer::Vector2 Flee (const T &agent)
 
template<class T , class N >
steer::Vector2 Evade (const T &agent, const N &other)
 
steer::Vector2 findPosition (const steer::Vector2 &goalPosition, const float radius, const steer::Vector2 &avoidPosition, float distanceBuffer)
 This function calculates a position located on the other side of some position in space, given a radius, that is out of reach from an undesirable position (for example, a pursuing agent).
 
template<class T , class N , class conT >
steer::Vector2 Hide (const T &agent, const N &other, const conT &obstacles, const steer::BehaviorParameters &parameters)
 
template<class T , class N , class P >
steer::Vector2 Interpose (const T &agent, const N &otherA, const P &otherB, const steer::BehaviorParameters &parameters)
 
template<class T >
steer::Vector2 Wander (const T &agent)
 
template<class T , class conT >
steer::Vector2 ObstacleAvoidance (const T &agent, const conT &obstacles, const steer::BehaviorParameters &parameters)
 
template<class T >
steer::Vector2 WallAvoidance (const T &agent, const std::vector< steer::Wall * > &walls)
 
template<class T >
steer::Vector2 PathFollowing (const T &agent, steer::Path *path, const steer::BehaviorParameters &params)
 
std::vector< steer::Vector2WorldTransform (std::vector< steer::Vector2 > &points, const steer::Vector2 &pos, const steer::Vector2 &forward, const steer::Vector2 &side, const steer::Vector2 &scale)
 Given a std::vector of steer::Vector2, a position, orientation, and scale, this function transforms the std::vector of steer::Vector2 into the object's world space.
 
std::vector< steer::Vector2WorldTransform (std::vector< steer::Vector2 > &points, const steer::Vector2 &pos, const steer::Vector2 &forward, const steer::Vector2 &side)
 Given a std::vector of steer::Vector2, a position, and orientation, this function transforms the std::vector of steer::Vector2 into the object's world space.
 
steer::Vector2 PointToWorldSpace (const steer::Vector2 &point, const steer::Vector2 &AgentHeading, const steer::Vector2 &AgentSide, const steer::Vector2 &AgentPosition)
 Transforms a point from the agent's local space into world space.
 
steer::Vector2 VectorToWorldSpace (const steer::Vector2 &vec, const steer::Vector2 &AgentHeading, const steer::Vector2 &AgentSide)
 Transforms a vector from the agent's local space into world space.
 
steer::Vector2 PointToLocalSpace (const steer::Vector2 &point, const steer::Vector2 &AgentHeading, const steer::Vector2 &AgentSide, const steer::Vector2 &AgentPosition)
 Transforms a vector from world space into the agent's local space.
 
steer::Vector2 VectorToLocalSpace (const steer::Vector2 &vec, const steer::Vector2 &AgentHeading, const steer::Vector2 &AgentSide)
 Transforms a vector from world space into the agent's local space.
 
void Vec2DRotateAroundOrigin (steer::Vector2 &v, float ang)
 Rotates a vector by an angle in radians around the origin.
 
std::vector< steer::Vector2CreateWhiskers (unsigned int NumWhiskers, float WhiskerLength, float fov, steer::Vector2 facing, steer::Vector2 origin)
 Given an origin, a facing direction, a 'field of view' describing the limit of the outer whiskers, a whisker length and the number of whiskers this method returns a vector containing the end positions of a series of whiskers radiating away from the origin and with equal distance between them. (like the spokes of a wheel clipped to a specific segment size);.
 
template<typename T >
bool isNaN (T val)
 
float DegreesToRadians (float degrees)
 
bool IsZero (float val)
 Returns true if the parameter is equal to zero.
 
bool InRange (float start, float end, float val)
 Returns true if the third parameter is in the range described by the first two parameters.
 
template<class T >
Maximum (const T &v1, const T &v2)
 
int RandInt (int x, int y)
 Returns a random integer between x and y.
 
float RandFloat ()
 Returns a random float between 1 and the maximum value for a float.
 
float RandInRange (float x, float y)
 Returns a random float between x and y.
 
bool RandBool ()
 Returns true or false randomly.
 
float RandomClamped ()
 Returns a random float in the range -1 < n < 1.
 
float RandGaussian (float mean=0.0, float standard_deviation=1.0)
 Returns a random number with a normal distribution. See method at http://www.taygeta.com/random/gaussian.html.
 
float Sigmoid (float input, float response=1.0)
 Returns a value from the sigmoid (S-curve) function based on input and response.
 
template<class T >
MaxOf (const T &a, const T &b)
 
template<class T >
MinOf (const T &a, const T &b)
 
template<class T , class U , class V >
void Clamp (T &arg, const U &minVal, const V &maxVal)
 
int Rounded (float val)
 Rounds a double up or down depending on its value.
 
int RoundUnderOffset (float val, float offset)
 rounds a double up or down depending on whether its mantissa is higher or lower than offset.
 
bool isEqual (float a, float b)
 Compares two real numbers. Returns true if they are equal.
 
bool isEqual (double a, double b)
 Compares two real numbers. Returns true if they are equal.
 
template<class T >
float Average (const std::vector< T > &v)
 
float StandardDeviation (const std::vector< float > &v)
 Finds the standard deviation from a std::vector of floats.
 
template<class container >
void DeleteSTLContainer (container &c)
 
template<class map >
void DeleteSTLMap (map &m)
 
Vector2 operator* (const Vector2 &lhs, double rhs)
 
Vector2 operator* (double lhs, const Vector2 &rhs)
 
Vector2 operator- (const Vector2 &lhs, const Vector2 &rhs)
 
Vector2 operator+ (const Vector2 &lhs, const Vector2 &rhs)
 
Vector2 operator/ (const Vector2 &lhs, double val)
 
Vector2 Vec2DNormalize (const Vector2 &v)
 
double Vec2DDistance (const Vector2 &v1, const Vector2 &v2)
 
double Vec2DDistanceSq (const Vector2 &v1, const Vector2 &v2)
 
double Vec2DLength (const Vector2 &v)
 
double Vec2DLengthSq (const Vector2 &v)
 
bool NotInsideRegion (Vector2 p, Vector2 top_left, Vector2 bot_rgt)
 
bool InsideRegion (Vector2 p, Vector2 top_left, Vector2 bot_rgt)
 
bool InsideRegion (Vector2 p, int left, int top, int right, int bottom)
 
bool isSecondInFOVOfFirst (Vector2 posFirst, Vector2 facingFirst, Vector2 posSecond, double fov)
 

Variables

const int MaxInt = (std::numeric_limits<int>::max)()
 
const double MaxDouble = (std::numeric_limits<double>::max)()
 
const double MinDouble = (std::numeric_limits<double>::min)()
 
const float MaxFloat = (std::numeric_limits<float>::max)()
 
const float MinFloat = (std::numeric_limits<float>::min)()
 Useful constants for Pi.
 
const float Pi = 3.14159f
 
const float TwoPi = Pi * 2
 
const float HalfPi = Pi / 2
 
const float QuarterPi = Pi / 4
 

Detailed Description

All steering functions are templated for easy application to objects inheriting from Agent. Because of this, it is easy to add into any type of design - be it a class hierarchy or a more advanced data structure or system (such as an entity component system). All functions return a steer::steer::Vector2 that can be used to calculate a force with which the entity should be moved given each type of behavior. Combine each calculated force with a weight (any scalar value - but keep it sane or behavior could become strange). Simply multiply each weight, or weights, by the force generated by each behavior's return value to fine-tune it. In addition to the steering functions themselves, this file contains various utilities used by them to perform their work.

Function Documentation

std::vector< steer::Vector2 > steer::CreateWhiskers ( unsigned int  NumWhiskers,
float  WhiskerLength,
float  fov,
steer::Vector2  facing,
steer::Vector2  origin 
)
inline

Given an origin, a facing direction, a 'field of view' describing the limit of the outer whiskers, a whisker length and the number of whiskers this method returns a vector containing the end positions of a series of whiskers radiating away from the origin and with equal distance between them. (like the spokes of a wheel clipped to a specific segment size);.

Parameters
NumWhiskers- a plain old unsigned int.
WhiskerLength- a plain old float.
facing- a steer::Vector2 of floats.
origin- a steer::Vector2 of floats.
steer::Vector2 steer::findPosition ( const steer::Vector2 goalPosition,
const float  radius,
const steer::Vector2 avoidPosition,
float  distanceBuffer 
)
inline

This function calculates a position located on the other side of some position in space, given a radius, that is out of reach from an undesirable position (for example, a pursuing agent).

Parameters
goalPosition- a 2D vector of doubles.
radius- a plain old float.
avoidPosition- a 2D vector of doubles.
boundary- a plain old float.
bool steer::InRange ( float  start,
float  end,
float  val 
)
inline

Returns true if the third parameter is in the range described by the first two parameters.

Parameters
start- a plain old float.
end- a plain old float.
val- a plain old float.
bool steer::isEqual ( float  a,
float  b 
)
inline

Compares two real numbers. Returns true if they are equal.

Parameters
a- a plain old float.
b- a plain old float.
bool steer::isEqual ( double  a,
double  b 
)
inline

Compares two real numbers. Returns true if they are equal.

Parameters
a- a plain old double.
b- a plain old double.
bool steer::IsZero ( float  val)
inline

Returns true if the parameter is equal to zero.

Parameters
val- a plain old float.
bool steer::LineIntersection2D ( steer::Vector2  A,
steer::Vector2  B,
steer::Vector2  C,
steer::Vector2  D,
float &  dist,
steer::Vector2 point 
)
inline

Checks for an intersection between two lines, given beginning and end points for both lines.

Parameters
A- a 2D vector of floats.
B- a 2D vector of floats.
C- a 2D vector of floats.
D- a 2D vector of floats.
dist- a plain old float.
point- a 2D vector of floats.
steer::Vector2 steer::PointToLocalSpace ( const steer::Vector2 point,
const steer::Vector2 AgentHeading,
const steer::Vector2 AgentSide,
const steer::Vector2 AgentPosition 
)
inline

Transforms a vector from world space into the agent's local space.

Parameters
point- a steer::Vector2 of floats.
AgentHeading- a steer::Vector2 of floats.
AgentSide- a steer::Vector2 of floats.
AgentPosition- a steer::Vector2 of floats.
steer::Vector2 steer::PointToWorldSpace ( const steer::Vector2 point,
const steer::Vector2 AgentHeading,
const steer::Vector2 AgentSide,
const steer::Vector2 AgentPosition 
)
inline

Transforms a point from the agent's local space into world space.

Parameters
point- a steer::Vector2 of floats.
AgentHeading- a steer::Vector2 of floats.
AgentSide- a steer::Vector2 of floats.
AgentPosition- a steer::Vector2 of floats.
float steer::RandGaussian ( float  mean = 0.0,
float  standard_deviation = 1.0 
)
inline

Returns a random number with a normal distribution. See method at http://www.taygeta.com/random/gaussian.html.

Parameters
mean- a plain old float.
standard_deviation- a plain old float.
float steer::RandInRange ( float  x,
float  y 
)
inline

Returns a random float between x and y.

Parameters
x- a plain old float.
y- a plain old float.
int steer::RandInt ( int  x,
int  y 
)
inline

Returns a random integer between x and y.

Parameters
x- a plain old int.
y- a plain old int.
int steer::Rounded ( float  val)
inline

Rounds a double up or down depending on its value.

Parameters
val- a plain old float.
int steer::RoundUnderOffset ( float  val,
float  offset 
)
inline

rounds a double up or down depending on whether its mantissa is higher or lower than offset.

Parameters
val- a plain old float.
offset- a plain old float.
template<class T >
steer::Vector2 steer::Seek ( const T &  agent,
steer::Vector2  target 
)

A function returning the value necessary to steer an agent towards a target.

Parameters
agent- a steer::Agent derived object.
target- the target vector you are trying to reach.
float steer::Sigmoid ( float  input,
float  response = 1.0 
)
inline

Returns a value from the sigmoid (S-curve) function based on input and response.

Parameters
input- a plain old float.
response- a plain old float.
float steer::StandardDeviation ( const std::vector< float > &  v)
inline

Finds the standard deviation from a std::vector of floats.

Parameters
v- a std::vector of floats.
bool steer::TwoCirclesOverlapped ( float  x1,
float  y1,
float  r1,
float  x2,
float  y2,
float  r2 
)
inline

Tests for circle-to-circle overlap.

Parameters
x1- a plain old float.
y1- a plain old float.
r1- a plain old float.
x2- a plain old float.
y2- a plain old float.
r2- a plain old float.
bool steer::TwoCirclesOverlapped ( Vector2  c1,
float  r1,
Vector2  c2,
float  r2 
)
inline

Tests for circle-to-circle overlap.

Parameters
c1- a plain old float.
r1- a plain old float.
c2- a plain old float.
r2- a plain old float.
void steer::Vec2DRotateAroundOrigin ( steer::Vector2 v,
float  ang 
)
inline

Rotates a vector by an angle in radians around the origin.

Parameters
v- a steer::Vector2 of floats.
ang- a plain old float.
steer::Vector2 steer::VectorToLocalSpace ( const steer::Vector2 vec,
const steer::Vector2 AgentHeading,
const steer::Vector2 AgentSide 
)
inline

Transforms a vector from world space into the agent's local space.

Parameters
vec- a steer::Vector2 of floats.
AgentHeading- a steer::Vector2 of floats.
AgentSide- a steer::Vector2 of floats.
steer::Vector2 steer::VectorToWorldSpace ( const steer::Vector2 vec,
const steer::Vector2 AgentHeading,
const steer::Vector2 AgentSide 
)
inline

Transforms a vector from the agent's local space into world space.

Parameters
vec- a steer::Vector2 of floats.
AgentHeading- a steer::Vector2 of floats.
AgentSide- a steer::Vector2 of floats.
std::vector< steer::Vector2 > steer::WorldTransform ( std::vector< steer::Vector2 > &  points,
const steer::Vector2 pos,
const steer::Vector2 forward,
const steer::Vector2 side,
const steer::Vector2 scale 
)
inline

Given a std::vector of steer::Vector2, a position, orientation, and scale, this function transforms the std::vector of steer::Vector2 into the object's world space.

Parameters
points- a std::vector of steer::Vector2 floats.
pos- a steer::Vector2 of floats.
forward- a steer::Vector2 of floats.
side- a steer::Vector2 of floats.
scale- a steer::Vector2 of floats.
std::vector< steer::Vector2 > steer::WorldTransform ( std::vector< steer::Vector2 > &  points,
const steer::Vector2 pos,
const steer::Vector2 forward,
const steer::Vector2 side 
)
inline

Given a std::vector of steer::Vector2, a position, and orientation, this function transforms the std::vector of steer::Vector2 into the object's world space.

Parameters
points- a std::vector of steer::Vector2.
pos- a steer::Vector2 of floats.
forward- a steer::Vector2 of floats.
side- a steer::Vector2 of floats.
void steer::WrapAround ( steer::Vector2 pos,
int  MaxX,
int  MaxY 
)
inline

Calculates the vector useful for wrapping around the steering vector of an agent to fit in the bounds of a rectangle (the screen, for example).

Parameters
pos- a 2D vector of floats.
MaxX- a plain old int.
MaxY- a plain old int.