XII Release 0.1.0
Loading...
Searching...
No Matches
xiiGameGrid< CellData > Class Template Reference

xiiGameGrid 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 (xiiUInt16 uiSizeX, xiiUInt16 uiSizeY)
 Clears all data and reallocates the grid with the given dimensions.
 
void SetWorldSpaceDimensions (const xiiVec3 &vLowerLeftCorner, const xiiVec3 &vCellSize, Orientation ori=InPlaneXZ)
 Sets the lower left position of the grid in world space coordinates and the cell size.
 
void SetWorldSpaceDimensions (const xiiVec3 &vLowerLeftCorner, const xiiVec3 &vCellSize, const xiiMat3 &mRotation)
 Sets the lower left position of the grid in world space coordinates and the cell size.
 
xiiVec3 GetCellSize () const
 Returns the size of each cell.
 
xiiVec2I32 GetCellAtWorldPosition (const xiiVec3 &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).
 
xiiUInt16 GetGridSizeX () const
 Returns the number of cells along the X axis.
 
xiiUInt16 GetGridSizeY () const
 Returns the number of cells along the Y axis.
 
xiiBoundingBox GetWorldBoundingBox () const
 Returns the world-space bounding box of the grid, as specified via SetWorldDimensions.
 
xiiUInt32 GetNumCells () const
 Returns the total number of cells.
 
CellData & GetCell (xiiUInt32 uiIndex)
 Gives access to a cell by cell index.
 
const CellData & GetCell (xiiUInt32 uiIndex) const
 Gives access to a cell by cell index.
 
CellData & GetCell (const xiiVec2I32 &vCoord)
 Gives access to a cell by cell coordinates.
 
const CellData & GetCell (const xiiVec2I32 &vCoord) const
 Gives access to a cell by cell coordinates.
 
xiiVec2I32 ConvertCellIndexToCoordinate (xiiUInt32 uiIndex) const
 Converts a cell index into a 2D cell coordinate.
 
xiiUInt32 ConvertCellCoordinateToIndex (const xiiVec2I32 &vCoord) const
 Converts a cell coordinate into a cell index.
 
xiiVec3 GetCellWorldSpaceOrigin (const xiiVec2I32 &vCoord) const
 Returns the lower left world space position of the cell with the given coordinates.
 
xiiVec3 GetCellLocalSpaceOrigin (const xiiVec2I32 &vCoord) const
 
xiiVec3 GetCellWorldSpaceCenter (const xiiVec2I32 &vCoord) const
 Returns the center world space position of the cell with the given coordinates.
 
xiiVec3 GetCellLocalSpaceCenter (const xiiVec2I32 &vCoord) const
 
bool IsValidCellCoordinate (const xiiVec2I32 &vCoord) const
 Checks whether the given cell coordinate is inside valid ranges.
 
bool PickCell (const xiiVec3 &vRayStartPos, const xiiVec3 &vRayDirNorm, xiiVec2I32 *out_pCellCoord, xiiVec3 *out_pIntersection=nullptr) const
 Casts a world space ray through the grid and determines which cell is hit (if any).
 
const xiiVec3GetWorldSpaceOrigin () const
 Returns the lower left corner position in world space of the grid.
 
const xiiMat3GetRotationToWorldSpace () const
 Returns the matrix used to rotate coordinates from grid space to world space.
 
const xiiMat3GetRotationToGridSpace () const
 Returns the matrix used to rotate coordinates from world space to grid space.
 
bool GetRayIntersection (const xiiVec3 &vRayStartWorldSpace, const xiiVec3 &vRayDirNormalizedWorldSpace, float fMaxLength, float &out_fIntersection, xiiVec2I32 &out_vCellCoord) const
 Tests where and at which cell the given world space ray intersects the grids bounding box.
 
bool GetRayIntersectionExpandedBBox (const xiiVec3 &vRayStartWorldSpace, const xiiVec3 &vRayDirNormalizedWorldSpace, float fMaxLength, float &out_fIntersection, const xiiVec3 &vExpandBBoxByThis) const
 Tests whether a ray would hit the grid bounding box, if it were expanded by a constant.
 
xiiResult Serialize (xiiStreamWriter &ref_stream) const
 
xiiResult Deserialize (xiiStreamReader &ref_stream)
 

Detailed Description

template<class CellData>
class xiiGameGrid< CellData >

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

Member Enumeration Documentation

◆ Orientation

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

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

InPlaneXZ 

The grid is expected to lie in the XZ plane in world-space (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 world-space (when Y is up, this is similar to a top down RTS game)

Member Function Documentation

◆ PickCell()

template<class CellData>
bool xiiGameGrid< CellData >::PickCell ( const xiiVec3 & vRayStartPos,
const xiiVec3 & vRayDirNorm,
xiiVec2I32 * out_pCellCoord,
xiiVec3 * out_pIntersection = nullptr ) const

Casts a world space ray through the grid and determines which cell is hit (if any).

Note
The picked cell is determined from where the ray hits the 'ground plane', ie. the plane that goes through the world space origin.

◆ SetWorldSpaceDimensions() [1/2]

template<class CellData>
void xiiGameGrid< CellData >::SetWorldSpaceDimensions ( const xiiVec3 & vLowerLeftCorner,
const xiiVec3 & vCellSize,
const xiiMat3 & 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.

◆ SetWorldSpaceDimensions() [2/2]

template<class CellData>
void xiiGameGrid< CellData >::SetWorldSpaceDimensions ( const xiiVec3 & vLowerLeftCorner,
const xiiVec3 & 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.


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