ezEngine  Milestone 7
ezGameGrid< CellData > Class Template Reference

ezGameGrid is a general purpose 2D grid structure that has several convenience functions which are often required when working with a grid. More...

#include <GameGrid.h>

Public Types

enum  Orientation { InPlaneXY, InPlaneXZ, InPlaneXminusZ }
 

Public Member Functions

void CreateGrid (ezUInt16 uiWidth, ezUInt16 uiHeight)
 Clears all data and reallocates the grid with the given dimensions.
 
void SetWorldSpaceDimensions (const ezVec3 &vLowerLeftCorner, const ezVec3 &vCellSize, Orientation ori=InPlaneXZ)
 Sets the lower left position of the grid in world space coordinates and the cell size. More...
 
void SetWorldSpaceDimensions (const ezVec3 &vLowerLeftCorner, const ezVec3 &vCellSize, const ezMat3 &mRotation)
 Sets the lower left position of the grid in world space coordinates and the cell size. More...
 
ezVec3 GetWorldSpaceCellSize () const
 Returns the worldspace size of each cell.
 
ezVec2I32 GetCellAtWorldPosition (const ezVec3 &vWorldSpacePos) const
 Returns the coordinate of the cell at the given world-space position. The world space dimension must be set for this to work. The indices might be outside valid ranges (negative, larger than the maximum size).
 
ezUInt16 GetGridWidth () const
 Returns the number of cells along the X axis.
 
ezUInt16 GetGridHeight () const
 Returns the number of cells along the Y axis.
 
ezBoundingBox GetWorldBoundingBox () const
 Returns the world-space bounding box of the grid, as specified via SetWorldDimensions.
 
ezUInt32 GetNumCells () const
 Returns the total number of cells.
 
CellData & GetCell (ezUInt32 uiIndex)
 Gives access to a cell by cell index.
 
const CellData & GetCell (ezUInt32 uiIndex) const
 Gives access to a cell by cell index.
 
CellData & GetCell (const ezVec2I32 &Coord)
 Gives access to a cell by cell coordinates.
 
const CellData & GetCell (const ezVec2I32 &Coord) const
 Gives access to a cell by cell coordinates.
 
ezVec2I32 ConvertCellIndexToCoordinate (ezUInt32 uiIndex) const
 Converts a cell index into a 2D cell coordinate.
 
ezUInt32 ConvertCellCoordinateToIndex (const ezVec2I32 &Coord) const
 Converts a cell coordinate into a cell index.
 
ezVec3 GetCellWorldSpaceOrigin (const ezVec2I32 &Coord) const
 Returns the lower left world space position of the cell with the given coordinates.
 
ezVec3 GetCellWorldSpaceCenter (const ezVec2I32 &Coord) const
 Returns the center world space position of the cell with the given coordinates.
 
bool IsValidCellCoordinate (const ezVec2I32 &Coord) const
 Checks whether the given cell coordinate is inside valid ranges.
 
bool PickCell (const ezVec3 &vRayStartPos, const ezVec3 &vRayDirNorm, ezVec2I32 *out_CellCoord, ezVec3 *out_vIntersection=nullptr) const
 Casts a world space ray through the grid and determines which cell is hit (if any).
 

Private Attributes

ezUInt16 m_uiWidth
 
ezUInt16 m_uiHeight
 
ezMat3 m_RotateToWorldspace
 
ezMat3 m_RotateToGridspace
 
ezVec3 m_vWorldSpaceOrigin
 
ezVec3 m_vWorldSpaceCellSize
 
ezVec3 m_vInverseWorldSpaceCellSize
 
ezDynamicArray< CellData > m_Cells
 

Detailed Description

template<class CellData>
class ezGameGrid< CellData >

ezGameGrid is a general purpose 2D grid structure that has several convenience functions which are often required when working with a grid.

Member Enumeration Documentation

template<class CellData>
enum ezGameGrid::Orientation
Enumerator
InPlaneXY 

The grid is expected to lie in the XY plane in worldspace (when Y is up, this is similar to a 2D side scroller)

InPlaneXZ 

The grid is expected to lie in the XZ plane in worldspace (when Y is up, this is similar to a top down RTS game)

InPlaneXminusZ 

The grid is expected to lie in the XZ plane in worldspace (when Y is up, this is similar to a top down RTS game)

Member Function Documentation

template<class CellData >
void ezGameGrid< CellData >::SetWorldSpaceDimensions ( const ezVec3 vLowerLeftCorner,
const ezVec3 vCellSize,
Orientation  ori = InPlaneXZ 
)

Sets the lower left position of the grid in world space coordinates and the cell size.

Together with the grid size, these values determine the final world space dimensions. The rotation defines how the grid is rotated in world space. An identity rotation means that grid cell coordinates (X, Y) map directly to world space coordinates (X, Y). So the grid is 'standing up' in world space (considering that Y is 'up'). Other rotations allow to rotate the grid into other planes, such as XZ, if that is more convenient.

template<class CellData >
void ezGameGrid< CellData >::SetWorldSpaceDimensions ( const ezVec3 vLowerLeftCorner,
const ezVec3 vCellSize,
const ezMat3 mRotation 
)

Sets the lower left position of the grid in world space coordinates and the cell size.

Together with the grid size, these values determine the final world space dimensions. The rotation defines how the grid is rotated in world space. An identity rotation means that grid cell coordinates (X, Y) map directly to world space coordinates (X, Y). So the grid is 'standing up' in world space (considering that Y is 'up'). Other rotations allow to rotate the grid into other planes, such as XZ, if that is more convenient.


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