Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00882_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00882_source.php on line 2
The ARGoS Website

qtopengl_widget.h
Go to the documentation of this file.
1 
7 #ifndef QTOPENGL_WIDGET_H
8 #define QTOPENGL_WIDGET_H
9 
10 namespace argos {
11  class CQTOpenGLWidget;
12  class CQTOpenGLMainWindow;
13  class CSpace;
14  class CSimulator;
15  class CQTOpenGLBox;
16  class CQTOpenGLUserFunctions;
17  class CPositionalEntity;
18  class CControllableEntity;
19  class CEmbodiedEntity;
20 }
21 
22 #include <argos3/plugins/simulator/visualizations/qt-opengl/qtopengl_camera.h>
23 #include <argos3/core/simulator/entity/entity.h>
24 #include <argos3/core/utility/datatypes/datatypes.h>
25 #include <QOpenGLWidget>
26 #include <QOpenGLFunctions>
27 #include <QOpenGLTexture>
28 
29 #ifdef __APPLE__
30 #include <glu.h>
31 #else
32 #include <GL/glu.h>
33 #endif
34 
35 namespace argos {
36 
37  /****************************************/
38  /****************************************/
39 
40  class CQTOpenGLOperationDrawNormal : public CEntityOperation<CQTOpenGLOperationDrawNormal, CQTOpenGLWidget, void> {
41  public:
43  };
44 
45  class CQTOpenGLOperationDrawSelected : public CEntityOperation<CQTOpenGLOperationDrawSelected, CQTOpenGLWidget, void> {
46  public:
48  };
49 
50 #define REGISTER_QTOPENGL_ENTITY_OPERATION(ACTION, OPERATION, ENTITY) \
51  REGISTER_ENTITY_OPERATION(ACTION, CQTOpenGLWidget, OPERATION, void, ENTITY);
52 
53  /****************************************/
54  /****************************************/
55 
56  class CQTOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions {
57 
58  Q_OBJECT
59 
60  public:
61 
65  struct SFrameGrabData {
66  bool Grabbing; // true when grabbing
67  QString Directory; // output directory
68  QString BaseName; // frame file basename
69  QString Format; // output file format
70  SInt32 Quality; // output quality [0-100]
71 
73  Grabbing(false),
74  Directory("."),
75  BaseName("frame_"),
76  Format("png"),
77  Quality(-1) {}
78 
79  void Init(TConfigurationNode& t_tree);
80  };
81 
85  struct SSelectionInfo {
86  bool IsSelected; // true when an entity is selected
87  CEntity* Entity; // the selected entity
88 
90  IsSelected(false),
91  Entity(NULL) {}
92  };
93 
94  public:
95 
102  CQTOpenGLWidget(QWidget* pc_parent,
103  CQTOpenGLMainWindow& c_main_window,
104  CQTOpenGLUserFunctions& c_user_functions);
108  virtual ~CQTOpenGLWidget();
109 
115  virtual void initializeGL();
116 
120  virtual void paintGL();
121 
126  CRay3 RayFromWindowCoord(int n_x,
127  int n_y);
128 
133  int n_y);
134 
140 
145  void SelectEntity(CEntity& c_entity);
146 
151  void DeselectEntity();
152 
158  void SelectInScene(UInt32 un_x,
159  UInt32 un_y);
160 
164  void DrawEntity(CPositionalEntity& c_entity);
165 
169  void DrawEntity(CEmbodiedEntity& c_entity);
170 
174  void DrawRays(CControllableEntity& c_entity);
175 
179  void DrawBoundingBox(CEmbodiedEntity& c_entity);
180 
184  inline virtual int heightForWidth(int w) const {
185  return (w * 3) / 4;
186  }
187 
191  inline virtual QSize sizeHint() const {
192  return QSize(1024,768);
193  }
194 
198  inline virtual QSize minimumSize() const {
199  return QSize(320,240);
200  }
201 
206  return m_cUserFunctions;
207  }
208 
213  return m_cCamera;
214  }
215 
220  return m_sFrameGrabData;
221  }
222 
226  inline void SetInvertMouse(bool b_InvertMouse) {
227  m_bInvertMouse = b_InvertMouse;
228  }
229 
230  signals:
231 
236  void StepDone(int n_step);
237 
243  void ExperimentDone();
244 
249  void EntitySelected(CEntity* pc_entity);
250 
255  void EntityDeselected(CEntity* pc_entity);
256 
257  public slots:
258 
264  void PlayExperiment();
265 
270  void FastForwardExperiment();
271 
277  void PauseExperiment();
278 
282  void StepExperiment();
283 
288  void ResetExperiment();
289 
293  void SetDrawFrameEvery(int n_every);
294 
298  void SetGrabFrame(bool b_grab_on);
299 
304  void SetCamera(int n_camera);
305 
310  void SetCameraFocalLength(double f_length);
311 
315  void KeyPressed(QKeyEvent* pc_event);
316 
320  void KeyReleased(QKeyEvent* pc_event);
321 
322  protected:
323 
324  void DrawScene();
325  void DrawArena();
326  void DrawAxes();
327 
328  virtual void timerEvent(QTimerEvent* pc_event);
329  virtual void mousePressEvent(QMouseEvent* pc_event);
330  virtual void mouseReleaseEvent(QMouseEvent* pc_event);
331  virtual void mouseMoveEvent(QMouseEvent* pc_event);
332  virtual void keyPressEvent(QKeyEvent* pc_event);
333  virtual void keyReleaseEvent(QKeyEvent* pc_event);
334  virtual void resizeEvent(QResizeEvent* pc_event);
335  void reactToKeyEvent();
336 
337  private:
338 
340  CQTOpenGLMainWindow& m_cMainWindow;
342  CQTOpenGLUserFunctions& m_cUserFunctions;
343 
345  SInt32 nTimerId;
347  bool m_bFastForwarding;
349  SInt32 m_nDrawFrameEvery;
351  SInt32 m_nFrameCounter;
352 
354  bool m_bMouseGrabbed;
356  bool m_bShiftPressed;
358  QPoint m_cMouseGrabPos;
360  bool m_bInvertMouse;
362  SSelectionInfo m_sSelectionInfo;
363 
365  CSimulator& m_cSimulator;
367  CSpace& m_cSpace;
368 
370  bool m_bUsingFloorTexture;
372  QOpenGLTexture* m_pcFloorTexture;
374  QOpenGLTexture* m_pcGroundTexture;
375 
377  GLfloat* m_pfLightAmbient;
379  GLfloat* m_pfLightDiffuse;
381  GLfloat* m_pfLight0Position;
383  GLfloat* m_pfLight1Position;
384 
386  GLuint m_unArenaList;
388  GLuint m_unFloorList;
389 
391  CQTOpenGLCamera m_cCamera;
393  SFrameGrabData m_sFrameGrabData;
394 
396  enum EDirection {
397  DIRECTION_UP = 1,
398  DIRECTION_DOWN,
399  DIRECTION_LEFT,
400  DIRECTION_RIGHT,
401  DIRECTION_FORWARDS,
402  DIRECTION_BACKWARDS,
403  };
404 
406  QMap<EDirection, int> m_mapPressedKeys;
407  };
408 
409 }
410 
411 #endif
CQTOpenGLCamera & GetCamera()
Returns a reference to the camera.
The QTOpenGL user functions.
signed int SInt32
32-bit signed integer.
Definition: datatypes.h:93
An entity that contains a pointer to the user-defined controller.
CQTOpenGLWidget(QWidget *pc_parent, CQTOpenGLMainWindow &c_main_window, CQTOpenGLUserFunctions &c_user_functions)
Class constructor.
A 3D vector class.
Definition: vector3.h:29
CQTOpenGLUserFunctions & GetUserFunctions()
Returns a reference to the user functions.
virtual void keyReleaseEvent(QKeyEvent *pc_event)
void EntityDeselected(CEntity *pc_entity)
Emitted when an entity is deselected.
void ExperimentDone()
Emitted when the experiment is finished.
The basic entity type.
Definition: entity.h:89
virtual void mouseReleaseEvent(QMouseEvent *pc_event)
virtual void keyPressEvent(QKeyEvent *pc_event)
CVector3 GetWindowCoordInWorld(int n_x, int n_y)
Returns the position in the world corresponding to the given window coordinate.
virtual QSize minimumSize() const
Called internally by Qt to know the minimum widget size.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
void KeyPressed(QKeyEvent *pc_event)
Handles key press events.
CEntity * GetSelectedEntity()
Returns the currently selected entity, or NULL if none is selected.
This entity is a link to a body in the physics engine.
void PauseExperiment()
Pauses the experiment.
void StepExperiment()
Executes one experiment time step.
void KeyReleased(QKeyEvent *pc_event)
Handles key release events.
void SetDrawFrameEvery(int n_every)
When fast-forwarding, sets every how many steps a frame must be drawn.
virtual QSize sizeHint() const
Called internally by Qt to know the preferred widget size.
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
virtual void paintGL()
Logic for scene drawing.
void SelectEntity(CEntity &c_entity)
Selects the passed entity.
Data regarding frame grabbing.
virtual int heightForWidth(int w) const
Called internally by Qt to set the aspect ratio.
CRay3 RayFromWindowCoord(int n_x, int n_y)
Casts a ray from the given window coordinate.
virtual void initializeGL()
Called when the GL context must be initialized.
SFrameGrabData & GetFrameGrabData()
Returns the current frame grabbing data.
virtual void mouseMoveEvent(QMouseEvent *pc_event)
void DeselectEntity()
Deselects the currently selected entity.
void SetCamera(int n_camera)
Sets the current camera in use.
void PlayExperiment()
Plays the experiment.
virtual void timerEvent(QTimerEvent *pc_event)
void ResetExperiment()
Resets the state of the experiment to its state right after initialization.
void FastForwardExperiment()
Fast forwards the experiment.
void SelectInScene(UInt32 un_x, UInt32 un_y)
Selects the entity closest to the camera at the given screen coordinates.
void SetInvertMouse(bool b_InvertMouse)
Sets whether the mouse should be inverted when moving.
void EntitySelected(CEntity *pc_entity)
Emitted when an entity is selected.
void SetGrabFrame(bool b_grab_on)
Toggles frame grabbing.
void DrawEntity(CPositionalEntity &c_entity)
Draws a positional entity.
The basic operation to be stored in the vtable.
Definition: entity.h:331
void DrawBoundingBox(CEmbodiedEntity &c_entity)
Draws the bounding box of an embodied entity.
virtual ~CQTOpenGLWidget()
Class destructor.
void SetCameraFocalLength(double f_length)
Sets the focal length of the current camera.
void DrawRays(CControllableEntity &c_entity)
Draws a ray.
void StepDone(int n_step)
Emitted whenever a time step has been executed.
void Init(TConfigurationNode &t_tree)
virtual void mousePressEvent(QMouseEvent *pc_event)
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
Data arelated to robot selection.
virtual void resizeEvent(QResizeEvent *pc_event)
The core class of ARGOS.
Definition: simulator.h:62