Waterflow
Visualize water in terrain
|
Handles the representation of the voxelgrid. More...
#include <voxel.h>
Public Member Functions | |
Voxelgrid (DataHandler *handle, int64_t hashSize) | |
Constructs an empty voxel grid. | |
~Voxelgrid () | |
Completely delete the sparse voxelgrid. | |
void | drawVoxels (glm::mat4 projectionMatrix, glm::mat4 viewMatrix) |
Draw the voxel data. | |
void | FloodFill (int x, int z, int height, bool fillDown=true) |
Floodfills pixels at the specified position and height. | |
GLint | getHeight (int16_t x, int16_t z) |
Gets the height in waterHeight. | |
std::vector< GLint > * | getHeightMap () |
Returns a pointer to waterHeight. | |
neighs * | getNeighbourhood (int16_t x, int16_t y, int16_t z) |
Get a voxel and the 26 neighbouring pixels. | |
neighs * | getNeighbourhoodHash (int16_t x, int16_t y, int16_t z) |
Get a voxel and the 26 neighbouring pixels. | |
voxel * | getVoxel (int16_t x, int16_t y, int16_t z) |
Get value of voxel at x,y,z. | |
std::vector< GLuint > * | getVoxelPositions () |
Create a data pointer to all existing voxels. | |
void | hashAdd (int16_t x, int16_t y, int16_t z, bool filled, float a, float b) |
Adds a pixel using the hash functions. | |
voxel * | hashGet (int16_t x, int16_t y, int16_t z) |
Gets a pixel using the hash functions. | |
void | hashInit () |
Initializes the hashmap to the size specified by hashSize. | |
void | initDraw () |
Initialize Voxelgrid for drawing. | |
bool | isEqualPoint (voxel *vox, short int x, short int y, short int z) |
Returns true if the voxel contains the coordinates specified by x,y,z. | |
void | rehash () |
rehashes the table. | |
void | setHeight (int16_t x, int16_t y, int16_t z) |
Sets the height in waterHeight. | |
void | setVoxel (int16_t x, int16_t y, int16_t z, bool filled, float a, float b) |
Set value of voxel at x,y,z. | |
void | updateVoxelrender () |
Updates the buffer on the GPU. | |
Public Attributes | |
int64_t | hashSize |
size of the hash table | |
GLuint | numCollisions |
How many collisions presently. | |
GLuint | numInTable |
How many elements there are in the hashTable. | |
Private Member Functions | |
int64_t | hashFunc (int64_t x, int64_t y, int64_t z, int64_t inHashSize) |
hashFunc which returns a position in the hashtable to insert the voxel | |
Private Attributes | |
DataHandler * | datahandler |
Handle to the datahandler and thus the model data. | |
std::vector< voxel * > * | hashTable |
Pointer to hashTable. Filled with voxel pointers. | |
GLuint | height |
The height of the map, needed for voxel extraction. | |
GLuint | numVoxels |
Number of voxels in the voxelPositions. | |
GLfloat | rehashTresh |
Rehash treshhold. | |
GLuint | voxelBuffer |
Buffer for rendering. | |
std::vector< GLuint > * | voxelPositions |
Vector for the position where there are voxels, for drawing purposes. | |
std::vector< std::vector < std::vector< voxel * > * > * > * | voxels |
Container for the voxel lookup tables. | |
GLuint | voxelShader |
Shader program. | |
GLuint | voxelVAO |
VAOs for rendering. | |
std::vector< GLint > * | waterHeight |
The map of height data for the topmost water voxel. | |
GLuint | width |
The width of the map, needed for saving data in linear containers. | |
int | xoff [27] |
xoffsets for neighbour extraction. | |
int | yoff [27] |
xoffsets for neighbour extraction. | |
int | zoff [27] |
xoffsets for neighbour extraction. |
Handles the representation of the voxelgrid.
The class is used to construct the voxelgrid used for simulation and visualization. It places a voxel for each point in the base area (x times z) and uses N number of voxels in the precision from the lowest point in the model to the heighest peak. Note voxels outside of highest possible, however not negative voxel coordinates. The class implements a rudimentary sparse voxelgrid.
Voxelgrid::Voxelgrid | ( | DataHandler * | handle, |
int64_t | hashSize | ||
) |
Constructs an empty voxel grid.
Constructs an initially empty sparse voxelgrid, which scales so that there is N number of voxels in height representing the lowest point to the heighest. Where N is ceil(DataHandler->getTerrainScale) The grid dynamically grows when voxels are added. The grid supports values between -10 and INT_MAX-10, by offsetting input coordinates with +10.
handle | Handle to the DataHandler will be bound to the class |
hashSize | intialsize of the hashTable. Set if you plan on using the hashfunctions, should be a power of 2 for quick calculations. |
void Voxelgrid::drawVoxels | ( | glm::mat4 | projectionMatrix, |
glm::mat4 | viewMatrix | ||
) |
Draw the voxel data.
Draws the current buffer of voxels to the screen as billboards
void Voxelgrid::FloodFill | ( | int | x, |
int | z, | ||
int | height, | ||
bool | fillDown = true |
||
) |
GLint Voxelgrid::getHeight | ( | int16_t | x, |
int16_t | z | ||
) |
std::vector< GLint > * Voxelgrid::getHeightMap | ( | ) |
neighs * Voxelgrid::getNeighbourhood | ( | int16_t | x, |
int16_t | y, | ||
int16_t | z | ||
) |
neighs * Voxelgrid::getNeighbourhoodHash | ( | int16_t | x, |
int16_t | y, | ||
int16_t | z | ||
) |
Get a voxel and the 26 neighbouring pixels.
voxel * Voxelgrid::getVoxel | ( | int16_t | x, |
int16_t | y, | ||
int16_t | z | ||
) |
Get value of voxel at x,y,z.
Sets the values of the voxel at x,y,z and creates it in the sparse voxelgrid. if setting many voxels at the same time, loop over z first, followed by y, and from go from LOW values towards HIGH. (maximizes cache hits)
x | Coordinate of the voxel, x cannot be smaller than -10 |
y | Coordinate of the voxel, y cannot be smaller than -10 |
z | Coordinate of the voxel, z cannot be smaller than -10 |
std::vector< GLuint > * Voxelgrid::getVoxelPositions | ( | ) |
void Voxelgrid::hashAdd | ( | int16_t | x, |
int16_t | y, | ||
int16_t | z, | ||
bool | filled, | ||
float | a, | ||
float | b | ||
) |
int64_t Voxelgrid::hashFunc | ( | int64_t | x, |
int64_t | y, | ||
int64_t | z, | ||
int64_t | inHashSize | ||
) | [private] |
voxel * Voxelgrid::hashGet | ( | int16_t | x, |
int16_t | y, | ||
int16_t | z | ||
) |
void Voxelgrid::hashInit | ( | ) |
void Voxelgrid::initDraw | ( | ) |
Initialize Voxelgrid for drawing.
Gets the positions of all currently filled voxels, counts them, creates shader program, VAO and VBO.
void Voxelgrid::rehash | ( | ) |
void Voxelgrid::setHeight | ( | int16_t | x, |
int16_t | y, | ||
int16_t | z | ||
) |
void Voxelgrid::setVoxel | ( | int16_t | x, |
int16_t | y, | ||
int16_t | z, | ||
bool | filled, | ||
float | a, | ||
float | b | ||
) |
Set value of voxel at x,y,z.
Sets the values of the voxel at x,y,z and creates it in the sparse voxelgrid. if setting many voxels at the same time, loop over z first, followed by y, and from go from HIGH values towards LOW. (minimizes resizing) negative values supported by offsetting input by 10. supports values in the range -10 to INT_MAX-10
x | Coordinate of the voxel, x cannot be smaller than -10 |
y | Coordinate of the voxel, y cannot be smaller than -10 |
z | Coordinate of the voxel, z cannot be smaller than -10 |
filled | Bool determining if the voxel has been filled or not. |
a | Dummy variable for initial tests of size and performance |
b | Dummy variable for initial tests of size and performance |
void Voxelgrid::updateVoxelrender | ( | ) |
Updates the buffer on the GPU.
Which can be rendered by using drawVoxels()