Flow field based on a texture.
More...
Flow field based on a texture.
Definition at line 8 of file ImageFlowField.cs.
◆ ImageFlowField()
Agents.ImageFlowField.ImageFlowField |
( |
| ) |
|
|
inline |
Create a new image flow field
Definition at line 22 of file ImageFlowField.cs.
24 _sprite =
new Sprite();
◆ ColorToDirection()
Vector2 Agents.ImageFlowField.ColorToDirection |
( |
Color |
color | ) |
|
|
inlineprotected |
Convert color to direction.
- Parameters
-
- Returns
- Direction
Definition at line 63 of file ImageFlowField.cs.
66 var angle =
MathUtils.
Map(color.r, 0, 1, 0, Mathf.Pi / 2);
67 return new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
static float Map(float value, float istart, float istop, float ostart, float ostop)
Map a value from one bound to another.
◆ ComputeDirectionFromPosition()
override Vector2 Agents.ImageFlowField.ComputeDirectionFromPosition |
( |
int |
x, |
|
|
int |
y |
|
) |
| |
|
inlineprotectedvirtual |
Compute flow direction from a given position. Defaults with a right vector.
- Parameters
-
x | X coordinate |
y | Y coordinate |
- Returns
- Flow direction
Reimplemented from Agents.SimpleFlowField.
Definition at line 70 of file ImageFlowField.cs.
76 var color = image.GetPixel((x * res) + (res / 2), (y * res) + (res / 2));
Vector2 ColorToDirection(Color color)
Convert color to direction.
Texture SourceTexture
Source texture
int TextureScale
Texture scale
int Resolution
Grid resolution
◆ CreateFieldFromTexture()
void Agents.ImageFlowField.CreateFieldFromTexture |
( |
| ) |
|
|
inlineprotected |
Create field from source texture.
Definition at line 30 of file ImageFlowField.cs.
39 for (
int j = 0; j <
rows; ++j)
41 for (
int i = 0; i <
cols; ++i)
43 var idx = i + (j *
cols);
44 var direction =
new FlowDirection()
46 RectSize = resolutionSize,
48 RectPivotOffset = resolutionSize / 2.0f,
51 direction.RectRotation = Mathf.Rad2Deg(direction.Direction.Angle());
52 field[idx] = direction;
override Vector2 ComputeDirectionFromPosition(int x, int y)
Compute flow direction from a given position. Defaults with a right vector.
FlowDirection[] field
Flow field
◆ CenterOnScreen
bool Agents.ImageFlowField.CenterOnScreen |
◆ SourceTexture
Texture Agents.ImageFlowField.SourceTexture |
◆ TextureScale
int Agents.ImageFlowField.TextureScale = 1 |
|
getset |
The documentation for this class was generated from the following file: