Class NavMesh
Represents a navigation mesh for pathfinding.
Inherited Members
Namespace: Genesis.Core.GameElements
Assembly: Genesis.dll
Syntax
public class NavMesh : GameElement
Constructors
NavMesh(string, Vec3, int, int, float)
Initializes a new instance of the NavMesh class.
Declaration
public NavMesh(string name, Vec3 location, int cellsX, int cellsY, float cellSize)
Parameters
Type | Name | Description |
---|---|---|
string | name | |
Vec3 | location | The location of the navigation mesh. |
int | cellsX | The number of cells in the X direction. |
int | cellsY | The number of cells in the Y direction. |
float | cellSize | The size of each cell in the grid. |
Properties
CellHeight
The height of each cell in the grid.
Declaration
public float CellHeight { get; set; }
Property Value
Type | Description |
---|---|
float |
CellWidth
The width of each cell in the grid.
Declaration
public float CellWidth { get; set; }
Property Value
Type | Description |
---|---|
float |
CellsX
The number of cells in the X direction.
Declaration
public int CellsX { get; set; }
Property Value
Type | Description |
---|---|
int |
CellsY
The number of cells in the Y direction.
Declaration
public int CellsY { get; set; }
Property Value
Type | Description |
---|---|
int |
Debug
Gets or sets the value if debug mode is used
Declaration
public bool Debug { get; set; }
Property Value
Type | Description |
---|---|
bool |
Location
The location of the navigation mesh in 3D space.
Declaration
public Vec3 Location { get; set; }
Property Value
Type | Description |
---|---|
Vec3 |
StraightCost
The cost of moving straight from one cell to another.
Declaration
public int StraightCost { get; set; }
Property Value
Type | Description |
---|---|
int |
UseDiagonal
Declaration
public bool UseDiagonal { get; set; }
Property Value
Type | Description |
---|---|
bool |
Methods
AddObstacle(int, int)
Adds an obstacle to the navigation mesh.
Declaration
public void AddObstacle(int column, int row)
Parameters
Type | Name | Description |
---|---|---|
int | column | The column index of the cell where the obstacle is located. |
int | row | The row index of the cell where the obstacle is located. |
BuildGrid()
Builds the grid of cells for the navigation mesh.
Declaration
public void BuildGrid()
DrawGrid(IRenderDevice)
Draws the grid cells of the navigation mesh.
Declaration
public void DrawGrid(IRenderDevice renderer)
Parameters
Type | Name | Description |
---|---|---|
IRenderDevice | renderer | The renderer used to draw the grid cells. |
DrawPath(IRenderDevice, Waypoint)
Draws the path on the navigation mesh.
Declaration
public void DrawPath(IRenderDevice renderer, Waypoint end)
Parameters
Type | Name | Description |
---|---|---|
IRenderDevice | renderer | The renderer used to draw the path. |
Waypoint | end | The destination waypoint of the path. |
FindPath(int, int, int, int)
Finds a path from the starting cell to the ending cell on the navigation mesh.
Declaration
public Waypoint FindPath(int sCol, int sRow, int eCol, int eRow)
Parameters
Type | Name | Description |
---|---|---|
int | sCol | The column index of the starting cell. |
int | sRow | The row index of the starting cell. |
int | eCol | The column index of the ending cell. |
int | eRow | The row index of the ending cell. |
Returns
Type | Description |
---|---|
Waypoint | The destination waypoint of the path if found, otherwise null. |
FindPathAsync(int, int, int, int, FindPathAsynchResult)
Finds a path from the starting cell to the ending cell on the navigation mesh.
Declaration
public void FindPathAsync(int sCol, int sRow, int eCol, int eRow, FindPathAsynchResult callback)
Parameters
Type | Name | Description |
---|---|---|
int | sCol | The column index of the starting cell. |
int | sRow | The row index of the starting cell. |
int | eCol | The column index of the ending cell. |
int | eRow | The row index of the ending cell. |
FindPathAsynchResult | callback |
GetGridCell(int, int)
Get the gird cell at the given location
Declaration
public GridCell GetGridCell(int col, int row)
Parameters
Type | Name | Description |
---|---|---|
int | col | The column index |
int | row | The row index |
Returns
Type | Description |
---|---|
GridCell |
GetGridCellFromCoordinates(int, int)
Get the gridd cell from coordinats (workarround)
Declaration
public GridCell GetGridCellFromCoordinates(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
int | x | |
int | y |
Returns
Type | Description |
---|---|
GridCell |
GetGridCellFromCoordinatesParallel(int, int)
Declaration
public GridCell GetGridCellFromCoordinatesParallel(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
int | x | |
int | y |
Returns
Type | Description |
---|---|
GridCell |
GetIndicesFromGridCell(GridCell)
Declaration
public int[] GetIndicesFromGridCell(GridCell cell)
Parameters
Type | Name | Description |
---|---|---|
GridCell | cell |
Returns
Type | Description |
---|---|
int[] |
HasObstacle(GridCell)
Checks if there is an obstacle at the specified grid cell.
Declaration
public bool HasObstacle(GridCell cell)
Parameters
Type | Name | Description |
---|---|---|
GridCell | cell | The grid cell to check for obstacles. |
Returns
Type | Description |
---|---|
bool | True if there is an obstacle at the specified grid cell, otherwise false. |
IsObstacle(int, int)
Checks if there is an obstacle at the specified cell coordinates.
Declaration
public bool IsObstacle(int col, int row)
Parameters
Type | Name | Description |
---|---|---|
int | col | The column index of the cell to check. |
int | row | The row index of the cell to check. |
Returns
Type | Description |
---|---|
bool | True if there is an obstacle at the specified cell, otherwise false. |
OnRender(Game, IRenderDevice)
Renders the navmesh
Declaration
public override void OnRender(Game game, IRenderDevice renderDevice)
Parameters
Type | Name | Description |
---|---|---|
Game | game | |
IRenderDevice | renderDevice |
Overrides
ToPath(Waypoint)
Declaration
public static List<Waypoint> ToPath(Waypoint waypoint)
Parameters
Type | Name | Description |
---|---|---|
Waypoint | waypoint |
Returns
Type | Description |
---|---|
List<Waypoint> |