Waterflow
Visualize water in terrain
|
Main structure of the program. More...
#include <program.h>
Public Member Functions | |
Program (GLuint simCase) | |
Simple constructor that selects which type of simulation to use. | |
~Program () | |
Simple destructor that just cleans up. | |
void | checkKeys () |
Checks which keys are held down each iteration. | |
void | clean () |
Makes sure the program exits cleanly. | |
void | display () |
All rendering commands are sent here. | |
int | exec () |
Main entry for running the program. | |
void | handleEvent (SDL_Event *event) |
Takes care of all events since last main loop iteration. | |
void | handleKeypress (SDL_Event *event) |
Handles Keyboard presses that should only happen once. | |
void | handleMouseButton (SDL_Event *event) |
Get data from mouse click. | |
void | handleMouseMove (SDL_Event *event) |
Handles movements of the mouse. | |
bool | init () |
All one time initializations for the program is done here. | |
int | testVoxels () |
Run a test program for the voxelgrid. | |
void | timeUpdate () |
Updates the time. | |
void | update () |
Updates the simulation and camera. | |
Private Attributes | |
TwBar * | antBar |
Handle for AntTweakBar GUI window. | |
Camera * | cam |
Camera for moving in 3D. | |
GLfloat | currentTime |
Total time since program started. | |
DataHandler * | dataHandler |
Holds data about the terrain. | |
GLfloat | deltaTime |
Time for last frame. | |
GLuint | depthshader |
Shaders used for rendering a depthmap of the water. | |
GLfloat | dtSim |
dT to use in heightfield simulation | |
GLfloat | FPS |
Current frames per second (based on deltaTime) | |
SDL_GLContext | glcontext |
SDL openGL context. | |
float | heighAtClickProj |
Terrain/water height at the clicked position. | |
float | heightAtClickData |
Terrain height at the clicked position. | |
float | heightAtPos |
Terrain height at the comera position. | |
FileHandler * | heightData |
Water height data to save/load. | |
HeightField * | hf |
Heightfield for water simulation. | |
init_Data_struct * | init_data |
Holds data collected from XML. | |
bool | isRunning |
True as long as the program is running, set to false to quit. | |
bool | mouseHidden |
Bool to check if the mouse is hidden or not. | |
double | objX |
Terrain x coordinate at clicked position. | |
double | objZ |
Terrain z coordinate at clicked position. | |
SDL_Window * | screen |
Handle for the SDL window. | |
int | screenH |
Screen height. | |
int | screenW |
Screen width. | |
ShallowGPU * | sgpu |
Shallow water simulation. | |
GLuint | shallowwatershader |
Shaders used for rendering water in the shallow water simulation. | |
bool | sim |
Determines if the simulation is paused or not. | |
GLuint | simCase |
Which simulation is to be run. | |
myDrawable * | skycube |
Skycube model. | |
GLuint | skyshader |
Shaders used for rendering the skybox. | |
myDrawable * | terrain |
Terrain model. | |
GLuint | terrainshader |
Shaders used for rendering terrain. | |
FileHandler * | velocityData |
Water velocity data to save/load. | |
Voxelgrid * | voxs |
A voxelgrid, not currently used. | |
GLuint | watershader |
Shaders used for rendering the water. | |
myDrawable * | waterTerrain |
Water model. |
Main structure of the program.
This is where the broad strokes of the program should be outlined. Contains the main loop of the program and funtions for the different phases.
Program::Program | ( | GLuint | simCase | ) |
Simple constructor that selects which type of simulation to use.
simCase | Selected simulation method (1 = heightfield, 2 = shallowWater) |
Definition at line 12 of file program.cpp.
void Program::checkKeys | ( | ) |
Checks which keys are held down each iteration.
This is for events that requires buttons to be held down for longer periods of time. Currently used mainly for moving the camera around in the 3D environment. For single event keypresses use handleKeypress()
Definition at line 414 of file program.cpp.
void Program::clean | ( | ) |
Makes sure the program exits cleanly.
Closes the SDL OpenGL context correctly and closes the AntTweakBar.
Definition at line 300 of file program.cpp.
void Program::display | ( | ) |
All rendering commands are sent here.
Sends the rendering commands to all drawables and uploads the camera uniforms to the programs.
Definition at line 261 of file program.cpp.
int Program::exec | ( | ) |
Main entry for running the program.
Contains the main loop for the program and the structure of which order the program phases comes in.
Definition at line 33 of file program.cpp.
void Program::handleEvent | ( | SDL_Event * | event | ) |
Takes care of all events since last main loop iteration.
Looks at all events and either takes care of the more uncommon ones like screen events and quit events. Passes the other events along to the appropriate handler.
event | An event to be processed |
Definition at line 308 of file program.cpp.
void Program::handleKeypress | ( | SDL_Event * | event | ) |
Handles Keyboard presses that should only happen once.
Define events here when a single event should be generated from a keyboard press. For held down key events look at checkKeys() instead.
event | An event to be processed |
Definition at line 343 of file program.cpp.
void Program::handleMouseButton | ( | SDL_Event * | event | ) |
Get data from mouse click.
Callback funciton for left mouse button. Retrieves x and y ((0, 0) is upper left corner from this function) of mouse. glReadPixels is used to retrieve Z-values from depth buffer. Here width-y is passed to comply with OpenGL implementation. glGetIntegerv retrievs values of Viewport matrix to pass to gluUnProject later. gluUnProject retrievs the original model coordinates from screen coordinates and Z-value. objY contains terrain height at clicked position after gluUnProject.
event | An event to be processed |
Definition at line 396 of file program.cpp.
void Program::handleMouseMove | ( | SDL_Event * | event | ) |
Handles movements of the mouse.
Rotates the camera if the mouse pointer is hidden otherwise it just passes the movements to AntTweakBar so that it is possible to interact with the GUI.
event | An event to be processed |
Definition at line 389 of file program.cpp.
bool Program::init | ( | ) |
All one time initializations for the program is done here.
The openGL context is created and all objects should be created and initialized here. If the init does not return true the program exits. Currently this only happens if the OpenGL context fails to initialize in some way.
Definition at line 60 of file program.cpp.
void Program::timeUpdate | ( | ) |
Updates the time.
Calculates the last frame time and updates the FPS and current time. This is not part of update since we want the same time delta for events as for the update.
Definition at line 227 of file program.cpp.
void Program::update | ( | ) |
Updates the simulation and camera.
This is where the simulation is updated currently. After the simulation the model for the water is updated.
Definition at line 234 of file program.cpp.