Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes
Grid Class Reference

#include <grid.hpp>

Public Member Functions

 Grid ()
 
 Grid (int rows, int columns)
 Initializes this Grid with the specified number of rows and columns. More...
 
 ~Grid ()
 
void addCell (int x, int y, CellType type)
 Adds a GridCell of the specified type at the given location. If the type is CellType::Spawn, then a pointer to the newly allocated GridCell will be added to the spawnCells vector. Note: If a GridCell already exists at the given location, the GridCell will not be added. (This function asserts that the given location is empty). Note: A GridCell will not be added if its x and y coordinates are outside of the integer range [0, columns - 1] and [0, rows - 1]. (This function asserts that the given x and y coordinates are within this range). More...
 
GridCellgetCell (int x, int y)
 Attempts to retrieve a GridCell at the specified location. Note: This function asserts if the coordinates are outside of the grid's dimensions. Note: This function assumes that all GridCells inside the grid's dimensions are initialized. More...
 
int getRows () const
 Returns the number of rows in this Grid. More...
 
int getColumns () const
 Returns the number of columns in this Grid. More...
 
std::vector< std::vector< GridCell * > > getGrid ()
 Returns the 2-D GridCell vector maintained by this Grid. More...
 
std::vector< GridCell * > getSpawnPoints ()
 Returns the vector of spawn point GridCells in this grid. More...
 
glm::vec3 getRandomSpawnPoint ()
 randomly selects a spawn point More...
 
glm::vec3 gridCellCenterPosition (GridCell *cell)
 Returns the center position (as an Object position vector) of the given GridCell's center. More...
 
void writeToFile (std::string path)
 

Static Public Member Functions

static glm::ivec2 getGridCellFromPosition (glm::vec3 position)
 Returns the position of the GridCell that would contain the given position. More...
 
static std::vector< glm::ivec2 > getCellsFromPositionRange (glm::vec3 p1, glm::vec3 p2)
 Returns a vector of positions of GridCells that contain the rectangle that extends from p1 to p2 (assumes p1.x <= p2.x and p1.z <= p2.z) More...
 

Static Public Attributes

static float const grid_cell_width = DEFAULT_GRIDCELL_WIDTH
 The width, in meters, of each GridCell in this grid. More...
 

Constructor & Destructor Documentation

◆ Grid() [1/2]

Grid::Grid ( )
inline

◆ Grid() [2/2]

Grid::Grid ( int  rows,
int  columns 
)

Initializes this Grid with the specified number of rows and columns.

Parameters
rowsNumber of rows in the grid.
columnsNumber of columns in the grid.

◆ ~Grid()

Grid::~Grid ( )

Member Function Documentation

◆ addCell()

void Grid::addCell ( int  x,
int  y,
CellType  type 
)

Adds a GridCell of the specified type at the given location. If the type is CellType::Spawn, then a pointer to the newly allocated GridCell will be added to the spawnCells vector. Note: If a GridCell already exists at the given location, the GridCell will not be added. (This function asserts that the given location is empty). Note: A GridCell will not be added if its x and y coordinates are outside of the integer range [0, columns - 1] and [0, rows - 1]. (This function asserts that the given x and y coordinates are within this range).

Parameters
xx coordinate of the new GridCell.
yy coordinate of the new GridCell.
typetype of the GridCell to add to the grid.

◆ getCell()

GridCell * Grid::getCell ( int  x,
int  y 
)

Attempts to retrieve a GridCell at the specified location. Note: This function asserts if the coordinates are outside of the grid's dimensions. Note: This function assumes that all GridCells inside the grid's dimensions are initialized.

Parameters
xx coordinate of the GridCell to retrieve.
yy coordinate of the GridCell to retrieve.
Returns
Pointer to the GridCell at the specified coordinates.

◆ getCellsFromPositionRange()

std::vector< glm::ivec2 > Grid::getCellsFromPositionRange ( glm::vec3  p1,
glm::vec3  p2 
)
static

Returns a vector of positions of GridCells that contain the rectangle that extends from p1 to p2 (assumes p1.x <= p2.x and p1.z <= p2.z)

Parameters
p13-D game world point from which rectangle extands
p23-D game world point to which rectangle extends
Returns
vector of positions of GridCells that contain the rectangle that extends from p1 to p2. If p1.x > p2.x or p1.z > p2.z, returns an empty vector.

◆ getColumns()

int Grid::getColumns ( ) const

Returns the number of columns in this Grid.

Returns
Integer number of columns in this Grid.

◆ getGrid()

std::vector< std::vector< GridCell * > > Grid::getGrid ( )

Returns the 2-D GridCell vector maintained by this Grid.

Returns
2-D GridCell vector maintained by this Grid.

◆ getGridCellFromPosition()

glm::ivec2 Grid::getGridCellFromPosition ( glm::vec3  position)
static

Returns the position of the GridCell that would contain the given position.

Parameters
position3-D Game world position
Returns
2-D Grid position of the GridCell that would contain the given position.
Note
It's possible that there may be no GridCell in a particularly used Grid that has the returned coordinates (meaning the input position is out of bounds of a given maze).

◆ getRandomSpawnPoint()

glm::vec3 Grid::getRandomSpawnPoint ( )

randomly selects a spawn point

Returns
corner coordinate of a randomly selected spawn point

◆ getRows()

int Grid::getRows ( ) const

Returns the number of rows in this Grid.

Returns
Integer number of rows in this Grid.

◆ getSpawnPoints()

std::vector< GridCell * > Grid::getSpawnPoints ( )

Returns the vector of spawn point GridCells in this grid.

Returns
Vector of spawn point GridCells in this grid.

◆ gridCellCenterPosition()

glm::vec3 Grid::gridCellCenterPosition ( GridCell cell)

Returns the center position (as an Object position vector) of the given GridCell's center.

Parameters
cellGridCell whose center position will be returned as an Object position vector.
Returns
Center position of the given grid cell as an Object Physics position vector, or (0,0,0) if the given cell pointer is nullptr

◆ writeToFile()

void Grid::writeToFile ( std::string  path)

Field Documentation

◆ grid_cell_width

const float Grid::grid_cell_width = DEFAULT_GRIDCELL_WIDTH
static

The width, in meters, of each GridCell in this grid.


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