Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GLViewer.h
Go to the documentation of this file.
1 /*
2 
3 License
4 
5 Menge
6 Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
7 All rights reserved.
8 
9 Permission to use, copy, modify, and distribute this software and its documentation
10 for educational, research, and non-profit purposes, without fee, and without a
11 written agreement is hereby granted, provided that the above copyright notice,
12 this paragraph, and the following four paragraphs appear in all copies.
13 
14 This software program and documentation are copyrighted by the University of North
15 Carolina at Chapel Hill. The software program and documentation are supplied "as is,"
16 without any accompanying services from the University of North Carolina at Chapel
17 Hill or the authors. The University of North Carolina at Chapel Hill and the
18 authors do not warrant that the operation of the program will be uninterrupted
19 or error-free. The end-user understands that the program was developed for research
20 purposes and is advised not to rely exclusively on the program for any reason.
21 
22 IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS
23 BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
24 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
25 DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
26 AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
29 DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY
31 OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
32 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS
33 TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
34 
35 Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
36 
37 */
38 
47 #ifndef __GLVIEWER_H__
48 #define __GLVIEWER_H__
49 
50 #include "SDL/SDL.h"
51 #include <string>
52 #include <vector>
53 
54 #include "CoreConfig.h"
55 #include "GLCamera.h"
56 #include "GLGroundPlane.h"
57 #include "GLScene.h"
58 #include "Profiler.h"
59 #include "ScreenGrab.h"
60 
61 namespace Menge {
62 
63  // Forward declarations
64  class Image;
65 
71  namespace Vis {
72 
73  // Forward declarations
74  class ViewConfig;
75  class Watermark;
76 
80  class MENGE_API GLViewer {
81  public:
88  GLViewer( int width, int height );
89 
95  GLViewer( ViewConfig & cfg );
96 
100  ~GLViewer(void);
101 
107  void run();
108 
115  bool setBGImage( const std::string & imgName );
116 
122  bool hasBGImage() const { return _bgImg != 0x0; }
123 
130  bool setWatermark( const std::string & imgName );
131 
137  bool hasWatermark() const { return _waterMark != 0x0; }
138 
142  void clearBGImage();
143 
150  bool initViewer( const std::string & title );
151 
158  void resizeGL( int w, int h );
159 
163  void initGL();
164 
172  void setScene( SceneGraph::GLScene * scene );
173 
178  void newGLContext();
179 
183  void drawGL();
184 
192  bool handleMouse( SDL_Event & e );
193 
201  bool handleKeyboard( SDL_Event & e );
202 
209  void setDrawWorldAxis( bool state ) { _drawWorldAxis = state; }
210 
216  bool getDrawWorldAxis() const { return _drawWorldAxis; }
217 
222  void drawRecordingFrame() const;
223 
231  void setCameraFOV( int i, float fov ) { _cameras[i].setFOV( fov ); }
232 
240  void setCameraFarPlane( int i, float dist ) { _cameras[i].setFarPlane( dist ); }
241 
248  void offsetTime( float delta );
254  void setTime( float t ) { _viewTime = t; };
255 
264  void setBGColor( float r, float g, float b );
265 
273  SceneGraph::GLCamera * getCamera( int i=0 ) { return &_cameras[i]; }
274 
281  void setFixedStep( float stepSize );
282 
288  void setDumpPath( const std::string & path );
289 
290  protected:
294  static Uint32 FLAGS;
295 
297  // members
298 
302  int _width;
303 
307  int _height;
308 
313 
317  std::vector< SceneGraph::GLCamera > _cameras;
318 
322  size_t _currCam;
323 
328  int _downX;
329 
334  int _downY;
335 
336  // HUD/UI components
337 
341  bool _update;
342 
347 
351  bool _showFPS;
352 
357 
361  bool _pause;
362 
367  bool _running;
368 
373  float _viewTime;
374 
379 
383  float _stepSize;
384 
389 
394 
399 
404 
408  std::string _dumpPath;
409 
414  size_t _imgCount;
415 
419  std::vector< SceneGraph::GLLight > _lights;
420 
424  void initLighting();
425 
427  // methods
428 
432  bool initSDL( const std::string & title );
433 
437  void drawWorldAxis() const;
438  };
439  } // namespace Vis
440 } // namespace Menge
441 #endif // __GLVIEWER_H__
Vector3 _bgColor
The viewer's background color.
Definition: GLViewer.h:378
bool _pause
Controls whether the viewer advances the GLScene (true) or not (false).
Definition: GLViewer.h:361
bool hasWatermark() const
Reports if the viewer has a watermark.
Definition: GLViewer.h:137
size_t _currCam
The index of camera currently being used to draw the scene.
Definition: GLViewer.h:322
SDL_Event SDL_Event
Forward declaration of the SDL event type.
Definition: Context.h:53
bool _drawWorldAxis
Determines whether a world-aligned axis is drawn.
Definition: GLViewer.h:346
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Class for defining an OpenGL Viewer.
Definition: GLViewer.h:80
Watermark * _waterMark
An optional watermark.
Definition: GLViewer.h:393
Sets up the proper compiler directives for platform and dll export/import.
std::vector< SceneGraph::GLCamera > _cameras
A set of cameras from which to draw the scene.
Definition: GLViewer.h:317
size_t _imgCount
The number of images which have been output. Used for labeling the image file names into a sequential...
Definition: GLViewer.h:414
The namespace containing visualization functionality for the pedestrian simulation.
Definition: GLViewer.h:64
int _height
The height of the viewer window (in pixels).
Definition: GLViewer.h:307
bool getDrawWorldAxis() const
Reports the state of whether the world axis is drawn or not.
Definition: GLViewer.h:216
void setCameraFOV(int i, float fov)
Sets the horizontal field of view for the ith camera.
Definition: GLViewer.h:231
bool hasBGImage() const
Reports if the viewer has a background image.
Definition: GLViewer.h:122
void setTime(float t)
Sets the current time.
Definition: GLViewer.h:254
bool _dumpImages
Determines if screen capture images will be output at each time advance.
Definition: GLViewer.h:398
void setCameraFarPlane(int i, float dist)
Sets the distance to the camera's far clipping plane.
Definition: GLViewer.h:240
The definition of a grid visualization of the ground plane.
SampleTimer _fpsDisplayTimer
A timer to determine the displayed frame rate value.
Definition: GLViewer.h:356
SceneGraph::GLCamera * getCamera(int i=0)
Gets a pointer to the ith camera.
Definition: GLViewer.h:273
float _stepSize
The step size for fixed-step simulation.
Definition: GLViewer.h:383
SceneGraph::GLScene * _scene
The GLScene to draw.
Definition: GLViewer.h:312
std::string _dumpPath
The path to the folder in which to write screen capture images.
Definition: GLViewer.h:408
void setDrawWorldAxis(bool state)
Sets whether the world axis is drawn or not.
Definition: GLViewer.h:209
A timer which uses a cache of values to only update its values every N calls to lap/elapsed. Useful for displaying frame rate.
Definition: Profiler.h:168
int _downY
The y-position of the mouse when a mouse button was depressed (in screen space).
Definition: GLViewer.h:334
The class which contains the entire drawable scene.
Definition: GLScene.h:72
The definition of the scene – the root of the directed, acyclic scene graph.
bool _update
Determines if the GLScene needs to update.
Definition: GLViewer.h:341
bool _validDumpPath
Reports if the screen capture output path is valid.
Definition: GLViewer.h:403
bool _running
Determines if the viewer should still operate – as long as it is true, it will continue its main loo...
Definition: GLViewer.h:367
int _width
The width of the viewer window (in pixels).
Definition: GLViewer.h:302
The class for controlling the view camera: it's position, orientation field of view, projection matrix, etc.
Definition: GLCamera.h:57
Functionality for timing and profiling the program.
bool _showFPS
Determines whether the frame rate is displayed in the viewer.
Definition: GLViewer.h:351
int _downX
The x-position of the mouse when a mouse button was depressed (in screen space).
Definition: GLViewer.h:328
Wrapper for the managed ImageData.
Definition: image.h:175
The specification of an OpenGL GLViewer for a scene.
Definition: ViewConfig.h:207
A class for handling the watermark functionality.
Definition: Watermark.h:74
std::vector< SceneGraph::GLLight > _lights
The set of lights to use in rendering.
Definition: GLViewer.h:419
float _viewTime
The current time at which the viewer is running. Modified by calls to GLViewer::setTime and GLViewer:...
Definition: GLViewer.h:373
Image * _bgImg
A pointer to the optional background image.
Definition: GLViewer.h:388
Functionality for capturing screen grabs to the file system.
Class to handle camera transformations in OpenGL.
static Uint32 FLAGS
The various SDL flags which determine the view.
Definition: GLViewer.h:294