Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Menge::Vis::GLViewer Class Reference

Class for defining an OpenGL Viewer. More...

#include <GLViewer.h>

Public Member Functions

 GLViewer (int width, int height)
 Default constructor based on preferred viewer size. More...
 
 GLViewer (ViewConfig &cfg)
 Constructor based on configuration in a ViewConfig instance. More...
 
 ~GLViewer (void)
 Destructor.
 
void run ()
 Runs the main loop – including advancing the scene in time. Exiting this function means the main event loop is no longer running.
 
bool setBGImage (const std::string &imgName)
 Sets the optional background image to the viewer. More...
 
bool hasBGImage () const
 Reports if the viewer has a background image. More...
 
bool setWatermark (const std::string &imgName)
 Sets the watermark to the viewer. More...
 
bool hasWatermark () const
 Reports if the viewer has a watermark. More...
 
void clearBGImage ()
 Clears the background image from the viewer.
 
bool initViewer (const std::string &title)
 Initializes the viewer with the given title. More...
 
void resizeGL (int w, int h)
 Resizes the window to the indicated size. More...
 
void initGL ()
 Initializes the opengl mechanism.
 
void setScene (SceneGraph::GLScene *scene)
 Sets the GLScene to be drawn. A viewer can only draw a single scene; all drawn elements belong either to the GLScene or a GLContext. More...
 
void newGLContext ()
 Causes the viewer to recognize that a new OpenGL context has been created (such as window resizes).
 
void drawGL ()
 Main drawing function – draws scene and context as available.
 
bool handleMouse (SDL_Event &e)
 Processes a mouse event. More...
 
bool handleKeyboard (SDL_Event &e)
 Processes a keyboard event. More...
 
void setDrawWorldAxis (bool state)
 Sets whether the world axis is drawn or not. More...
 
bool getDrawWorldAxis () const
 Reports the state of whether the world axis is drawn or not. More...
 
void drawRecordingFrame () const
 Draws a red frame around the viewer, indicating that images are being saved.
 
void setCameraFOV (int i, float fov)
 Sets the horizontal field of view for the ith camera. More...
 
void setCameraFarPlane (int i, float dist)
 Sets the distance to the camera's far clipping plane. More...
 
void offsetTime (float delta)
 Change the scene time by the given offset. More...
 
void setTime (float t)
 Sets the current time. More...
 
void setBGColor (float r, float g, float b)
 Sets the view's background color. This must be called AFTER the view has been initialized. More...
 
SceneGraph::GLCameragetCamera (int i=0)
 Gets a pointer to the ith camera. More...
 
void setFixedStep (float stepSize)
 Sets the simulator to use a fixed time step, with the given value. More...
 
void setDumpPath (const std::string &path)
 Sets the path for when outputting screen capture images. More...
 

Protected Member Functions

void initLighting ()
 Initizlies the OpenGL lighting based on the set of lights.
 
bool initSDL (const std::string &title)
 Initializes the SDL mechanism for event handling and context creation.
 
void drawWorldAxis () const
 Draws a simple, three-color world axis at the origin of world space.
 

Protected Attributes

int _width
 The width of the viewer window (in pixels).
 
int _height
 The height of the viewer window (in pixels).
 
SceneGraph::GLScene_scene
 The GLScene to draw.
 
std::vector< SceneGraph::GLCamera_cameras
 A set of cameras from which to draw the scene.
 
size_t _currCam
 The index of camera currently being used to draw the scene.
 
int _downX
 The x-position of the mouse when a mouse button was depressed (in screen space).
 
int _downY
 The y-position of the mouse when a mouse button was depressed (in screen space).
 
bool _update
 Determines if the GLScene needs to update.
 
bool _drawWorldAxis
 Determines whether a world-aligned axis is drawn.
 
bool _showFPS
 Determines whether the frame rate is displayed in the viewer.
 
SampleTimer _fpsDisplayTimer
 A timer to determine the displayed frame rate value.
 
bool _pause
 Controls whether the viewer advances the GLScene (true) or not (false).
 
