Plasma Engine  2.0
Loading...
Searching...
No Matches
plGameGrid< CellData > Class Template Reference

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

Detailed Description

template<class CellData>
class plGameGrid< CellData >

plGameGrid 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 plGameGrid::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 plGameGrid< CellData >::PickCell ( const plVec3 & vRayStartPos,
const plVec3 & vRayDirNorm,
plVec2I32 * out_pCellCoord,
plVec3 * 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 plGameGrid< CellData >::SetWorldSpaceDimensions ( const plVec3 & vLowerLeftCorner,
const plVec3 & vCellSize,
const plMat3 & 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 plGameGrid< CellData >::SetWorldSpaceDimensions ( const plVec3 & vLowerLeftCorner,
const plVec3 & 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: