The functions and elements of a SmokeSystem. More...
#include <SmokeSystem.h>
Public Member Functions | |
SmokeSystem (const float _gridLengthX=10.0, const float _gridLengthY=10.0, const float _gridLengthZ=10.0, const int _gridBaseRes=10) | |
The Constructor for the SmokeSystem class. Initializes all of the values and creates instances necessary for the smoke simulation. | |
~SmokeSystem () | |
The Destructor for SmokeSystem class. De-allocates the memory by deleting the created instances. | |
void | advectVelocity (float _dt) |
This function advects the velocity. The velocity field is advected based on the conservation of momentum equation of the Navier-Stokes equations. RK4 integration is used for stability purposes. | |
ngl::Vec3 | advectVelocityFunction (float _i, float _j, float _k, float _h, float _currU, float _currV, float _currW) |
The velocity advection function. It calculates the F, G, and H values which are the conservation of momentum equation with the absence of the pressure and external force terms. | |
void | applyBuoyancyAndTurbulenceForces (float _dt, float _time) |
This function calculates and applies the buoyancy and turbulence forces. The buoyance forces are based on the temperature and density values. The hotter the temperature of the gas, the bigger the buoyance force. The noise/turbulence force is directly proportional to the buoyancy force. | |
void | applyPressure (float _dt) |
This function applies the pressure by updating the velocity field with the calculated pressure values. | |
void | calcVorticityConfinement (float _dt) |
This function calculates and applies the vorticity force. | |
void | calcPressure () |
This function calculates the pressure by solving Poisson's equation for pressure. This solver uses the Geiss-Seidel method with successive overrelaxation. | |
void | convectDensity (float _i, float _j, float _k, float _dt) |
This function convects the density. | |
void | convectEnergy (float _dt) |
This function convects the density and temperature. | |
float | convectEnergyFunction (float _i, float _j, float _k, float _curr, float _next_inX, float _prev_inX, float _next_inY, float _prev_inY, float _next_inZ, float _prev_inZ) |
The energy convection function. | |
void | convectTemperature (float _i, float _j, float _k, float _dt) |
This function convects the temperature. | |
void | createSpriteVAO () |
This function creates a vertex array object of Sprites. Each sprite is located at the center of each voxel. | |
void | createVelocityVAO () |
This function creates a vertex array object of Verticies for the velocity field arrows. This function was written by Jon Macey. | |
void | drawSmokeSprites () |
Draws the smoke sprites. | |
void | drawVelocityArrows () |
Draws the velocity field arrows. | |
void | emitEnergy (float _dt) |
Emits density and temperature from the emitter. The emitter location and size values are used to associate a cube of voxels with the emitter. The sine and power functions are used to emit the energy in a semi-spherical shape inside the cube of voxels. | |
float | getAbsoluteTolerance () const |
Gets the absolute tolerance of the pressure. | |
std::vector< Sprite > * | getData () |
Gets the m_spriteData variable. | |
Emitter * | getEmitter () |
Gets the emitter. | |
float | getGravity () const |
Gets the gravity value. | |
VoxelGrid * | getGrid () |
Gets the voxel grid. | |
float | getKDensityDiss () const |
Gets the k density dissipation constant. | |
float | getKFall () const |
Gets the k buoyancy fall constant. | |
float | getKRise () const |
Gets the k buoyancy rise constant. | |
float | getKTemperDiss () const |
Gets the k temperature dissipation constant. | |
float | getKVorticity () const |
Gets the k vorticity confinement constant. | |
float | getNoiseMagnitude () const |
Gets the magnitude of the noise. | |
noise::module::Perlin * | getNoiseModule () |
Gets the noise module. | |
float | getNoiseSpeed () const |
Gets the speed of the noise. | |
Obstacle * | getObstacle () |
Gets the obstacle object. | |
float | getOpacityStrength () const |
Gets the strength of the opacity. | |
int | getPrecisionX () const |
Gets the precision of the grid in the x direction. | |
int | getPrecisionY () const |
Gets the precision of the grid in the y direction. | |
int | getPrecisionZ () const |
Gets the precision of the grid in the z direction. | |
int | getPressureIters () const |
Gets the pressure iterations. | |
float | getRelaxationRate () const |
Gets the relaxation rate of the pressure. | |
float | getShadowStrength () const |
Gets the strength of the shadow. | |
GLuint | getTexID () const |
Gets the m_texID variable. | |
float | getViscosity () const |
Gets the viscosity value. | |
void | initGridValues () |
This function initializes the voxel grid values/. | |
void | initSolidVoxels () |
This function initializes the solid voxels based on the location of the obstacle's verticies. | |
void | initSmokeSpritePoints () |
This function creates the smoke sprite points. | |
void | initValues (const float _gridLengthX=10.0, const float _gridLengthY=10.0, const float _gridLengthZ=10.0, const int _gridBaseRes=10) |
This function initializes the values. All of the initial values of the variables are in this function so this function can be called to reset all of the variables back to their default values. | |
void | initVelocityField () |
This function creates the velocity field arrows. | |
bool | isObstacle () const |
Gets the boolean value of whether or not there is an obstacle to draw. | |
void | reset () |
Resets the simulation by deleting and re-creating and re-initializing everything. | |
void | setAbsoluteTolerance (double _val) |
Sets the absolute tolerance for the pressure. | |
void | setGravity (double _val) |
Sets the gravity force. | |
void | setGridBaseRes (int _res) |
Sets the base resolution of the voxel grid. | |
void | setGridLengthX (float _length) |
Sets the x length of the voxel grid. | |
void | setGridLengthY (float _length) |
Sets the y length of the voxel grid. | |
void | setGridLengthZ (float _length) |
Sets the y length of the voxel grid. | |
void | setH (float _val) |
Sets the width of the voxels. | |
void | setIsObstacle (bool _val) |
Sets the boolean of whether or not there is an obstacle. | |
void | setKDensityDiss (double _val) |
Sets the k density dissipation constant. | |
void | setKFall (double _val) |
Sets the k fall buoyancy constant. | |
void | setKRise (double _val) |
Sets the k rise buoyancy constant. | |
void | setKTemperDiss (float _val) |
Sets the k temperature dissipation constant. | |
void | setKVorticity (double _val) |
Sets the vorticity confinement constant. | |
void | setNoiseMagnitude (float _val) |
Sets the magnitude of the force of the noise. | |
void | setNoiseSpeed (float _val) |
Sets the speed of the noise. | |
void | setOpacityStrength (float _val) |
Sets the shadow strength. | |
void | setPrecisionX (int _precision) |
Sets the x precision of the voxel grid. | |
void | setPrecisionY (int _precision) |
Sets the y precision of the voxel grid. | |
void | setPrecisionZ (int _precision) |
Sets the z precision of the voxel grid. | |
void | setRelaxationRate (double _val) |
Sets the relaxation rate for the pressure. | |
void | setShadowStrength (float _val) |
Sets the shadow strength. | |
void | setViscosity (float _val) |
Sets the viscosity. | |
void | update (float _dt, float _time, bool _showVelocityField) |
This function updates the smoke by performing all of the calculations. | |
void | updateSpriteVAO () |
updates the sprite vertex array object | |
void | updateVelocityVAOData () |
updates the velocity arrow data of the vertex array object | |
void | updateVelocityVAO () |
updates the velocity arrow vertex array object | |
Private Attributes | |
float | m_absoluteTolerance |
The absolute tolerance of the pressure. The pressure iterates until the residual norm is below this absolute tolerance value. | |
Emitter * | m_emitter |
The emitter. | |
ngl::Vec3 | m_gravity |
The gravity force. | |
VoxelGrid * | m_grid |
The voxel grid. | |
int | m_gridBaseRes |
The base resolution of the grid. | |
float | m_gridLengthX |
The length of the grid in the x direction. | |
float | m_gridLengthY |
The length of the grid in the y direction. | |
float | m_gridLengthZ |
The length of the grid in the z direction. | |
float | m_h |
The master width of the voxel cell. | |
float | m_hX |
The width of the voxel cell in the x direction. | |
float | m_hY |
The width of the voxel cell in the y direction. | |
float | m_hZ |
The width of the voxel cell in the z direction. | |
bool | m_isObstacle |
A boolean determining if three is an obstacle or not. | |
float | m_kDensityDiss |
The user-specified density dissipation constant. | |
float | m_kFall |
The user-specified fall constant. | |
float | m_kRise |
The user-specified rise constant. | |
float | m_kTemperDiss |
The user-specified temper dissipation constant. | |
float | m_kVorticity |
The user-specified vorticity constant. | |
float | m_noiseMagnitude |
The magnitude of the force of the noise. | |
noise::module::Perlin | m_noiseModule |
The noise module. | |
noise::module::Turbulence | m_noiseTurbulenceModule |
The turbulence noise module. | |
float | m_noiseSpeed |
The speed of the noise. | |
Obstacle * | m_obstacle |
The obstacle object. | |
float | m_opacityStrength |
The strength of the opacity. | |
int | m_precisionX |
The precision of the grid in the x direction. | |
int | m_precisionY |
The precision of the grid in the y direction. | |
int | m_precisionZ |
The precision of the grid in the z direction. | |
int | m_pressureIters |
The number of pressure iterations per time step. | |
float | m_relaxationRate |
The relaxation rate of the pressure. | |
float | m_shadowStrength |
The strength of the shadow. | |
GLuint | m_texID |
The texture id. | |
std::vector< Sprite > | m_spriteData |
The data (verticies, normals, and uv's) of the smoke sprite points. | |
ngl::VertexArrayObject * | m_spriteVAO |
The vertex array object of the smoke sprites. | |
std::vector< ngl::vertData > | m_velocityFieldData |
The data (verticies, normals, and uv's) of the velocity field arrows. | |
ngl::VertexArrayObject * | m_velocityFieldVAO |
The vertex array object of the velocity field arrows. | |
float | m_viscosity |
The viscosity of the fluid simulation. |
The functions and elements of a SmokeSystem.
SmokeSystem::SmokeSystem | ( | const float | _gridLengthX = 10.0 , |
const float | _gridLengthY = 10.0 , |
||
const float | _gridLengthZ = 10.0 , |
||
const int | _gridBaseRes = 10 |
||
) |
The Constructor for the SmokeSystem class. Initializes all of the values and creates instances necessary for the smoke simulation.
[in] | _gridLengthX | the length of the grid in the x direction. |
[in] | _gridLengthY | the length of the grid in the y direction. |
[in] | _gridLengthY | the length of the grid in the z direction. |
[in] | _gridBaseRes | the base resolution of the grid. |
1. Create instances.
2. Initialize values.
3. Initialize texture object.
4. Initialize vertex array objects.
5. Initialize turbulence source module.
6. Initialize vertex array object data.
The Destructor for SmokeSystem class. De-allocates the memory by deleting the created instances.
1. De-allocate memory.
void SmokeSystem::advectVelocity | ( | float | _dt | ) |
This function advects the velocity. The velocity field is advected based on the conservation of momentum equation of the Navier-Stokes equations. RK4 integration is used for stability purposes.
[in] | _dt | The time step aka Δt |
The following code is based on the equations provided in the following book: Griebel, M., Dornseifer, T., and Neunhoeffer, T., 1998. Numerical Simulation in Fluid Dynamics: a Practical Introduction. Philadelphia: the Society for Industrial and Applied Mathematics.
1. Advect the velocity using RK4 integration. The velocity field needs to be advected to satisfy the conservation of momentum equation.
2. Calculate the right hand side of the Poisson pressure equation.
3. Copy the calculated F, G, and H values to the voxel.
ngl::Vec3 SmokeSystem::advectVelocityFunction | ( | float | _i, |
float | _j, | ||
float | _k, | ||
float | _h, | ||
float | _currU, | ||
float | _currV, | ||
float | _currW | ||
) |
The velocity advection function. It calculates the F, G, and H values which are the conservation of momentum equation with the absence of the pressure and external force terms.
[in] | _i | the index of the voxel grid in the x direction |
[in] | _j | the index of the voxel grid in the y direction |
[in] | _k | the index of the voxel grid in the z direction |
[in] | _h | the width of an individual voxel |
[in] | _currU | the u velocity component of the current voxel (located on the min x cell wall) |
[in] | _currV | the v velocity component of the current voxel (located on the min y cell wall) |
[in] | _currW | the w velocity component of the current voxel (located on the min z cell wall) |
Below is a breakdown of the Navier-Stokes momentum equation into partial derivatives and the finite difference discretization. However this breakdown does not include pressure and the external force terms.
NAVIER-STOKES -----------------------------
∂U/∂t = λ(▽^2)U - (▽U)*U
∂u/∂t = λ( (▽^2)*u ) - (▽U)*u
∂v/∂t = λ( (▽^2)*v ) - (▽U)*v
∂w/∂t = λ( (▽^2)*w ) - (▽U)*w
DIVERGENCE -----------------------------
▽U = ∂u/∂x + ∂v/∂y + ∂w/∂z
(▽U)*u = ∂uu/∂x + ∂uv/∂y + ∂uw/∂z
(▽U)*v = ∂vu/∂x + ∂vv/∂y + ∂vw/∂z
(▽U)*w = ∂wu/∂x + ∂wv/∂y + ∂ww/∂z
LAPLACIAN -----------------------------
▽^2 = (∂^2)/(∂x^2) + (∂^2)/(∂y^2) + (∂^2)/(∂z^2)
(▽^2)*u = (∂^2)u/(∂x^2) + (∂^2)u/(∂y^2) + (∂^2)u/(∂z^2)
(▽^2)*v = (∂^2)v/(∂x^2) + (∂^2)v/(∂y^2) + (∂^2)v/(∂z^2)
(▽^2)*w = (∂^2)w/(∂x^2) + (∂^2)w/(∂y^2) + (∂^2)w/(∂z^2)
NAVIER & DIVERGENCE & LAPLACIAN -----------------------------
∂u/∂t = λ( (∂^2)u/(∂x^2) + (∂^2)u/(∂y^2) + (∂^2)u/(∂z^2) ) - ∂uu/∂x - ∂uv/∂y - ∂uw/∂z
∂v/∂t = λ( (∂^2)v/(∂x^2) + (∂^2)v/(∂y^2) + (∂^2)v/(∂z^2) ) - ∂vu/∂x - ∂vv/∂y - ∂vw/∂z
∂w/∂t = λ( (∂^2)w/(∂x^2) + (∂^2)w/(∂y^2) + (∂^2)w/(∂z^2) ) - ∂wu/∂x - ∂wv/∂y - ∂ww/∂z
DISCRETIZATION -----------------------------
∂u/∂x = u(i+1,j,k) - u(i,j,k)
∂v/∂y = v(i,j+1,k) - v(i,j,k)
∂w/∂z = w(i,j,k+1) - w(i,j,k)
∂uu/∂x = u(i+1,j,k)*u(i+1,j,k) - u(i,j,k)*u(i,j,k)
∂uv/∂y = u(i+1,j,k)*v(i,j+1,k) - u(i,j,k)*v(i,j,k)
∂uw/∂z = u(i+1,j,k)*w(i,j,k+1) - u(i,j,k)*w(i,j,k)
∂vu/∂x = v(i,j+1,k)*u(i+1,j,k) - v(i,j,k)*u(i,j,k)
∂vv/∂y = v(i,j+1,k)*v(i,j+1,k) - v(i,j,k)*v(i,j,k)
∂vw/∂z = v(i,j+1,k)*w(i,j,k+1) - v(i,j,k)*w(i,j,k)
∂wu/∂x = w(i,j,k+1)*u(i+1,j,k) - w(i,j,k)*u(i,j,k)
∂wv/∂y = w(i,j,k+1)*v(i,j+1,k) - w(i,j,k)*v(i,j,k)
∂ww/∂z = w(i,j,k+1)*w(i,j,k+1) - w(i,j,k)*w(i,j,k)
(∂^2)u/(∂x^2) = u(i+1,j,k) - 2*u(i,j,k) + u(i-1,j,k)
(∂^2)u/(∂y^2) = u(i,j+1,k) - 2*u(i,j,k) + u(i,j+1,k)
(∂^2)u/(∂z^2) = u(i,j,k+1) - 2*u(i,j,k) + u(i,j,k+1)
(∂^2)v/(∂x^2) = v(i+1,j,k) - 2*v(i,j,k) + v(i-1,j,k)
(∂^2)v/(∂y^2) = v(i,j+1,k) - 2*v(i,j,k) + v(i,j+1,k)
(∂^2)v/(∂z^2) = v(i,j,k+1) - 2*v(i,j,k) + v(i,j,k+1)
(∂^2)w/(∂x^2) = w(i+1,j,k) - 2*w(i,j,k) + w(i-1,j,k)
(∂^2)w/(∂y^2) = w(i,j+1,k) - 2*w(i,j,k) + w(i,j+1,k)
(∂^2)w/(∂z^2) = w(i,j,k+1) - 2*w(i,j,k) + w(i,j,k+1)
The following code is based on the equations provided in the following book: Griebel, M., Dornseifer, T., and Neunhoeffer, T., 1998. Numerical Simulation in Fluid Dynamics: a Practical Introduction. Philadelphia: the Society for Industrial and Applied Mathematics.
1. Calculate the x component result of the conservation of momentum equation with the absence of the pressure and external force terms. This calculation uses central differences and the the donor-cell discretization described in the book by Griebel et al. (1998).
2. Calculate the y component result of the conservation of momentum equation with the absence of the pressure and external force terms. This calculation uses central differences and the the donor-cell discretization described in the book by Griebel et al. (1998).
3. Calculate the z component result of the conservation of momentum equation with the absence of the pressure and external force terms. This calculation uses central differences and the the donor-cell discretization described in the book by Griebel et al. (1998).
End of Citation
void SmokeSystem::applyBuoyancyAndTurbulenceForces | ( | float | _dt, |
float | _time | ||
) |
This function calculates and applies the buoyancy and turbulence forces. The buoyance forces are based on the temperature and density values. The hotter the temperature of the gas, the bigger the buoyance force. The noise/turbulence force is directly proportional to the buoyancy force.
[in] | _dt | The time step aka Δt |
[in] | _time | the time |
1 . The following equation for buoyancy is based on the buoyancy force equation described in this article: Cline, D., Cardon, D., Egbert, P. K., 2004. Fluid Flow for the Rest of Us: Tutorial of the Marker and Cell Method in Computer Graphics. Provo: Brigham Young University. Available from: http://people.sc.fsu.edu/~jburkardt/pdf/fluid_flow_for_the_rest_of_us.pdf [Accessed 8 June 2013]
2. Calculate the noise/turbulence force using the libnoise library by Jason Bevins (http://libnoise.sourceforge.net/). The noise value is directly proportional to the size of the buoyancy force.
3. Apply the buoyancy and noise forces to the velocity field.
void SmokeSystem::applyPressure | ( | float | _dt | ) |
This function applies the pressure by updating the velocity field with the calculated pressure values.
[in] | _dt | The time step aka Δt |
1. Add the calculation of the conservation of momentum equation without the pressure to the new velocity.
2. Add the pressure term to the new velocity.
3. Update the velocity field with the new velocity.
4. Force the velocity of a solid voxel (a voxel inside an obstacle) to 0. This step was done in this function in an attempt to not cycle through all of the voxels again for efficiency purposes.
5. Force some of the components of the velocity of the cells on the boundary to 0. This step was done in this function in an attempt to not cycle through all of the voxels again for efficiency purposes.
void SmokeSystem::calcPressure | ( | ) |
This function calculates the pressure by solving Poisson's equation for pressure. This solver uses the Geiss-Seidel method with successive overrelaxation.
The following code is based on the steps outlined in this book: Griebel, M., Dornseifer, T., and Neunhoeffer, T., 1998. Numerical Simulation in Fluid Dynamics: a Practical Introduction. Philadelphia: the Society for Industrial and Applied Mathematics.
1. Iterate through all of the voxels until the residual norm is below the user-specified absolute tolerance value. This is the Geiss-Seidel method with successive overrelaxation described in the book by Griebel et al.
2. Create parameters to prevent the pressure from being influenced by boundary cells.
3. Calculate the pressure. This equation is based on the equation provided in the book by Griebel et al.
4. Calculate the residual. This equation is based on the equation provided in the book by Griebel et al.
5. Copy the calculated pressure value to the temporary pressure value in the voxel.
6. Calculate the residual norm.
7. Copy the calculated pressure values to the grid.
End of Citation
void SmokeSystem::calcVorticityConfinement | ( | float | _dt | ) |
This function calculates and applies the vorticity force.
[in] | _dt | The time step aka Δt |
1. The following code for vorticity confinement is based on the steps outlined in this article: Cline, D., Cardon, D., Egbert, P. K., 2004. Fluid Flow for the Rest of Us: Tutorial of the Marker and Cell Method in Computer Graphics. Provo: Brigham Young University. Available from: http://people.sc.fsu.edu/~jburkardt/pdf/fluid_flow_for_the_rest_of_us.pdf [Accessed 8 June 2013]
2. Calculate the curl (∇ x u) using central differences.
3. Calculate the curl magnitude (n)
4. Calculate gradient direction of n (N = ∇n/||∇n||)
5. Calculate vorticity force.
6. Apply the force to the velocity field.
7. Copy new curl magnitudes to the grid.
End of Citation
void SmokeSystem::convectDensity | ( | float | _i, |
float | _j, | ||
float | _k, | ||
float | _dt | ||
) |
This function convects the density.
[in] | _i | the index of the voxel grid in the x direction |
[in] | _j | the index of the voxel grid in the y direction |
[in] | _k | the index of the voxel grid in the z direction |
[in] | _dt | The time step aka Δt |
1. Convect the density using RK4 integration.
2. Dissipate the density based on the user-specified k density dissipation value.
3. Clamp the density value between 0 and 1.
4. Copy the calculated density value to the temporary density value in the current voxel.
void SmokeSystem::convectEnergy | ( | float | _dt | ) |
This function convects the density and temperature.
[in] | _dt | The time step aka Δt |
1. Convect the density.
2. Convect the temperature.
3. Add a shadow to the sprites The following code adds a shadow to the sprites by adding a shadow value to each sprite based on the total density that is in front of the sprite. The shadow value is then used to change the colour value of the sprite texture.
4. Copy calculated density and temperature values to the grid and update the sprite vertex array object.
float SmokeSystem::convectEnergyFunction | ( | float | _i, |
float | _j, | ||
float | _k, | ||
float | _curr, | ||
float | _next_inX, | ||
float | _prev_inX, | ||
float | _next_inY, | ||
float | _prev_inY, | ||
float | _next_inZ, | ||
float | _prev_inZ | ||
) |
The energy convection function.
[in] | _i | the index of the voxel grid in the x direction |
[in] | _j | the index of the voxel grid in the y direction |
[in] | _k | the index of the voxel grid in the z direction |
[in] | _curr | the value of the energy in the current voxel |
[in] | _next_inX | the value of the energy in the next voxel in the x direction |
[in] | _prev_inX | the value of the energy in the previous voxel in the x direction |
[in] | _next_inY | the value of the energy in the next voxel in the y direction |
[in] | _prev_inY | the value of the energy in the previous voxel in the y direction |
[in] | _next_inZ | the value of the energy in the next voxel in the z direction |
[in] | _prev_inZ | the value of the energy in the previous voxel in the z direction |
1. Calculate and return the new energy value using the convection equation.
void SmokeSystem::convectTemperature | ( | float | _i, |
float | _j, | ||
float | _k, | ||
float | _dt | ||
) |
This function convects the temperature.
[in] | _i | the index of the voxel grid in the x direction |
[in] | _j | the index of the voxel grid in the y direction |
[in] | _k | the index of the voxel grid in the z direction |
[in] | _dt | The time step aka Δt |
1. Convect the temperature using RK4 integration.
2. Dissipate the temperature based on the user-specified k temperature dissipation value.
3. Clamp the temperature value between 0 and 1.
4. Copy the calculated temperature value to the temporary temperature value in the current voxel.
void SmokeSystem::createSpriteVAO | ( | ) |
This function creates a vertex array object of Sprites. Each sprite is located at the center of each voxel.
1. Create a sprite vertex array object using the sprite data. Set attribute array pointers for the following attributes: position, transparency, shadow, and temperature.
void SmokeSystem::createVelocityVAO | ( | ) |
This function creates a vertex array object of Verticies for the velocity field arrows. This function was written by Jon Macey.
1. Create a velocity field arrow vertex array object using the velocity field data. Set attribute array pointers for the following attributes: position, uv coordinates, and normals. This function is the same as the createVAO function in the NGL library written by Jon Macey.
void SmokeSystem::drawSmokeSprites | ( | ) |
Draws the smoke sprites.
1. Bind and draw the sprite vertex array object.
void SmokeSystem::drawVelocityArrows | ( | ) |
Draws the velocity field arrows.
1. Bind and draw the velocity field arrow vertex array object.
void SmokeSystem::emitEnergy | ( | float | _dt | ) |
Emits density and temperature from the emitter. The emitter location and size values are used to associate a cube of voxels with the emitter. The sine and power functions are used to emit the energy in a semi-spherical shape inside the cube of voxels.
[in] | _dt | The time step aka Δt |
1. Calculate the world position of the emitter based on its location in the domain.
2. Calculate the world position of the max edges of the emitter using the emitter size.
3. Calculate the world position of the min edges of the emitter using the emitter size.
4. Calculate the voxel indexes of the max and min edges. Clamp if the edges are outside of the domain.
5. Cycle through the cube of voxels that are associated with the emitter.
6. Emit density and temperature. The sine and power functions are used to emit the energy in a semi-spherical shape inside the cube of voxels.
float SmokeSystem::getAbsoluteTolerance | ( | ) | const [inline] |
Gets the absolute tolerance of the pressure.
std::vector<Sprite>* SmokeSystem::getData | ( | ) | [inline] |
Gets the m_spriteData variable.
Emitter* SmokeSystem::getEmitter | ( | ) | [inline] |
Gets the emitter.
float SmokeSystem::getGravity | ( | ) | const [inline] |
Gets the gravity value.
VoxelGrid* SmokeSystem::getGrid | ( | ) | [inline] |
Gets the voxel grid.
float SmokeSystem::getKDensityDiss | ( | ) | const [inline] |
Gets the k density dissipation constant.
float SmokeSystem::getKFall | ( | ) | const [inline] |
Gets the k buoyancy fall constant.
float SmokeSystem::getKRise | ( | ) | const [inline] |
Gets the k buoyancy rise constant.
float SmokeSystem::getKTemperDiss | ( | ) | const [inline] |
Gets the k temperature dissipation constant.
float SmokeSystem::getKVorticity | ( | ) | const [inline] |
Gets the k vorticity confinement constant.
float SmokeSystem::getNoiseMagnitude | ( | ) | const [inline] |
Gets the magnitude of the noise.
noise::module::Perlin* SmokeSystem::getNoiseModule | ( | ) | [inline] |
Gets the noise module.
float SmokeSystem::getNoiseSpeed | ( | ) | const [inline] |
Gets the speed of the noise.
Obstacle* SmokeSystem::getObstacle | ( | ) | [inline] |
Gets the obstacle object.
float SmokeSystem::getOpacityStrength | ( | ) | const [inline] |
Gets the strength of the opacity.
int SmokeSystem::getPrecisionX | ( | ) | const [inline] |
Gets the precision of the grid in the x direction.
int SmokeSystem::getPrecisionY | ( | ) | const [inline] |
Gets the precision of the grid in the y direction.
int SmokeSystem::getPrecisionZ | ( | ) | const [inline] |
Gets the precision of the grid in the z direction.
int SmokeSystem::getPressureIters | ( | ) | const [inline] |
Gets the pressure iterations.
float SmokeSystem::getRelaxationRate | ( | ) | const [inline] |
Gets the relaxation rate of the pressure.
float SmokeSystem::getShadowStrength | ( | ) | const [inline] |
Gets the strength of the shadow.
GLuint SmokeSystem::getTexID | ( | ) | const [inline] |
Gets the m_texID variable.
float SmokeSystem::getViscosity | ( | ) | const [inline] |
Gets the viscosity value.
void SmokeSystem::initGridValues | ( | ) |
This function initializes the voxel grid values/.
1. Initialize the values in the SmokeSystem class that are associated with the VoxelGrid instance (m_grid).
void SmokeSystem::initSmokeSpritePoints | ( | ) |
This function creates the smoke sprite points.
1. Initialize the smoke sprite data by adding a sprite for every voxel that is located at the center of the voxel.
void SmokeSystem::initSolidVoxels | ( | ) |
This function initializes the solid voxels based on the location of the obstacle's verticies.
1. Cycle through every vertex of the obstacle and set the voxel in which the vertex is located to a cell type of SOLID.
void SmokeSystem::initValues | ( | const float | _gridLengthX = 10.0 , |
const float | _gridLengthY = 10.0 , |
||
const float | _gridLengthZ = 10.0 , |
||
const int | _gridBaseRes = 10 |
||
) |
This function initializes the values. All of the initial values of the variables are in this function so this function can be called to reset all of the variables back to their default values.
[in] | _gridLengthX | the length of the grid in the x direction. |
[in] | _gridLengthY | the length of the grid in the y direction. |
[in] | _gridLengthY | the length of the grid in the z direction. |
[in] | _gridBaseRes | the base resolution of the grid. |
1. Initialize the voxel grid values.
2. Initialize the flags.
3. Initialize the fluid values.
4. Initialize the vorticity confinement values.
5. Initialize the pressure values.
6. Initialize the buoyancy force values.
7. Initialize the dissipation values.
8. Initialize the sprite values.
9. Initialize the emitter values.
10. Initialize the noise/turbulence values.
11. Initialize the solid voxels.
void SmokeSystem::initVelocityField | ( | ) |
This function creates the velocity field arrows.
1. Initialize the velocity field arrow data by adding 6 verticies per voxel to represent the arrows
bool SmokeSystem::isObstacle | ( | ) | const [inline] |
Gets the boolean value of whether or not there is an obstacle to draw.
void SmokeSystem::reset | ( | ) |
Resets the simulation by deleting and re-creating and re-initializing everything.
1. Remove the vertex array objects.
2. Re-create the vertex array objects.
3. Clear the vector of voxels.
4. Re-calculate the grid values.
5. Re-initialize the grid values.
6. Re-initialize the voxels.
7. Re-create the grid lines that show the edges of the voxel domain.
8. Re-initialize the smoke sprite point data.
9. Re-initialize the velocity field arrow data.
10. Re-initialize the solid voxels.
void SmokeSystem::setAbsoluteTolerance | ( | double | _val | ) | [inline] |
Sets the absolute tolerance for the pressure.
[in] | _val | the value to be set to the absolute tolerance value |
void SmokeSystem::setGravity | ( | double | _val | ) | [inline] |
Sets the gravity force.
[in] | _val | the value to be set to the gravity force |
void SmokeSystem::setGridBaseRes | ( | int | _res | ) |
Sets the base resolution of the voxel grid.
[in] | _res | the value to be set to the base resolution of the voxel grid |
1. Set the voxel grid base resolution and reset all of the data.
void SmokeSystem::setGridLengthX | ( | float | _length | ) |
Sets the x length of the voxel grid.
[in] | _length | the value to be set to the x length of the voxel grid |
1. Set the voxel grid length in the x direction and reset all of the data.
void SmokeSystem::setGridLengthY | ( | float | _length | ) |
Sets the y length of the voxel grid.
[in] | _length | the value to be set to the y length of the voxel grid |
1. Set the voxel grid length in the y direction and reset all of the data.
void SmokeSystem::setGridLengthZ | ( | float | _length | ) |
Sets the y length of the voxel grid.
[in] | _length | the value to be set to the z length of the voxel grid |
1. Set the voxel grid length in the z direction and reset all of the data.
void SmokeSystem::setH | ( | float | _val | ) |
Sets the width of the voxels.
[in] | _val | the value to be set to the width of the voxels |
1. Set voxel width and reset all of the data.
void SmokeSystem::setIsObstacle | ( | bool | _val | ) | [inline] |
Sets the boolean of whether or not there is an obstacle.
[in] | _val | the value to be set to the m_isObstacle variable |
void SmokeSystem::setKDensityDiss | ( | double | _val | ) | [inline] |
Sets the k density dissipation constant.
[in] | _val | the value to be set to the k density dissipation constant |
void SmokeSystem::setKFall | ( | double | _val | ) | [inline] |
Sets the k fall buoyancy constant.
[in] | _val | the value to be set to the k fall buoyancy constant |
void SmokeSystem::setKRise | ( | double | _val | ) | [inline] |
Sets the k rise buoyancy constant.
[in] | _val | the value to be set to the k rise buoyancy constant |
void SmokeSystem::setKTemperDiss | ( | float | _val | ) | [inline] |
Sets the k temperature dissipation constant.
[in] | _val | the value to be set to the k temperature dissipation constant |
void SmokeSystem::setKVorticity | ( | double | _val | ) | [inline] |
Sets the vorticity confinement constant.
[in] | _val | the value to be set to the vorticity confinement constant |
void SmokeSystem::setNoiseMagnitude | ( | float | _val | ) | [inline] |
Sets the magnitude of the force of the noise.
[in] | _val | the value to be set to the magnitude of the force of the noise |
void SmokeSystem::setNoiseSpeed | ( | float | _val | ) | [inline] |
Sets the speed of the noise.
[in] | _val | the value to be set to the speed of the noise |
void SmokeSystem::setOpacityStrength | ( | float | _val | ) | [inline] |
Sets the shadow strength.
[in] | _val | the value to be set to the shadow strength |
void SmokeSystem::setPrecisionX | ( | int | _precision | ) |
Sets the x precision of the voxel grid.
[in] | _precision | the value to be set to the x precision of the voxel grid |
1. Set voxel grid precision value in the x direction and reset all of the data.
void SmokeSystem::setPrecisionY | ( | int | _precision | ) |
Sets the y precision of the voxel grid.
[in] | _precision | the value to be set to the y precision of the voxel grid |
1. Set voxel grid precision value in the y direction and reset all of the data.
void SmokeSystem::setPrecisionZ | ( | int | _precision | ) |
Sets the z precision of the voxel grid.
[in] | _precision | the value to be set to the z precision of the voxel grid |
1. Set voxel grid precision value in the z direction and reset all of the data.
void SmokeSystem::setRelaxationRate | ( | double | _val | ) | [inline] |
Sets the relaxation rate for the pressure.
[in] | _val | the value to be set to the relaxation rate |
void SmokeSystem::setShadowStrength | ( | float | _val | ) | [inline] |
Sets the shadow strength.
[in] | _val | the value to be set to the shadow strength |
void SmokeSystem::setViscosity | ( | float | _val | ) | [inline] |
Sets the viscosity.
[in] | _val | the value to be set to the viscosity |
void SmokeSystem::update | ( | float | _dt, |
float | _time, | ||
bool | _showVelocityField | ||
) |
This function updates the smoke by performing all of the calculations.
[in] | _dt | The time step aka Δt |
[in] | _time | the time |
[in] | _showVelocityField | a flag to indicate whether or not the velocity field arrows are displayed. |
1. EMIT ENERGY.
2. APPLY BUOYANCY AND TURBULENCE FORCES.
3. CALCULATE AND APPLY VORTICITY FORCE.
5. ADVECT THE VELOCITY FIELD.
6. CALCULATE THE PRESSURE.
7. APPLY THE PRESSURE.
8. CONVECT THE ENERGY.
9. UPDATE THE VELOCITY FIELD ARROWS.
void SmokeSystem::updateSpriteVAO | ( | ) |
updates the sprite vertex array object
1. Update the sprite vertex array object with the new data.
void SmokeSystem::updateVelocityVAO | ( | ) |
updates the velocity arrow vertex array object
1. Update the velocity field arrow vertex array object with the new data.
void SmokeSystem::updateVelocityVAOData | ( | ) |
updates the velocity arrow data of the vertex array object
1. Update the velocity field data based on the new velocity field.
2. Calculate and update the base of the arrow.
3. Calculate and update the tip of the arrow.
4. Calculate and update the right wing tip of the arrow.
5. Calculate and update the left wing tip of the arrow.