Godot Nature of Code  1.2.0
Nature of Code implemented in Godot Engine
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Agents.SimpleFlowField Class Reference

Simple flow field. More...

Inheritance diagram for Agents.SimpleFlowField:
Agents.ImageFlowField

Classes

class  FlowDirection
 Flow direction. More...
 

Public Member Functions

Vector2 Lookup (Vector2 position)
 Lookup direction from flow. More...
 

Public Attributes

int Resolution = 30
 Grid resolution More...
 

Protected Member Functions

virtual Vector2 ComputeDirectionFromPosition (int x, int y)
 Compute flow direction from a given position. Defaults with a right vector. More...
 
void RefreshDirections ()
 Refresh flow directions. More...
 

Protected Attributes

int cols
 Column count More...
 
int rows
 Row count More...
 
FlowDirection[] field
 Flow field More...
 
Vector2 size
 Size More...
 

Detailed Description

Simple flow field.

Definition at line 8 of file SimpleFlowField.cs.

Member Function Documentation

◆ ComputeDirectionFromPosition()

virtual Vector2 Agents.SimpleFlowField.ComputeDirectionFromPosition ( int  x,
int  y 
)
inlineprotectedvirtual

Compute flow direction from a given position. Defaults with a right vector.

Parameters
xX coordinate
yY coordinate
Returns
Flow direction

Reimplemented in Agents.ImageFlowField.

Definition at line 77 of file SimpleFlowField.cs.

78  {
79  return Vector2.Right;
80  }

◆ Lookup()

Vector2 Agents.SimpleFlowField.Lookup ( Vector2  position)
inline

Lookup direction from flow.

Parameters
positionPosition
Returns
Direction vector

Definition at line 55 of file SimpleFlowField.cs.

56  {
57  var rect = new Rect2(GlobalPosition, size);
58  if (rect.HasPoint(position))
59  {
60  var x = (int)Mathf.Clamp((position.x - GlobalPosition.x) / Resolution, 0, cols - 1);
61  var y = (int)Mathf.Clamp((position.y - GlobalPosition.y) / Resolution, 0, rows - 1);
62  return field[x + (y * cols)].Direction;
63  }
64  else
65  {
66  return Vector2.Zero;
67  }
68  }
FlowDirection[] field
Flow field
int Resolution
Grid resolution
int cols
Column count

◆ RefreshDirections()

void Agents.SimpleFlowField.RefreshDirections ( )
inlineprotected

Refresh flow directions.

Definition at line 85 of file SimpleFlowField.cs.

86  {
87  for (int j = 0; j < rows; ++j)
88  {
89  for (int i = 0; i < cols; ++i)
90  {
91  var idx = i + (j * cols);
92  var direction = field[idx];
93  direction.Direction = ComputeDirectionFromPosition(i, j);
94  direction.RectRotation = Mathf.Rad2Deg(direction.Direction.Angle());
95  }
96  }
97  }
Vector2 Direction
Direction vector
virtual Vector2 ComputeDirectionFromPosition(int x, int y)
Compute flow direction from a given position. Defaults with a right vector.

Member Data Documentation

◆ cols

int Agents.SimpleFlowField.cols
protected

Column count

Definition at line 14 of file SimpleFlowField.cs.

◆ field

FlowDirection [] Agents.SimpleFlowField.field
protected

Flow field

Definition at line 20 of file SimpleFlowField.cs.

◆ Resolution

int Agents.SimpleFlowField.Resolution = 30

Grid resolution

Definition at line 11 of file SimpleFlowField.cs.

◆ rows

int Agents.SimpleFlowField.rows
protected

Row count

Definition at line 17 of file SimpleFlowField.cs.

◆ size

Vector2 Agents.SimpleFlowField.size
protected

Size

Definition at line 23 of file SimpleFlowField.cs.


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