ARGoS  3
A parallel, multi-engine simulator for swarm robotics
qtopengl_widget.cpp
Go to the documentation of this file.
1 
7 #include "qtopengl_widget.h"
8 #include "qtopengl_main_window.h"
10 
11 #include <argos3/core/utility/logging/argos_log.h>
12 #include <argos3/core/utility/math/plane.h>
13 #include <argos3/core/simulator/simulator.h>
14 #include <argos3/core/simulator/loop_functions.h>
15 #include <argos3/core/simulator/space/space.h>
16 #include <argos3/core/simulator/entity/floor_entity.h>
17 #include <argos3/core/simulator/entity/composable_entity.h>
18 #include <argos3/core/simulator/entity/positional_entity.h>
19 
20 #include <QDir>
21 #include <QToolTip>
22 #include <QTimerEvent>
23 #include <QMouseEvent>
24 #include <QPainter>
25 
26 #ifndef GL_MULTISAMPLE
27 #define GL_MULTISAMPLE 0x809D
28 #endif
29 
30 namespace argos {
31 
32  static const Real ASPECT_RATIO = 4.0f / 3.0f;
33  static const UInt32 SELECT_BUFFER_SIZE = 128;
34 
35  /****************************************/
36  /****************************************/
37 
39  CQTOpenGLMainWindow& c_main_window,
40  CQTOpenGLUserFunctions& c_user_functions) :
41  QOpenGLWidget(pc_parent),
42  m_cMainWindow(c_main_window),
43  m_cUserFunctions(c_user_functions),
44  nTimerId(-1),
45  m_bFastForwarding(false),
46  m_nDrawFrameEvery(1),
47  m_nFrameCounter(0),
48  m_bMouseGrabbed(false),
49  m_bShiftPressed(false),
50  m_bInvertMouse(false),
51  m_cSimulator(CSimulator::GetInstance()),
52  m_cSpace(m_cSimulator.GetSpace()),
53  m_bUsingFloorTexture(false),
54  m_pcFloorTexture(NULL),
55  m_pcGroundTexture(NULL),
56  m_punSelectionBuffer(new GLuint[SELECT_BUFFER_SIZE])
57  {
58  /* Set the widget's size policy */
59  QSizePolicy cSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
60  cSizePolicy.setHeightForWidth(true);
61  setSizePolicy(cSizePolicy);
62  /* Grab focus when clicked on */
63  setFocusPolicy(Qt::ClickFocus);
64  /* Force size and geometry */
65  updateGeometry();
66  /* Keys */
67  m_mapPressedKeys[DIRECTION_UP] = false;
68  m_mapPressedKeys[DIRECTION_DOWN] = false;
69  m_mapPressedKeys[DIRECTION_LEFT] = false;
70  m_mapPressedKeys[DIRECTION_RIGHT] = false;
71  m_mapPressedKeys[DIRECTION_FORWARDS] = false;
72  m_mapPressedKeys[DIRECTION_BACKWARDS] = false;
73  }
74 
75  /****************************************/
76  /****************************************/
77 
79  makeCurrent();
80  delete m_pcGroundTexture;
81  glDeleteLists(1, m_unArenaList);
82  if(m_bUsingFloorTexture) {
83  delete m_pcFloorTexture;
84  glDeleteLists(1, m_unFloorList);
85  }
86  delete[] m_punSelectionBuffer;
87  doneCurrent();
88  }
89 
90  /****************************************/
91  /****************************************/
92 
94  /* Initializes the openGL functions */
95  initializeOpenGLFunctions();
96  /* Set clear color */
97  glClearColor(0, .5, .5, 255); // dark cyan
98  /* Set up the texture parameters for the floor plane
99  (here we refer to the standard floor, not the floor entity) */
100  m_pcGroundTexture = new QOpenGLTexture(QImage(m_cMainWindow.GetTextureDir() + "/ground.png"));
101  m_pcGroundTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,
102  QOpenGLTexture::Linear);
103 #ifdef ARGOS_WITH_FREEIMAGE
104  /* Now take care of the floor entity */
105  try {
106  /* Create an image to use as texture */
107  m_cSpace.GetFloorEntity().SaveAsImage("/tmp/argos_floor.png");
108  m_bUsingFloorTexture = true;
109  /* Use the image as texture */
110  m_pcFloorTexture = new QOpenGLTexture(QImage("/tmp/argos_floor.png"));
111  m_pcFloorTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,
112  QOpenGLTexture::Linear);
113  m_cSpace.GetFloorEntity().ClearChanged();
114  }
115  catch(CARGoSException& ex) {}
116 #endif
117  /* Nicest hints */
118  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
119  glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);
120  /* Setup lighting */
121  GLfloat pfLightAmbient[] = { .2, .2, .2, 1. };
122  GLfloat pfLightDiffuse[] = { .8, .8, .8, 1. };
123  GLfloat pfLightPosition[] = { 50. , 50. , 2. , 1. };
124  glLightfv(GL_LIGHT0, GL_AMBIENT, pfLightAmbient);
125  glLightfv(GL_LIGHT0, GL_DIFFUSE, pfLightDiffuse);
126  glLightfv(GL_LIGHT0, GL_POSITION, pfLightPosition);
127  glEnable(GL_LIGHT0);
128  }
129 
130  /****************************************/
131  /****************************************/
132 
134  /* Clear accumulator buffer */
135  glClearAccum(0.0, 0.0, 0.0, 0.0);
136  /* Clear color buffer and depth buffer */
137  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
138  /* Smooth lines and shades */
139  glEnable(GL_LINE_SMOOTH);
140  glShadeModel(GL_SMOOTH);
141  /* Enable depth testing */
142  glEnable(GL_DEPTH_TEST);
143  /* Enable face culling */
144  glEnable(GL_CULL_FACE);
145  /* Enable lighting */
146  glEnable(GL_LIGHTING);
147  /* Calculate the perspective matrix */
148  glMatrixMode(GL_PROJECTION);
149  glLoadIdentity();
150  gluPerspective(m_cCamera.GetActiveSettings().YFieldOfView.GetValue(),
151  ASPECT_RATIO,
152  0.1f, 1000.0f);
153  /* Place the camera */
154  glMatrixMode(GL_MODELVIEW);
155  glLoadIdentity();
156  m_cCamera.Look();
157  /* Draw the arena */
158  DrawArena();
159  /* Draw the objects */
160  CEntity::TVector& vecEntities = m_cSpace.GetRootEntityVector();
161  for(CEntity::TVector::iterator itEntities = vecEntities.begin();
162  itEntities != vecEntities.end();
163  ++itEntities) {
164  glPushMatrix();
165  CallEntityOperation<CQTOpenGLOperationDrawNormal, CQTOpenGLWidget, void>(*this, **itEntities);
166  m_cUserFunctions.Call(**itEntities);
167  glPopMatrix();
168  }
169  /* Draw the selected object, if necessary */
170  if(m_sSelectionInfo.IsSelected) {
171  glPushMatrix();
172  CallEntityOperation<CQTOpenGLOperationDrawSelected, CQTOpenGLWidget, void>(*this, *vecEntities[m_sSelectionInfo.Index]);
173  glPopMatrix();
174  }
175  /* Draw in world */
176  glPushMatrix();
177  m_cUserFunctions.DrawInWorld();
178  glPopMatrix();
179  /* Draw axes */
180  DrawAxes();
181  /* Draw selection ray for debug */
182  glDisable(GL_LIGHTING);
183  glLineWidth(1.0f);
184  glBegin(GL_LINES);
185  glColor3f(1.0, 0.0, 0.0);
186  const CVector3& cStart = m_cSelectionRay.GetStart();
187  const CVector3& cEnd = m_cSelectionRay.GetEnd();
188  glVertex3f(cStart.GetX(), cStart.GetY(), cStart.GetZ());
189  glVertex3f(cEnd.GetX(), cEnd.GetY(), cEnd.GetZ());
190  glEnd();
191  glEnable(GL_LIGHTING);
192  /* Execute overlay drawing */
193  glShadeModel(GL_FLAT);
194  glDisable(GL_LIGHTING);
195  glDisable(GL_CULL_FACE);
196  glDisable(GL_DEPTH_TEST);
197  glMatrixMode(GL_MODELVIEW);
198  QPainter cPainter(this);
199  cPainter.setRenderHint(QPainter::Antialiasing);
200  cPainter.setRenderHint(QPainter::TextAntialiasing);
201  m_cUserFunctions.DrawOverlay(cPainter);
202  // cPainter.drawText(rect(), QString("%1 FPS").arg(m_fFPS, 0, 'f', 0));
203  cPainter.end();
204  /* Grab frame, if necessary */
205  if(m_sFrameGrabData.Grabbing) {
206  QString strFileName = QString("%1/%2%3.%4")
207  .arg(m_sFrameGrabData.Directory)
208  .arg(m_sFrameGrabData.BaseName)
209  .arg(m_cSpace.GetSimulationClock(), 5, 10, QChar('0'))
210  .arg(m_sFrameGrabData.Format);
211  QToolTip::showText(pos() + geometry().center(), "Stored frame to \"" + strFileName);
212  grabFramebuffer()
213  .save(
214  strFileName,
215  0,
216  m_sFrameGrabData.Quality);
217  }
218  }
219 
220  /****************************************/
221  /****************************************/
222 
224  int n_y) {
225  /* Make sure OpenGL context is correct */
226  makeCurrent();
227  /* Rescale coordinates by devicePixelRatio */
228  n_x *= devicePixelRatio();
229  n_y *= devicePixelRatio();
230  /* Get current viewport */
231  GLint nViewport[4];
232  glGetIntegerv(GL_VIEWPORT, nViewport);
233  /* Get OpenGL matrices */
234  GLdouble fModelViewMatrix[16];
235  GLdouble fProjectionMatrix[16];
236  glGetDoublev(GL_MODELVIEW_MATRIX, fModelViewMatrix);
237  glGetDoublev(GL_PROJECTION_MATRIX, fProjectionMatrix);
238  /*
239  * Convert mouse position in window into OpenGL representation
240  */
241  /* The x coordinate stays the same */
242  GLfloat fWinX = n_x;
243  /* The y coordinate of the window is top-left; in OpenGL is bottom-left */
244  GLfloat fWinY = nViewport[3] - n_y;
245  /*
246  * Get the position of the ray start in the world
247  * The ray starts at the near clipping plane (depth = 0.0f)
248  */
249  GLdouble fRayStartX, fRayStartY, fRayStartZ;
250  gluUnProject(fWinX, fWinY, 0.0f,
251  fModelViewMatrix, fProjectionMatrix, nViewport,
252  &fRayStartX, &fRayStartY, &fRayStartZ);
253  /*
254  * Get the position of the ray end in the world
255  * The ray starts at the far clipping plane (depth = 1.0f)
256  */
257  GLdouble fRayEndX, fRayEndY, fRayEndZ;
258  gluUnProject(fWinX, fWinY, 1.0f,
259  fModelViewMatrix, fProjectionMatrix, nViewport,
260  &fRayEndX, &fRayEndY, &fRayEndZ);
261  doneCurrent();
262  return CRay3(CVector3(fRayStartX, fRayStartY, fRayStartZ),
263  CVector3(fRayEndX, fRayEndY, fRayEndZ));
264  }
265 
266  /****************************************/
267  /****************************************/
268 
270  int n_y) {
271  /* Make sure OpenGL context is correct */
272  makeCurrent();
273  /* Rescale coordinates by devicePixelRatio */
274  n_x *= devicePixelRatio();
275  n_y *= devicePixelRatio();
276  /* Get current viewport */
277  GLint nViewport[4];
278  glGetIntegerv(GL_VIEWPORT, nViewport);
279  /* Get OpenGL matrices */
280  GLdouble fModelViewMatrix[16];
281  GLdouble fProjectionMatrix[16];
282  glGetDoublev(GL_MODELVIEW_MATRIX, fModelViewMatrix);
283  glGetDoublev(GL_PROJECTION_MATRIX, fProjectionMatrix);
284  /*
285  * Convert mouse position in window into a 3D representation
286  */
287  /* The x coordinate stays the same */
288  GLfloat fWinX = n_x;
289  /* The y coordinate of the window is top-left; in OpenGL is bottom-left */
290  GLfloat fWinY = nViewport[3] - n_y;
291  /* Read the z coordinate from the depth buffer in the back buffer */
292  GLfloat fWinZ;
293  glReadBuffer(GL_BACK);
294  glReadPixels(n_x, (GLint)fWinY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &fWinZ);
295  /* Get the actual position in the world */
296  GLdouble fWorldX, fWorldY, fWorldZ;
297  gluUnProject(fWinX, fWinY, fWinZ,
298  fModelViewMatrix, fProjectionMatrix, nViewport,
299  &fWorldX, &fWorldY, &fWorldZ);
300  /*
301  * Swap coordinates when creating the ray
302  * In ARGoS, the up vector is the Z-axis, while in OpenGL it is the Y-axis
303  */
304  doneCurrent();
305  return CVector3(fWorldX, fWorldZ, fWorldY);
306  }
307 
308  /****************************************/
309  /****************************************/
310 
312  return (m_sSelectionInfo.IsSelected ?
313  m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index] :
314  NULL);
315  }
316 
317  /****************************************/
318  /****************************************/
319 
321  /* Look for the idx corresponding to the entity */
322  size_t unIdx = 0;
323  while(m_cSpace.GetRootEntityVector()[unIdx] != &c_entity)
324  ++unIdx;
325  /* Check whether an entity had previously been selected */
326  if(m_sSelectionInfo.IsSelected) {
327  /* An entity had previously been selected */
328  /* Is that entity already selected? */
329  if(m_sSelectionInfo.Index == unIdx) return;
330  /* Deselect the previous one */
331  emit EntityDeselected(m_sSelectionInfo.Index);
332  m_cUserFunctions.EntityDeselected(
333  *m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index]);
334  }
335  else {
336  /* No entity had previously been selected */
337  m_sSelectionInfo.IsSelected = true;
338  }
339  /* Select the new entity */
340  m_sSelectionInfo.Index = unIdx;
341  emit EntitySelected(unIdx);
342  m_cUserFunctions.EntitySelected(
343  *m_cSpace.GetRootEntityVector()[unIdx]);
344  update();
345  }
346 
347  /****************************************/
348  /****************************************/
349 
351  /* If no entity was selected, nothing to do */
352  if(!m_sSelectionInfo.IsSelected) return;
353  /* Deselect the entity */
354  emit EntityDeselected(m_sSelectionInfo.Index);
355  m_cUserFunctions.EntityDeselected(
356  *m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index]);
357  m_sSelectionInfo.IsSelected = false;
358  update();
359  }
360 
361  /****************************************/
362  /****************************************/
363 
365  UInt32 un_y) {
366  /* Make sure OpenGL context is correct */
367  makeCurrent();
368  un_x *= devicePixelRatio();
369  un_y *= devicePixelRatio();
370  /* Used to store the viewport size */
371  GLint nViewport[4];
372  /* Set the selection buffer */
373  glSelectBuffer(SELECT_BUFFER_SIZE, m_punSelectionBuffer);
374  /* Switch to select mode */
375  glRenderMode(GL_SELECT);
376  /* Set the projection matrix */
377  glMatrixMode(GL_PROJECTION);
378  glLoadIdentity();
379  /* Set the viewport */
380  glGetIntegerv(GL_VIEWPORT, nViewport);
381  gluPickMatrix(un_x,
382  nViewport[3]-un_y,
383  5, 5,
384  nViewport);
385  gluPerspective(m_cCamera.GetActiveSettings().YFieldOfView.GetValue(),
386  ASPECT_RATIO,
387  0.1f, 1000.0f);
388  glMatrixMode(GL_MODELVIEW);
389  glLoadIdentity();
390  m_cCamera.Look();
391  /* Prepare name stack */
392  glInitNames();
393  /* Draw the objects */
394  CEntity::TVector& vecEntities = m_cSpace.GetRootEntityVector();
395  for(size_t i = 0; i < vecEntities.size(); ++i) {
396  glPushName(i);
397  glPushMatrix();
398  CallEntityOperation<CQTOpenGLOperationDrawNormal, CQTOpenGLWidget, void>(*this, *vecEntities[i]);
399  glPopMatrix();
400  glPopName();
401  }
402  glFlush();
403  /* Return to normal rendering mode and get hit count */
404  bool bWasSelected = m_sSelectionInfo.IsSelected;
405  UInt32 unHits = glRenderMode(GL_RENDER);
406  if (unHits == 0) {
407  /* No hits, deselect what was selected */
408  m_sSelectionInfo.IsSelected = false;
409  if(bWasSelected) {
410  emit EntityDeselected(m_sSelectionInfo.Index);
411  m_cUserFunctions.EntityDeselected(
412  *m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index]);
413  }
414  }
415  else {
416  /* There are hits!
417  * Process them, keeping the closest hit
418  */
419  GLuint* punByte = m_punSelectionBuffer;
420  GLuint unMinZ = 0xffffffff;
421  GLuint* punName = NULL;
422  for (UInt32 i = 0; i < unHits; i++) {
423  GLuint unNames = *punByte;
424  ++punByte;
425  if (*punByte < unMinZ) {
426  unMinZ = *punByte;
427  punName = punByte+2;
428  }
429  punByte += unNames+2;
430  }
431  /* Now *punName contains the closest hit */
432  if(bWasSelected &&
433  (m_sSelectionInfo.Index == *punName)) {
434  /* The user clicked on the selected entity, deselect it */
435  emit EntityDeselected(m_sSelectionInfo.Index);
436  m_sSelectionInfo.IsSelected = false;
437  m_cUserFunctions.EntitySelected(
438  *m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index]);
439  }
440  if(bWasSelected &&
441  (m_sSelectionInfo.Index != *punName)) {
442  /* The user clicked on a different entity from the selected one */
443  emit EntityDeselected(m_sSelectionInfo.Index);
444  m_cUserFunctions.EntityDeselected(
445  *m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index]);
446  m_sSelectionInfo.Index = *punName;
447  emit EntitySelected(m_sSelectionInfo.Index);
448  m_cUserFunctions.EntitySelected(
449  *m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index]);
450  }
451  else {
452  /* There was nothing selected, and the user clicked on an entity */
453  m_sSelectionInfo.IsSelected = true;
454  m_sSelectionInfo.Index = *punName;
455  emit EntitySelected(m_sSelectionInfo.Index);
456  m_cUserFunctions.EntitySelected(
457  *m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index]);
458  }
459  }
460  doneCurrent();
461  /* Redraw */
462  update();
463  }
464 
465  /****************************************/
466  /****************************************/
467 
469  /* Get the position of the entity */
470  const CVector3& cPosition = c_entity.GetPosition();
471  /* Get the orientation of the entity */
472  const CQuaternion& cOrientation = c_entity.GetOrientation();
473  CRadians cZAngle, cYAngle, cXAngle;
474  cOrientation.ToEulerAngles(cZAngle, cYAngle, cXAngle);
475  /* First, translate the entity */
476  glTranslatef(cPosition.GetX(), cPosition.GetY(), cPosition.GetZ());
477  /* Second, rotate the entity */
478  glRotatef(ToDegrees(cXAngle).GetValue(), 1.0f, 0.0f, 0.0f);
479  glRotatef(ToDegrees(cYAngle).GetValue(), 0.0f, 1.0f, 0.0f);
480  glRotatef(ToDegrees(cZAngle).GetValue(), 0.0f, 0.0f, 1.0f);
481  }
482 
483  /****************************************/
484  /****************************************/
485 
487  /* Get the position of the entity */
488  const CVector3& cPosition = c_entity.GetOriginAnchor().Position;
489  /* Get the orientation of the entity */
490  const CQuaternion& cOrientation = c_entity.GetOriginAnchor().Orientation;
491  CRadians cZAngle, cYAngle, cXAngle;
492  cOrientation.ToEulerAngles(cZAngle, cYAngle, cXAngle);
493  /* First, translate the entity */
494  glTranslatef(cPosition.GetX(), cPosition.GetY(), cPosition.GetZ());
495  /* Second, rotate the entity */
496  glRotatef(ToDegrees(cXAngle).GetValue(), 1.0f, 0.0f, 0.0f);
497  glRotatef(ToDegrees(cYAngle).GetValue(), 0.0f, 1.0f, 0.0f);
498  glRotatef(ToDegrees(cZAngle).GetValue(), 0.0f, 0.0f, 1.0f);
499  }
500 
501  /****************************************/
502  /****************************************/
503 
505  if(! c_entity.GetCheckedRays().empty()) {
506  glDisable(GL_LIGHTING);
507  glLineWidth(1.0f);
508  glBegin(GL_LINES);
509  for(UInt32 i = 0; i < c_entity.GetCheckedRays().size(); ++i) {
510  if(c_entity.GetCheckedRays()[i].first) {
511  glColor3f(1.0, 0.0, 1.0);
512  }
513  else {
514  glColor3f(0.0, 1.0, 1.0);
515  }
516  const CVector3& cStart = c_entity.GetCheckedRays()[i].second.GetStart();
517  const CVector3& cEnd = c_entity.GetCheckedRays()[i].second.GetEnd();
518  glVertex3f(cStart.GetX(), cStart.GetY(), cStart.GetZ());
519  glVertex3f(cEnd.GetX(), cEnd.GetY(), cEnd.GetZ());
520  }
521  glEnd();
522  glPointSize(5.0);
523  glColor3f(0.0, 0.0, 0.0);
524  glBegin(GL_POINTS);
525  for(UInt32 i = 0; i < c_entity.GetIntersectionPoints().size(); ++i) {
526  const CVector3& cPoint = c_entity.GetIntersectionPoints()[i];
527  glVertex3f(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
528  }
529  glEnd();
530  glPointSize(1.0);
531  glEnable(GL_LIGHTING);
532  }
533  }
534 
535  /****************************************/
536  /****************************************/
537 
539  const SBoundingBox& sBBox = c_entity.GetBoundingBox();
540  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
541  glDisable(GL_LIGHTING);
542  glLineWidth(3.0f);
543  glColor3f(1.0f, 1.0f, 1.0f);
544  /* This part covers the top and bottom faces (parallel to XY) */
545  glBegin(GL_QUADS);
546  /* Bottom face */
547  glNormal3f(0.0f, 0.0f, -1.0f);
548  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MinCorner.GetZ());
549  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MinCorner.GetZ());
550  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MinCorner.GetZ());
551  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MinCorner.GetZ());
552  /* Top face */
553  glNormal3f(0.0f, 0.0f, 1.0f);
554  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MaxCorner.GetZ());
555  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MaxCorner.GetZ());
556  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MaxCorner.GetZ());
557  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MaxCorner.GetZ());
558  glEnd();
559  /* This part covers the faces (South, East, North, West) */
560  glBegin(GL_QUADS);
561  /* South face */
562  glNormal3f(-1.0f, 0.0f, 0.0f);
563  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MinCorner.GetZ());
564  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MaxCorner.GetZ());
565  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MaxCorner.GetZ());
566  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MinCorner.GetZ());
567  /* East face */
568  glNormal3f(0.0f, -1.0f, 0.0f);
569  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MinCorner.GetZ());
570  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MinCorner.GetZ());
571  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MaxCorner.GetZ());
572  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MaxCorner.GetZ());
573  /* North face */
574  glNormal3f(1.0f, 0.0f, 0.0f);
575  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MinCorner.GetZ());
576  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MinCorner.GetZ());
577  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MaxCorner.GetZ());
578  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MinCorner.GetY(), sBBox.MaxCorner.GetZ());
579  /* West face */
580  glNormal3f(0.0f, 1.0f, 0.0f);
581  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MinCorner.GetZ());
582  glVertex3f(sBBox.MinCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MaxCorner.GetZ());
583  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MaxCorner.GetZ());
584  glVertex3f(sBBox.MaxCorner.GetX(), sBBox.MaxCorner.GetY(), sBBox.MinCorner.GetZ());
585  glEnd();
586  glEnable(GL_LIGHTING);
587  glLineWidth(1.0f);
588  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
589  }
590 
591  /****************************************/
592  /****************************************/
593 
595  m_bFastForwarding = false;
596  if(nTimerId != -1) killTimer(nTimerId);
597  nTimerId = startTimer(CPhysicsEngine::GetSimulationClockTick() * 1000.0f);
598  }
599 
600  /****************************************/
601  /****************************************/
602 
604  m_nFrameCounter = 0;
605  m_bFastForwarding = true;
606  if(nTimerId != -1) killTimer(nTimerId);
607  nTimerId = startTimer(1);
608  }
609 
610  /****************************************/
611  /****************************************/
612 
614  m_bFastForwarding = false;
615  if(nTimerId != -1) killTimer(nTimerId);
616  nTimerId = -1;
617  }
618 
619  /****************************************/
620  /****************************************/
621 
623  if(!m_cSimulator.IsExperimentFinished()) {
624  m_cSimulator.UpdateSpace();
625  if(m_bFastForwarding) {
626  /* Frame dropping happens only in fast-forward */
627  m_nFrameCounter = m_nFrameCounter % m_nDrawFrameEvery;
628  if(m_nFrameCounter == 0) {
629  update();
630  }
631  ++m_nFrameCounter;
632  } else {
633  update();
634  }
635  emit StepDone(m_cSpace.GetSimulationClock());
636  }
637  else {
638  PauseExperiment();
639  emit ExperimentDone();
640  }
641  }
642 
643  /****************************************/
644  /****************************************/
645 
647  m_cSimulator.Reset();
648  delete m_pcGroundTexture;
649  if(m_bUsingFloorTexture) delete m_pcFloorTexture;
650  initializeGL();
651  update();
652  }
653 
654  /****************************************/
655  /****************************************/
656 
658  m_nDrawFrameEvery = n_every;
659  }
660 
661  /****************************************/
662  /****************************************/
663 
664  void CQTOpenGLWidget::SetGrabFrame(bool b_grab_on) {
665  m_sFrameGrabData.Grabbing = b_grab_on;
666  }
667 
668  /****************************************/
669  /****************************************/
670 
671  void CQTOpenGLWidget::SetCamera(int n_camera) {
672  m_cCamera.SetActiveSettings(n_camera);
673  update();
674  QToolTip::showText(pos() + geometry().center(), QString("Current camera: #%1").arg(n_camera+1));
675  }
676 
677  /****************************************/
678  /****************************************/
679 
681  m_cCamera.GetActiveSettings().LensFocalLength = f_length / 1000.0f;
684  QToolTip::showText(pos() + geometry().center(), QString("Motion sens = %1").arg(m_cCamera.GetActiveSettings().MotionSensitivity));
685  update();
686  }
687 
688  /****************************************/
689  /****************************************/
690 
691  void CQTOpenGLWidget::KeyPressed(QKeyEvent* pc_event) {
692  switch(pc_event->key()) {
693  case Qt::Key_W:
694  case Qt::Key_Up:
695  /* Forwards */
696  m_mapPressedKeys[DIRECTION_FORWARDS] = true;
697  reactToKeyEvent();
698  break;
699  case Qt::Key_S:
700  case Qt::Key_Down:
701  /* Backwards */
702  m_mapPressedKeys[DIRECTION_BACKWARDS] = true;
703  reactToKeyEvent();
704  break;
705  case Qt::Key_A:
706  case Qt::Key_Left:
707  /* Left */
708  m_mapPressedKeys[DIRECTION_LEFT] = true;
709  reactToKeyEvent();
710  break;
711  case Qt::Key_D:
712  case Qt::Key_Right:
713  /* Right */
714  m_mapPressedKeys[DIRECTION_RIGHT] = true;
715  reactToKeyEvent();
716  break;
717  case Qt::Key_E:
718  /* Up */
719  m_mapPressedKeys[DIRECTION_UP] = true;
720  reactToKeyEvent();
721  break;
722  case Qt::Key_Q:
723  /* Up */
724  m_mapPressedKeys[DIRECTION_DOWN] = true;
725  reactToKeyEvent();
726  break;
727  default:
728  /* Unknown key */
729  QOpenGLWidget::keyPressEvent(pc_event);
730  break;
731  }
732  }
733 
734  /****************************************/
735  /****************************************/
736 
737  void CQTOpenGLWidget::KeyReleased(QKeyEvent* pc_event) {
738  switch(pc_event->key()) {
739  case Qt::Key_W:
740  case Qt::Key_Up:
741  /* Forwards */
742  m_mapPressedKeys[DIRECTION_FORWARDS] = false;
743  reactToKeyEvent();
744  break;
745  case Qt::Key_S:
746  case Qt::Key_Down:
747  /* Backwards */
748  m_mapPressedKeys[DIRECTION_BACKWARDS] = false;
749  reactToKeyEvent();
750  break;
751  case Qt::Key_A:
752  case Qt::Key_Left:
753  /* Left */
754  m_mapPressedKeys[DIRECTION_LEFT] = false;
755  reactToKeyEvent();
756  break;
757  case Qt::Key_D:
758  case Qt::Key_Right:
759  /* Right */
760  m_mapPressedKeys[DIRECTION_RIGHT] = false;
761  reactToKeyEvent();
762  break;
763  case Qt::Key_E:
764  /* Up */
765  m_mapPressedKeys[DIRECTION_UP] = false;
766  reactToKeyEvent();
767  break;
768  case Qt::Key_Q:
769  /* Up */
770  m_mapPressedKeys[DIRECTION_DOWN] = false;
771  reactToKeyEvent();
772  break;
773  default:
774  /* Unknown key */
775  QOpenGLWidget::keyPressEvent(pc_event);
776  break;
777  }
778  }
779 
780  /****************************************/
781  /****************************************/
782 
784  CVector3 cArenaSize(m_cSpace.GetArenaSize());
785  CVector3 cArenaMinCorner(m_cSpace.GetArenaCenter().GetX() - cArenaSize.GetX() * 0.5f,
786  m_cSpace.GetArenaCenter().GetY() - cArenaSize.GetY() * 0.5f,
787  m_cSpace.GetArenaCenter().GetZ() - cArenaSize.GetZ() * 0.5f);
788  CVector3 cArenaMaxCorner(m_cSpace.GetArenaCenter().GetX() + cArenaSize.GetX() * 0.5f,
789  m_cSpace.GetArenaCenter().GetY() + cArenaSize.GetY() * 0.5f,
790  m_cSpace.GetArenaCenter().GetZ() + cArenaSize.GetZ() * 0.5f);
791  /* Disable lighting - no funny color effects */
792  glDisable(GL_LIGHTING);
793  /* Enable textures */
794  glEnable(GL_TEXTURE_2D);
795  /* Take care of the floor entity if necessary */
796  /* The texture covers the object like a decal */
797  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
798 #ifdef ARGOS_WITH_FREEIMAGE
799  if(m_bUsingFloorTexture) {
800  /* Use the image as texture */
801  if(m_cSpace.GetFloorEntity().HasChanged()) {
802  /* Create an image to use as texture */
803  m_pcFloorTexture->destroy();
804  m_pcFloorTexture->create();
805  m_cSpace.GetFloorEntity().SaveAsImage("/tmp/argos_floor.png");
806  m_pcFloorTexture->setData(QImage("/tmp/argos_floor.png"));
807  m_pcFloorTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,
808  QOpenGLTexture::Linear);
809  /* Clear the 'changed' flag on the floor entity */
810  m_cSpace.GetFloorEntity().ClearChanged();
811  }
812  /* Draw the floor entity along with its texture */
813  m_pcFloorTexture->bind();
814  glBegin(GL_QUADS);
815  glTexCoord2d(0.0f, 1.0f); glVertex3f(cArenaMinCorner.GetX(), cArenaMinCorner.GetY(), 0.0f);
816  glTexCoord2d(1.0f, 1.0f); glVertex3f(cArenaMaxCorner.GetX(), cArenaMinCorner.GetY(), 0.0f);
817  glTexCoord2d(1.0f, 0.0f); glVertex3f(cArenaMaxCorner.GetX(), cArenaMaxCorner.GetY(), 0.0f);
818  glTexCoord2d(0.0f, 0.0f); glVertex3f(cArenaMinCorner.GetX(), cArenaMaxCorner.GetY(), 0.0f);
819  glEnd();
820  }
821  else {
822 #endif
823  /* Wrap the texture at the edges, which in this case means that it is repeated */
824  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
825  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
826  m_pcGroundTexture->bind();
827  /* Draw the floor along with its texture */
828  glBegin(GL_QUADS);
829  glTexCoord2f(0.0f, cArenaSize.GetY()); glVertex3f(cArenaMinCorner.GetX(), cArenaMinCorner.GetY(), 0.0f);
830  glTexCoord2f(cArenaSize.GetX(), cArenaSize.GetY()); glVertex3f(cArenaMaxCorner.GetX(), cArenaMinCorner.GetY(), 0.0f);
831  glTexCoord2f(cArenaSize.GetX(), 0.0f); glVertex3f(cArenaMaxCorner.GetX(), cArenaMaxCorner.GetY(), 0.0f);
832  glTexCoord2f(0.0f, 0.0f); glVertex3f(cArenaMinCorner.GetX(), cArenaMaxCorner.GetY(), 0.0f);
833  glEnd();
834 #ifdef ARGOS_WITH_FREEIMAGE
835  }
836 #endif
837  /* Disable the textures */
838  glDisable(GL_TEXTURE_2D);
839  /* Draw walls */
840  glDisable(GL_CULL_FACE);
841  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
842  glLineWidth(10.0f);
843  glColor3f(0.0f, 0.0f, 0.0f);
844  /* This part covers the top and bottom faces (parallel to XY) */
845  glBegin(GL_QUADS);
846  /* Top face */
847  glVertex3f(cArenaMinCorner.GetX(), cArenaMinCorner.GetY(), cArenaMaxCorner.GetZ());
848  glVertex3f(cArenaMaxCorner.GetX(), cArenaMinCorner.GetY(), cArenaMaxCorner.GetZ());
849  glVertex3f(cArenaMaxCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMaxCorner.GetZ());
850  glVertex3f(cArenaMinCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMaxCorner.GetZ());
851  glEnd();
852  /* This part covers the faces (South, East, North, West) */
853  glBegin(GL_QUADS);
854  /* South face */
855  glVertex3f(cArenaMinCorner.GetX(), cArenaMinCorner.GetY(), cArenaMinCorner.GetZ());
856  glVertex3f(cArenaMinCorner.GetX(), cArenaMinCorner.GetY(), cArenaMaxCorner.GetZ());
857  glVertex3f(cArenaMinCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMaxCorner.GetZ());
858  glVertex3f(cArenaMinCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMinCorner.GetZ());
859  /* East face */
860  glVertex3f(cArenaMinCorner.GetX(), cArenaMinCorner.GetY(), cArenaMinCorner.GetZ());
861  glVertex3f(cArenaMaxCorner.GetX(), cArenaMinCorner.GetY(), cArenaMinCorner.GetZ());
862  glVertex3f(cArenaMaxCorner.GetX(), cArenaMinCorner.GetY(), cArenaMaxCorner.GetZ());
863  glVertex3f(cArenaMinCorner.GetX(), cArenaMinCorner.GetY(), cArenaMaxCorner.GetZ());
864  /* North face */
865  glVertex3f(cArenaMaxCorner.GetX(), cArenaMinCorner.GetY(), cArenaMinCorner.GetZ());
866  glVertex3f(cArenaMaxCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMinCorner.GetZ());
867  glVertex3f(cArenaMaxCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMaxCorner.GetZ());
868  glVertex3f(cArenaMaxCorner.GetX(), cArenaMinCorner.GetY(), cArenaMaxCorner.GetZ());
869  /* West face */
870  glVertex3f(cArenaMinCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMinCorner.GetZ());
871  glVertex3f(cArenaMinCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMaxCorner.GetZ());
872  glVertex3f(cArenaMaxCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMaxCorner.GetZ());
873  glVertex3f(cArenaMaxCorner.GetX(), cArenaMaxCorner.GetY(), cArenaMinCorner.GetZ());
874  glEnd();
875  glLineWidth(1.0f);
876  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
877  glEnable(GL_CULL_FACE);
878  /* Restore lighting */
879  glEnable(GL_LIGHTING);
880  }
881 
882  /****************************************/
883  /****************************************/
884 
886  }
887 
888  /****************************************/
889  /****************************************/
890 
891  void CQTOpenGLWidget::timerEvent(QTimerEvent* pc_event) {
892  StepExperiment();
893  }
894 
895  /****************************************/
896  /****************************************/
897 
898  void CQTOpenGLWidget::mousePressEvent(QMouseEvent* pc_event) {
899  /*
900  * Mouse press without shift
901  * Either pure press, or press + CTRL
902  */
903  if(! (pc_event->modifiers() & Qt::ShiftModifier)) {
904  m_bMouseGrabbed = true;
905  m_cMouseGrabPos = pc_event->pos();
906  }
907  /*
908  * Mouse press with shift
909  */
910  else {
911  m_bMouseGrabbed = false;
912  SelectInScene(pc_event->pos().x(),
913  pc_event->pos().y());
914  }
915  }
916 
917  /****************************************/
918  /****************************************/
919 
920  void CQTOpenGLWidget::mouseReleaseEvent(QMouseEvent* pc_event) {
921  /*
922  * Mouse grabbed, selected entity, CTRL pressed
923  */
924  if(m_bMouseGrabbed &&
925  m_sSelectionInfo.IsSelected &&
926  (pc_event->modifiers() & Qt::ControlModifier)) {
927  /* Treat selected entity as an embodied entity */
928  CEmbodiedEntity* pcEntity = dynamic_cast<CEmbodiedEntity*>(
929  m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index]);
930  if(pcEntity == NULL) {
931  /* Treat selected entity as a composable entity with an embodied component */
932  CComposableEntity* pcCompEntity = dynamic_cast<CComposableEntity*>(
933  m_cSpace.GetRootEntityVector()[m_sSelectionInfo.Index]);
934  if(pcCompEntity != NULL && pcCompEntity->HasComponent("body")) {
935  pcEntity = &pcCompEntity->GetComponent<CEmbodiedEntity>("body");
936  }
937  else {
938  /* All conversions failed, get out */
939  m_bMouseGrabbed = false;
940  return;
941  }
942  }
943  /*
944  * If we get here, pcEntity is set to a non-NULL value
945  * Move the entity to the wanted place
946  */
947  /* Create a plane coincident with the world XY plane, centered at the entity position */
948  CPlane cXYPlane(pcEntity->GetOriginAnchor().Position, CVector3::Z);
949  /* Create a ray from the image pixel to the world */
950  CRay3 cMouseRay =
951  RayFromWindowCoord(pc_event->pos().x(),
952  pc_event->pos().y());
953  /* Calculate the new entity position as the intersection of the projected mouse position
954  with the plane created before */
955  CVector3 cNewPos;
956  if(cMouseRay.Intersects(cXYPlane, cNewPos)) {
957  pcEntity->MoveTo(cNewPos,
958  pcEntity->GetOriginAnchor().Orientation);
959  /* Entity moved, redraw */
960  update();
961  }
962  }
963  /*
964  * Mouse was grabbed, button released -> ungrab mouse
965  */
966  m_bMouseGrabbed = false;
967  }
968 
969  /****************************************/
970  /****************************************/
971 
972  void CQTOpenGLWidget::mouseMoveEvent(QMouseEvent* pc_event) {
973  /*
974  * Moving while mouse grabbed -> camera movement
975  */
976  if(m_bMouseGrabbed) {
977  if(! (pc_event->modifiers() & Qt::ControlModifier)) {
978  /*
979  * Camera movement
980  */
981  if(pc_event->buttons() == Qt::LeftButton) {
982  if (m_bInvertMouse) m_cCamera.Rotate( pc_event->pos() - m_cMouseGrabPos);
983  else m_cCamera.Rotate( m_cMouseGrabPos - pc_event->pos());
984  m_cMouseGrabPos = pc_event->pos();
985  update();
986  }
987  else if(pc_event->buttons() == Qt::RightButton) {
988  QPoint cDelta(pc_event->pos() - m_cMouseGrabPos);
989  m_cCamera.Move(-cDelta.y(), cDelta.x(), 0);
990  m_cMouseGrabPos = pc_event->pos();
991  update();
992  }
993  else if(pc_event->buttons() == Qt::MidButton) {
994  QPoint cDelta(pc_event->pos() - m_cMouseGrabPos);
995  m_cCamera.Move(0, 0, cDelta.y());
996  m_cMouseGrabPos = pc_event->pos();
997  update();
998  }
999  }
1000  }
1001  }
1002 
1003  /****************************************/
1004  /****************************************/
1005 
1006  void CQTOpenGLWidget::keyPressEvent(QKeyEvent* pc_event) {
1007  m_cUserFunctions.KeyPressed(pc_event);
1008  }
1009 
1010  /****************************************/
1011  /****************************************/
1012 
1013  void CQTOpenGLWidget::keyReleaseEvent(QKeyEvent* pc_event) {
1014  m_cUserFunctions.KeyReleased(pc_event);
1015  }
1016 
1017  /****************************************/
1018  /****************************************/
1019 
1021  SInt32 nForwardsBackwards = 0;
1022  SInt32 nSideways = 0;
1023  SInt32 nUpDown = 0;
1024 
1025  if(m_mapPressedKeys[DIRECTION_UP]) nUpDown++;
1026  if(m_mapPressedKeys[DIRECTION_DOWN]) nUpDown--;
1027  if(m_mapPressedKeys[DIRECTION_LEFT]) nSideways++;
1028  if(m_mapPressedKeys[DIRECTION_RIGHT]) nSideways--;
1029  if(m_mapPressedKeys[DIRECTION_FORWARDS]) nForwardsBackwards++;
1030  if(m_mapPressedKeys[DIRECTION_BACKWARDS]) nForwardsBackwards--;
1031 
1032  if(nForwardsBackwards != 0 ||
1033  nSideways != 0 ||
1034  nUpDown != 0) {
1035  m_cCamera.Move(15 * nForwardsBackwards,
1036  15 * nSideways,
1037  15 * nUpDown);
1038  update();
1039  }
1040  }
1041 
1042  /****************************************/
1043  /****************************************/
1044 
1045  void CQTOpenGLWidget::resizeEvent(QResizeEvent* pc_event) {
1046  /* Call parent's resize event handler */
1047  QOpenGLWidget::resizeEvent(pc_event);
1048  /* Show new window size */
1049  QToolTip::showText(pos() + geometry().center(), QString("Size: %1 x %2").arg(pc_event->size().width()).arg(pc_event->size().height()));
1050  }
1051 
1052  /****************************************/
1053  /****************************************/
1054 
1056  if(NodeExists(t_tree, "frame_grabbing")) {
1057  TConfigurationNode& tNode = GetNode(t_tree, "frame_grabbing");
1058  std::string strBuffer;
1059  /* Parse directory, removing trailing '/' */
1060  strBuffer = ".";
1061  GetNodeAttributeOrDefault(tNode, "directory", strBuffer, strBuffer);
1062  size_t unEndPos = strBuffer.find_last_not_of("/ \t");
1063  if(unEndPos != std::string::npos) {
1064  strBuffer = strBuffer.substr(0, unEndPos+1);
1065  }
1066  Directory = strBuffer.c_str();
1067  QDir cDirectory(Directory);
1068  if(!cDirectory.exists()) {
1069  THROW_ARGOSEXCEPTION("QTOpenGL: frame grabbing directory \"" << strBuffer << "\" does not exist. Create it first!");
1070  }
1071  /* Parse base name */
1072  strBuffer = "frame_";
1073  GetNodeAttributeOrDefault(tNode, "base_name", strBuffer, strBuffer);
1074  BaseName = strBuffer.c_str();
1075  /* Parse format */
1076  strBuffer = "png";
1077  GetNodeAttributeOrDefault(tNode, "format", strBuffer, strBuffer);
1078  Format = strBuffer.c_str();
1079  /* Parse quality */
1080  GetNodeAttributeOrDefault(tNode, "quality", Quality, Quality);
1081  }
1082  }
1083 
1084  /****************************************/
1085  /****************************************/
1086 
1087 }
argos::CQTOpenGLCamera::SSettings::LensFocalLength
Real LensFocalLength
The focal length of the lens (if this was a real camera)
Definition: qtopengl_camera.h:49
argos::CEmbodiedEntity::GetOriginAnchor
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
Definition: embodied_entity.h:119
argos::SAnchor::Orientation
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
Definition: physics_model.h:53
argos::CVector3::GetZ
Real GetZ() const
Returns the z coordinate of this vector.
Definition: vector3.h:125
argos::CQTOpenGLCamera::Look
void Look()
Definition: qtopengl_camera.h:94
argos::CQTOpenGLWidget::SSelectionInfo::IsSelected
bool IsSelected
Definition: qtopengl_widget.h:86
argos::CQTOpenGLWidget::SFrameGrabData::Init
void Init(TConfigurationNode &t_tree)
Definition: qtopengl_widget.cpp:1055
argos::CQTOpenGLWidget::PauseExperiment
void PauseExperiment()
Pauses the experiment.
Definition: qtopengl_widget.cpp:613
argos::CQTOpenGLCamera::SSettings::CalculateSensitivity
void CalculateSensitivity()
Calculate the sensitivity of the camera.
Definition: qtopengl_camera.cpp:293
argos::CQTOpenGLWidget::keyReleaseEvent
virtual void keyReleaseEvent(QKeyEvent *pc_event)
Definition: qtopengl_widget.cpp:1013
argos::CQTOpenGLWidget::initializeGL
virtual void initializeGL()
Called when the GL context must be initialized.
Definition: qtopengl_widget.cpp:93
argos
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
argos::CVector3
A 3D vector class.
Definition: vector3.h:29
argos::CFloorEntity::HasChanged
bool HasChanged() const
Returns true if the floor color has changed.
Definition: floor_entity.h:113
argos::CControllableEntity::GetCheckedRays
std::vector< std::pair< bool, CRay3 > > & GetCheckedRays()
Returns the list of checked rays.
Definition: controllable_entity.h:204
argos::CRadians
It defines the basic type CRadians, used to store an angle value in radians.
Definition: angles.h:42
argos::CComposableEntity
Basic class for an entity that contains other entities.
Definition: composable_entity.h:32
argos::CQTOpenGLUserFunctions::DrawInWorld
virtual void DrawInWorld()
Drawing hook executed after all objects have been drawn.
Definition: qtopengl_user_functions.h:165
argos::GetNode
TConfigurationNode & GetNode(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns the first of its child nodes with the wanted name.
Definition: argos_configuration.h:63
argos::CARGoSException
The exception that wraps all errors in ARGoS.
Definition: argos_exception.h:61
argos::CComposableEntity::GetComponent
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
Definition: composable_entity.cpp:109
argos::CQTOpenGLCamera::SSettings::YFieldOfView
CDegrees YFieldOfView
The focal length of the camera.
Definition: qtopengl_camera.h:51
argos::ToDegrees
CDegrees ToDegrees(const CRadians &c_radians)
Converts CRadians to CDegrees.
Definition: angles.h:489
argos::SBoundingBox::MinCorner
CVector3 MinCorner
Definition: physics_model.h:88
argos::SBoundingBox::MaxCorner
CVector3 MaxCorner
Definition: physics_model.h:89
argos::CQTOpenGLWidget::DrawArena
void DrawArena()
Definition: qtopengl_widget.cpp:783
argos::CRay3
Definition: ray3.h:19
argos::CVector3::Z
static const CVector3 Z
The z axis.
Definition: vector3.h:40
argos::CQTOpenGLWidget::SetCamera
void SetCamera(int n_camera)
Sets the current camera in use.
Definition: qtopengl_widget.cpp:671
argos::CQTOpenGLCamera::SetActiveSettings
void SetActiveSettings(UInt32 un_settings)
Definition: qtopengl_camera.h:124
argos::CSimulator
The core class of ARGOS.
Definition: simulator.h:62
argos::CEmbodiedEntity
This entity is a link to a body in the physics engine.
Definition: embodied_entity.h:48
argos::CQTOpenGLUserFunctions::EntitySelected
virtual void EntitySelected(CEntity &c_entity)
Called every time an entity is selected.
Definition: qtopengl_user_functions.h:124
argos::CEmbodiedEntity::MoveTo
virtual bool MoveTo(const CVector3 &c_position, const CQuaternion &c_orientation, bool b_check_only=false)
Moves the entity to the wanted position and orientation.
Definition: embodied_entity.cpp:321
argos::CQTOpenGLWidget::SetGrabFrame
void SetGrabFrame(bool b_grab_on)
Toggles frame grabbing.
Definition: qtopengl_widget.cpp:664
argos::CQTOpenGLCamera::Move
void Move(SInt32 n_forwards_backwards, SInt32 n_sideways, SInt32 n_up_down)
Definition: qtopengl_camera.cpp:328
argos::TConfigurationNode
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Definition: argos_configuration.h:27
argos::CQTOpenGLWidget::SelectEntity
void SelectEntity(CEntity &c_entity)
Selects the passed entity.
Definition: qtopengl_widget.cpp:320
argos::CQTOpenGLWidget::DrawEntity
void DrawEntity(CPositionalEntity &c_entity)
Draws a positional entity.
Definition: qtopengl_widget.cpp:468
argos::CQTOpenGLWidget::GetSelectedEntity
CEntity * GetSelectedEntity()
Returns the currently selected entity, or NULL if none is selected.
Definition: qtopengl_widget.cpp:311
argos::CVector3::GetX
Real GetX() const
Returns the x coordinate of this vector.
Definition: vector3.h:93
argos::CQTOpenGLWidget::mousePressEvent
virtual void mousePressEvent(QMouseEvent *pc_event)
Definition: qtopengl_widget.cpp:898
argos::CQTOpenGLCamera::Rotate
void Rotate(const QPoint &c_delta)
Definition: qtopengl_camera.cpp:314
argos::CPositionalEntity::GetPosition
const CVector3 & GetPosition() const
Definition: positional_entity.h:36
argos::CQTOpenGLWidget::ExperimentDone
void ExperimentDone()
Emitted when the experiment is finished.
argos::CQuaternion::ToEulerAngles
void ToEulerAngles(CRadians &c_z_angle, CRadians &c_y_angle, CRadians &c_x_angle) const
Definition: quaternion.h:171
argos::CQTOpenGLWidget::DrawBoundingBox
void DrawBoundingBox(CEmbodiedEntity &c_entity)
Draws the bounding box of an embodied entity.
Definition: qtopengl_widget.cpp:538
argos::CQuaternion
Definition: quaternion.h:14
argos::CPositionalEntity
Definition: positional_entity.h:20
argos::CQTOpenGLWidget::resizeEvent
virtual void resizeEvent(QResizeEvent *pc_event)
Definition: qtopengl_widget.cpp:1045
argos::CQTOpenGLWidget::FastForwardExperiment
void FastForwardExperiment()
Fast forwards the experiment.
Definition: qtopengl_widget.cpp:603
argos::CQTOpenGLWidget::SetCameraFocalLength
void SetCameraFocalLength(double f_length)
Sets the focal length of the current camera.
Definition: qtopengl_widget.cpp:680
argos::CQTOpenGLCamera::SSettings::CalculateYFieldOfView
void CalculateYFieldOfView()
Calculates the value of YFieldOfView.
Definition: qtopengl_camera.cpp:286
argos::CSpace::GetArenaCenter
const CVector3 & GetArenaCenter() const
Returns the arena center.
Definition: space.h:361
argos::CQTOpenGLCamera::GetActiveSettings
SSettings & GetActiveSettings()
Definition: qtopengl_camera.h:116
argos::CQTOpenGLWidget::EntityDeselected
void EntityDeselected(size_t un_index)
Emitted when an entity is deselected.
THROW_ARGOSEXCEPTION
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
Definition: argos_exception.h:111
argos::CQTOpenGLWidget::RayFromWindowCoord
CRay3 RayFromWindowCoord(int n_x, int n_y)
Casts a ray from the given window coordinate.
Definition: qtopengl_widget.cpp:223
argos::CRay3::Intersects
bool Intersects(const CPlane &c_plane, CVector3 &c_point) const
Definition: ray3.cpp:15
argos::CQTOpenGLWidget::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *pc_event)
Definition: qtopengl_widget.cpp:920
argos::CQTOpenGLWidget::KeyReleased
void KeyReleased(QKeyEvent *pc_event)
Handles key release events.
Definition: qtopengl_widget.cpp:737
argos::CSpace::GetArenaSize
const CVector3 & GetArenaSize() const
Returns the arena size.
Definition: space.h:343
argos::CFloorEntity::ClearChanged
void ClearChanged()
Marks the floor color as not changed.
Definition: floor_entity.h:129
argos::CQTOpenGLMainWindow::GetTextureDir
const QString & GetTextureDir() const
Definition: qtopengl_main_window.h:65
argos::CQTOpenGLWidget::paintGL
virtual void paintGL()
Logic for scene drawing.
Definition: qtopengl_widget.cpp:133
argos::CQTOpenGLWidget::~CQTOpenGLWidget
virtual ~CQTOpenGLWidget()
Class destructor.
Definition: qtopengl_widget.cpp:78
argos::CQTOpenGLUserFunctions::EntityDeselected
virtual void EntityDeselected(CEntity &c_entity)
Called every time an entity is deselected.
Definition: qtopengl_user_functions.h:130
argos::CQTOpenGLWidget::GetWindowCoordInWorld
CVector3 GetWindowCoordInWorld(int n_x, int n_y)
Returns the position in the world corresponding to the given window coordinate.
Definition: qtopengl_widget.cpp:269
argos::CQTOpenGLUserFunctions::KeyPressed
virtual void KeyPressed(QKeyEvent *pc_event)
Called when a key press event occurs.
Definition: qtopengl_user_functions.cpp:58
argos::CSpace::GetSimulationClock
UInt32 GetSimulationClock() const
Returns the current value of the simulation clock.
Definition: space.h:317
argos::CQTOpenGLUserFunctions
The QTOpenGL user functions.
Definition: qtopengl_user_functions.h:74
argos::CQTOpenGLWidget::DeselectEntity
void DeselectEntity()
Deselects the currently selected entity.
Definition: qtopengl_widget.cpp:350
argos::CQTOpenGLWidget::keyPressEvent
virtual void keyPressEvent(QKeyEvent *pc_event)
Definition: qtopengl_widget.cpp:1006
argos::CQTOpenGLWidget::DrawAxes
void DrawAxes()
Definition: qtopengl_widget.cpp:885
argos::CRay3::GetStart
CVector3 & GetStart()
Definition: ray3.h:37
SInt32
signed int SInt32
32-bit signed integer.
Definition: datatypes.h:93
argos::NodeExists
bool NodeExists(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns true if one of its child nodes has the wanted name.
Definition: argos_configuration.h:44
argos::CQTOpenGLWidget::SelectInScene
void SelectInScene(UInt32 un_x, UInt32 un_y)
Selects the entity closest to the camera at the given screen coordinates.
Definition: qtopengl_widget.cpp:364
qtopengl_widget.h
argos::CQTOpenGLWidget::timerEvent
virtual void timerEvent(QTimerEvent *pc_event)
Definition: qtopengl_widget.cpp:891
argos::CQTOpenGLCamera::SSettings::MotionSensitivity
Real MotionSensitivity
Motion sensitivity.
Definition: qtopengl_camera.h:53
argos::CSpace::GetFloorEntity
CFloorEntity & GetFloorEntity()
Returns the floor entity.
Definition: space.h:219
argos::CQTOpenGLUserFunctions::DrawOverlay
virtual void DrawOverlay(QPainter &c_painter)
Drawing hook to put graphics on top of the OpenGL window.
Definition: qtopengl_user_functions.h:174
argos::CQTOpenGLMainWindow
Definition: qtopengl_main_window.h:36
argos::CEntity
The basic entity type.
Definition: entity.h:89
argos::CPositionalEntity::GetOrientation
const CQuaternion & GetOrientation() const
Definition: positional_entity.h:52
argos::CQTOpenGLUserFunctions::Call
virtual void Call(CEntity &c_entity)
Calls a user method for the given entity.
Definition: qtopengl_user_functions.cpp:487
argos::CQTOpenGLWidget::StepExperiment
void StepExperiment()
Executes one experiment time step.
Definition: qtopengl_widget.cpp:622
argos::CQTOpenGLWidget::SFrameGrabData::Directory
QString Directory
Definition: qtopengl_widget.h:67
argos::CQTOpenGLWidget::ResetExperiment
void ResetExperiment()
Resets the state of the experiment to its state right after initialization.
Definition: qtopengl_widget.cpp:646
argos::CQTOpenGLWidget::SFrameGrabData::BaseName
QString BaseName
Definition: qtopengl_widget.h:68
UInt32
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
argos::CSimulator::IsExperimentFinished
bool IsExperimentFinished() const
Returns true if the experiment has finished.
Definition: simulator.cpp:284
argos::CQTOpenGLUserFunctions::KeyReleased
virtual void KeyReleased(QKeyEvent *pc_event)
Called when a key release event occurs.
Definition: qtopengl_user_functions.cpp:65
argos::GetNodeAttributeOrDefault
void GetNodeAttributeOrDefault(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer, const T &t_default)
Returns the value of a node's attribute, or the passed default value.
Definition: argos_configuration.h:318
argos::CQTOpenGLWidget::reactToKeyEvent
void reactToKeyEvent()
Definition: qtopengl_widget.cpp:1020
argos::CQTOpenGLWidget::SetDrawFrameEvery
void SetDrawFrameEvery(int n_every)
When fast-forwarding, sets every how many steps a frame must be drawn.
Definition: qtopengl_widget.cpp:657
argos::CPhysicsEngine::GetSimulationClockTick
static Real GetSimulationClockTick()
Returns the simulation clock tick.
Definition: physics_engine.cpp:264
argos::CPlane
Definition: plane.h:19
argos::CSimulator::UpdateSpace
void UpdateSpace()
Performs an update step of the space.
Definition: simulator.cpp:276
argos::CDegrees::GetValue
Real GetValue() const
Returns the value in degrees.
Definition: angles.h:322
qtopengl_user_functions.h
argos::CQTOpenGLWidget::PlayExperiment
void PlayExperiment()
Plays the experiment.
Definition: qtopengl_widget.cpp:594
argos::CQTOpenGLWidget::SFrameGrabData::Grabbing
bool Grabbing
Definition: qtopengl_widget.h:66
qtopengl_main_window.h
argos::CQTOpenGLWidget::CQTOpenGLWidget
CQTOpenGLWidget(QWidget *pc_parent, CQTOpenGLMainWindow &c_main_window, CQTOpenGLUserFunctions &c_user_functions)
Class constructor.
Definition: qtopengl_widget.cpp:38
argos::CSimulator::Reset
void Reset()
Resets the experiment.
Definition: simulator.cpp:175
argos::CQTOpenGLWidget::EntitySelected
void EntitySelected(size_t un_index)
Emitted when an entity is selected.
argos::CControllableEntity::GetIntersectionPoints
std::vector< CVector3 > & GetIntersectionPoints()
Returns the list of intersection points.
Definition: controllable_entity.h:214
argos::CVector3::GetY
Real GetY() const
Returns the y coordinate of this vector.
Definition: vector3.h:109
argos::CQTOpenGLWidget::SSelectionInfo::Index
size_t Index
Definition: qtopengl_widget.h:87
argos::CControllableEntity
An entity that contains a pointer to the user-defined controller.
Definition: controllable_entity.h:26
argos::CQTOpenGLWidget::StepDone
void StepDone(int n_step)
Emitted whenever a time step has been executed.
argos::CSpace::GetRootEntityVector
CEntity::TVector & GetRootEntityVector()
Returns a vector of all the root entities in the space.
Definition: space.h:137
argos::CQTOpenGLWidget::SFrameGrabData::Format
QString Format
Definition: qtopengl_widget.h:69
argos::CQTOpenGLWidget::DrawRays
void DrawRays(CControllableEntity &c_entity)
Draws a ray.
Definition: qtopengl_widget.cpp:504
argos::SAnchor::Position
CVector3 Position
The position of the anchor wrt the global coordinate system.
Definition: physics_model.h:51
argos::CQTOpenGLWidget::SFrameGrabData::Quality
SInt32 Quality
Definition: qtopengl_widget.h:70
Real
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
argos::CEntity::TVector
std::vector< CEntity * > TVector
A vector of entities.
Definition: entity.h:97
argos::CComposableEntity::HasComponent
bool HasComponent(const std::string &str_component)
Returns true if this composable entity has a component with the given string label.
Definition: composable_entity.cpp:150
argos::CEmbodiedEntity::GetBoundingBox
const SBoundingBox & GetBoundingBox() const
Returns the bounding box of this embodied entity.
Definition: embodied_entity.cpp:232
argos::CQTOpenGLWidget::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *pc_event)
Definition: qtopengl_widget.cpp:972
argos::CQTOpenGLWidget::KeyPressed
void KeyPressed(QKeyEvent *pc_event)
Handles key press events.
Definition: qtopengl_widget.cpp:691
argos::SBoundingBox
Definition: physics_model.h:87
argos::CRay3::GetEnd
CVector3 & GetEnd()
Definition: ray3.h:45