bool _running
 Determines if the viewer should still operate – as long as it is true, it will continue its main loop (. More...
 
float _viewTime
 The current time at which the viewer is running. Modified by calls to GLViewer::setTime and GLViewer::offsetTime.
 
Vector3 _bgColor
 The viewer's background color.
 
float _stepSize
 The step size for fixed-step simulation.
 
Image_bgImg
 A pointer to the optional background image.
 
Watermark_waterMark
 An optional watermark.
 
bool _dumpImages
 Determines if screen capture images will be output at each time advance.
 
bool _validDumpPath
 Reports if the screen capture output path is valid.
 
std::string _dumpPath
 The path to the folder in which to write screen capture images.
 
size_t _imgCount
 The number of images which have been output. Used for labeling the image file names into a sequential order.
 
std::vector< SceneGraph::GLLight_lights
 The set of lights to use in rendering.
 

Static Protected Attributes

static Uint32 FLAGS = SDL_OPENGL | SDL_DOUBLEBUF | SDL_RESIZABLE
 The various SDL flags which determine the view.
 

Detailed Description

Class for defining an OpenGL Viewer.

Constructor & Destructor Documentation

Menge::Vis::GLViewer::GLViewer ( int  width,
int  height 
)

Default constructor based on preferred viewer size.

Parameters
widthThe width of the view window, in pixels.
heightThe height of the view window, in pixels.
Menge::Vis::GLViewer::GLViewer ( ViewConfig cfg)

Constructor based on configuration in a ViewConfig instance.

Parameters
cfgA fully specified view configuration.

Member Function Documentation

SceneGraph::GLCamera* Menge::Vis::GLViewer::getCamera ( int  i = 0)
inline

Gets a pointer to the ith camera.

Parameters
iThe index of the desired camera. The index value is not checked.
Returns
A pointer to the ith camera.
bool Menge::Vis::GLViewer::getDrawWorldAxis ( ) const
inline

Reports the state of whether the world axis is drawn or not.

Returns
A boolean indicating if the world axis is drawn (true) or not (false).
bool Menge::Vis::GLViewer::handleKeyboard ( SDL_Event e)

Processes a keyboard event.

Parameters
eAn SDL_Event corresponding with an appropriate SDL keyboard event (key up/down).
Returns
A boolean indicating if a scene redraw is necessary (true) or not (false).
bool Menge::Vis::GLViewer::handleMouse ( SDL_Event e)

Processes a mouse event.

Parameters
eAn SDL_Event corresponding with an appropriate SDL mouse event (button up/down, move).
Returns
A boolean indicating if a scene redraw is necessary (true) or not (false).

This scale should be the size of a pixel at the target depth

bool Menge::Vis::GLViewer::hasBGImage ( ) const
inline

Reports if the viewer has a background image.

Returns
True if there is a background image, false otherwise.
bool Menge::Vis::GLViewer::hasWatermark ( ) const
inline

Reports if the viewer has a watermark.

Returns
True if there is a watermark, false otherwise.
bool Menge::Vis::GLViewer::initViewer ( const std::string &  title)

Initializes the viewer with the given title.

Parameters
titleThe name displayed at the top of the window.
Returns
True if initialization was successful, false otherwise.
void Menge::Vis::GLViewer::offsetTime ( float  delta)

Change the scene time by the given offset.

Parameters
deltaThe amount of time change. Can be negative, but only meaningful if the GLScene can support negative time changes.
void Menge::Vis::GLViewer::resizeGL ( int  w,
int  h 
)

Resizes the window to the indicated size.

Parameters
wThe new width of the viewer window.
hThe new height of the viewer window.
void Menge::Vis::GLViewer::setBGColor ( float  r,
float  g,
float  b 
)

Sets the view's background color. This must be called AFTER the view has been initialized.

Parameters
rThe red component of the background color (must be in the range [0, 1]).
gThe green component of the background color (must be in the range [0, 1]).
bThe blue component of the background color (must be in the range [0, 1]).
bool Menge::Vis::GLViewer::setBGImage ( const std::string &  imgName)

Sets the optional background image to the viewer.

Parameters
imgNameA valid path to a valid image to load.
Returns
A boolean reporting success (true) or failure (false).
void Menge::Vis::GLViewer::setCameraFarPlane ( int  i,
float  dist 
)
inline

Sets the distance to the camera's far clipping plane.

Parameters
iThe index of the camera - index value is NOT checked.
distThe distance, from the camera, to its far clipping plane. Value is not validated.
void Menge::Vis::GLViewer::setCameraFOV ( int  i,
float  fov 
)
inline

Sets the horizontal field of view for the ith camera.

Parameters
iThe index of the camera - index value is NOT checked.
fovThe horizontal field of view for the indicated camera. Value is not validated.
void Menge::Vis::GLViewer::setDrawWorldAxis ( bool  state)
inline

Sets whether the world axis is drawn or not.

Parameters
stateA boolean controlling whether the world axis is drawn (true) or not (false).
void Menge::Vis::GLViewer::setDumpPath ( const std::string &  path)

Sets the path for when outputting screen capture images.

Parameters
pathThe path to which output images should be written.
void Menge::Vis::GLViewer::setFixedStep ( float  stepSize)

Sets the simulator to use a fixed time step, with the given value.

Parameters
stepSizeThe size of the fixed step the viewer should advance its GLScene.
void Menge::Vis::GLViewer::setScene ( SceneGraph::GLScene scene)

Sets the GLScene to be drawn. A viewer can only draw a single scene; all drawn elements belong either to the GLScene or a GLContext.

Parameters
sceneThe GLScene to be rendered and temporally advanced.
void Menge::Vis::GLViewer::setTime ( float  t)
inline

Sets the current time.

Parameters
tThe current time for the viewer and its GLScene.
bool Menge::Vis::GLViewer::setWatermark ( const std::string &  imgName)

Sets the watermark to the viewer.

Parameters
imgNameA valid path to a valid image to load.
Returns
A boolean reporting success (true) or failure (false).

Member Data Documentation

bool Menge::Vis::GLViewer::_running
protected

Determines if the viewer should still operate – as long as it is true, it will continue its main loop (.

See also
GLViewer::run).

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