3#include <Foundation/Containers/DynamicArray.h>
4#include <Foundation/Math/Mat3.h>
5#include <Foundation/Math/Vec2.h>
6#include <Foundation/Math/Vec3.h>
7#include <Utilities/UtilitiesDLL.h>
11template <
class CellData>
25 void CreateGrid(plUInt16 uiSizeX, plUInt16 uiSizeY);
60 plUInt32
GetNumCells()
const {
return m_uiGridSizeX * m_uiGridSizeY; }
63 CellData&
GetCell(plUInt32 uiIndex) {
return m_Cells[uiIndex]; }
66 const CellData&
GetCell(plUInt32 uiIndex)
const {
return m_Cells[uiIndex]; }
111 float& out_fIntersection,
const plVec3& vExpandBBoxByThis)
const;
113 void ComputeWorldSpaceCorners(
plVec3* pCorners)
const;
119 plUInt16 m_uiGridSizeX;
120 plUInt16 m_uiGridSizeY;
122 plMat3 m_mRotateToWorldspace;
123 plMat3 m_mRotateToGridspace;
125 plVec3 m_vWorldSpaceOrigin;
126 plVec3 m_vLocalSpaceCellSize;
127 plVec3 m_vInverseLocalSpaceCellSize;
132#include <Utilities/DataStructures/Implementation/GameGrid_inl.h>
Definition DynamicArray.h:81
plGameGrid is a general purpose 2D grid structure that has several convenience functions which are of...
Definition GameGrid.h:13
plUInt16 GetGridSizeX() const
Returns the number of cells along the X axis.
Definition GameGrid.h:51
const CellData & GetCell(plUInt32 uiIndex) const
Gives access to a cell by cell index.
Definition GameGrid.h:66
const plMat3 & GetRotationToGridSpace() const
Returns the matrix used to rotate coordinates from world space to grid space.
Definition GameGrid.h:103
plUInt16 GetGridSizeY() const
Returns the number of cells along the Y axis.
Definition GameGrid.h:54
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.
Definition GameGrid_inl.h:29
const CellData & GetCell(const plVec2I32 &vCoord) const
Gives access to a cell by cell coordinates.
Definition GameGrid.h:72
plVec3 GetCellWorldSpaceOrigin(const plVec2I32 &vCoord) const
Returns the lower left world space position of the cell with the given coordinates.
Definition GameGrid_inl.h:70
plUInt32 GetNumCells() const
Returns the total number of cells.
Definition GameGrid.h:60
plUInt32 ConvertCellCoordinateToIndex(const plVec2I32 &vCoord) const
Converts a cell coordinate into a cell index.
Definition GameGrid.h:78
plVec3 GetCellSize() const
Returns the size of each cell.
Definition GameGrid.h:44
bool IsValidCellCoordinate(const plVec2I32 &vCoord) const
Checks whether the given cell coordinate is inside valid ranges.
Definition GameGrid_inl.h:94
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).
Definition GameGrid_inl.h:100
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.
Definition GameGrid_inl.h:130
plBoundingBox GetWorldBoundingBox() const
Returns the world-space bounding box of the grid, as specified via SetWorldDimensions.
Definition GameGrid_inl.h:120
CellData & GetCell(const plVec2I32 &vCoord)
Gives access to a cell by cell coordinates.
Definition GameGrid.h:69
plVec3 GetCellWorldSpaceCenter(const plVec2I32 &vCoord) const
Returns the center world space position of the cell with the given coordinates.
Definition GameGrid_inl.h:82
plVec2I32 ConvertCellIndexToCoordinate(plUInt32 uiIndex) const
Converts a cell index into a 2D cell coordinate.
Definition GameGrid.h:75
const plVec3 & GetWorldSpaceOrigin() const
Returns the lower left corner position in world space of the grid.
Definition GameGrid.h:97
CellData & GetCell(plUInt32 uiIndex)
Gives access to a cell by cell index.
Definition GameGrid.h:63
const plMat3 & GetRotationToWorldSpace() const
Returns the matrix used to rotate coordinates from grid space to world space.
Definition GameGrid.h:100
plVec2I32 GetCellAtWorldPosition(const plVec3 &vWorldSpacePos) const
Returns the coordinate of the cell at the given world-space position. The world space dimension must ...
Definition GameGrid_inl.h:61
void CreateGrid(plUInt16 uiSizeX, plUInt16 uiSizeY)
Clears all data and reallocates the grid with the given dimensions.
Definition GameGrid_inl.h:18
Orientation
Definition GameGrid.h:16
@ InPlaneXminusZ
The grid is expected to lie in the XZ plane in world-space (when Y is up, this is similar to a top do...
Definition GameGrid.h:19
@ InPlaneXZ
The grid is expected to lie in the XZ plane in world-space (when Y is up, this is similar to a top do...
Definition GameGrid.h:18
@ InPlaneXY
The grid is expected to lie in the XY plane in world-space (when Y is up, this is similar to a 2D sid...
Definition GameGrid.h:17
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.
Definition GameGrid_inl.h:167
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54