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>
22 #include <QTimerEvent>
23 #include <QMouseEvent>
24 #include <QWheelEvent>
26 #include <QOpenGLFramebufferObject>
28 #ifndef GL_MULTISAMPLE
29 #define GL_MULTISAMPLE 0x809D
34 static const Real ASPECT_RATIO = 4.0f / 3.0f;
42 QOpenGLWidget(pc_parent),
43 m_cMainWindow(c_main_window),
44 m_cUserFunctions(c_user_functions),
46 m_bFastForwarding(false),
49 m_bMouseGrabbed(false),
50 m_bShiftPressed(false),
51 m_bInvertMouse(false),
53 m_cSpace(m_cSimulator.GetSpace()),
54 m_bShowBoundary(true),
55 m_bUsingFloorTexture(false),
56 m_pcFloorTexture(nullptr),
57 m_pcGroundTexture(nullptr) {
59 QSizePolicy cSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
60 cSizePolicy.setHeightForWidth(
true);
61 setSizePolicy(cSizePolicy);
63 setFocusPolicy(Qt::ClickFocus);
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;
80 delete m_pcGroundTexture;
81 if(m_bUsingFloorTexture) {
82 delete m_pcFloorTexture;
92 initializeOpenGLFunctions();
94 glClearColor(0, .5, .5, 255);
97 m_pcGroundTexture =
new QOpenGLTexture(QImage(m_cMainWindow.
GetTextureDir() +
"/ground.png"));
98 m_pcGroundTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,
99 QOpenGLTexture::Linear);
100 #ifdef ARGOS_WITH_FREEIMAGE
105 m_bUsingFloorTexture =
true;
107 m_pcFloorTexture =
new QOpenGLTexture(QImage(
"/tmp/argos_floor.png"));
108 m_pcFloorTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,
109 QOpenGLTexture::Linear);
115 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
116 glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST);
118 GLfloat pfLightAmbient[] = { .2f, .2f, .2f, 1.0f };
119 GLfloat pfLightDiffuse[] = { .8f, .8f, .8f, 1.0f };
120 GLfloat pfLightPosition[] = { 50.0f , 50.0f , 2.0f , 1.0f };
121 glLightfv(GL_LIGHT0, GL_AMBIENT, pfLightAmbient);
122 glLightfv(GL_LIGHT0, GL_DIFFUSE, pfLightDiffuse);
123 glLightfv(GL_LIGHT0, GL_POSITION, pfLightPosition);
132 glClearAccum(0.0, 0.0, 0.0, 0.0);
134 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
136 glEnable(GL_LINE_SMOOTH);
137 glShadeModel(GL_SMOOTH);
139 glEnable(GL_DEPTH_TEST);
141 glEnable(GL_CULL_FACE);
143 glEnable(GL_LIGHTING);
145 glMatrixMode(GL_PROJECTION);
151 glMatrixMode(GL_MODELVIEW);
158 for(
auto itEntities = vecEntities.begin();
159 itEntities != vecEntities.end();
162 CallEntityOperation<CQTOpenGLOperationDrawNormal, CQTOpenGLWidget, void>(*
this, **itEntities);
163 m_cUserFunctions.
Call(**itEntities);
169 CallEntityOperation<CQTOpenGLOperationDrawSelected, CQTOpenGLWidget, void>(*
this, *m_sSelectionInfo.
Entity);
179 glShadeModel(GL_FLAT);
180 glDisable(GL_LIGHTING);
181 glDisable(GL_CULL_FACE);
182 glDisable(GL_DEPTH_TEST);
183 glMatrixMode(GL_MODELVIEW);
184 QPainter cPainter(
this);
185 cPainter.setRenderHint(QPainter::Antialiasing);
186 cPainter.setRenderHint(QPainter::TextAntialiasing);
192 QString strFileName = QString(
"%1/%2%3.%4")
196 .arg(m_sFrameGrabData.
Format);
197 QToolTip::showText(pos() + geometry().center(),
"Stored frame to \"" + strFileName);
214 n_x *= devicePixelRatio();
215 n_y *= devicePixelRatio();
218 glGetIntegerv(GL_VIEWPORT, nViewport);
220 GLdouble fModelViewMatrix[16];
221 GLdouble fProjectionMatrix[16];
222 glGetDoublev(GL_MODELVIEW_MATRIX, fModelViewMatrix);
223 glGetDoublev(GL_PROJECTION_MATRIX, fProjectionMatrix);
230 GLfloat fWinY = nViewport[3] - n_y;
235 GLdouble fRayStartX, fRayStartY, fRayStartZ;
236 gluUnProject(fWinX, fWinY, 0.0f,
237 fModelViewMatrix, fProjectionMatrix, nViewport,
238 &fRayStartX, &fRayStartY, &fRayStartZ);
243 GLdouble fRayEndX, fRayEndY, fRayEndZ;
244 gluUnProject(fWinX, fWinY, 1.0f,
245 fModelViewMatrix, fProjectionMatrix, nViewport,
246 &fRayEndX, &fRayEndY, &fRayEndZ);
249 CVector3(fRayEndX, fRayEndY, fRayEndZ));
260 n_x *= devicePixelRatio();
261 n_y *= devicePixelRatio();
264 glGetIntegerv(GL_VIEWPORT, nViewport);
266 GLdouble fModelViewMatrix[16];
267 GLdouble fProjectionMatrix[16];
268 glGetDoublev(GL_MODELVIEW_MATRIX, fModelViewMatrix);
269 glGetDoublev(GL_PROJECTION_MATRIX, fProjectionMatrix);
276 GLfloat fWinY = nViewport[3] - n_y;
279 glReadBuffer(GL_BACK);
280 glReadPixels(n_x, (GLint)fWinY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &fWinZ);
282 GLdouble fWorldX, fWorldY, fWorldZ;
283 gluUnProject(fWinX, fWinY, fWinZ,
284 fModelViewMatrix, fProjectionMatrix, nViewport,
285 &fWorldX, &fWorldY, &fWorldZ);
291 return CVector3(fWorldX, fWorldZ, fWorldY);
311 if(m_sSelectionInfo.
Entity == &c_entity)
return;
315 *m_sSelectionInfo.
Entity);
322 m_sSelectionInfo.
Entity = &c_entity;
337 *m_sSelectionInfo.
Entity);
366 glTranslated(cPosition.
GetX(), cPosition.
GetY(), cPosition.
GetZ());
368 glRotated(
ToDegrees(cXAngle).GetValue(), 1.0f, 0.0f, 0.0f);
369 glRotated(
ToDegrees(cYAngle).GetValue(), 0.0f, 1.0f, 0.0f);
370 glRotated(
ToDegrees(cZAngle).GetValue(), 0.0f, 0.0f, 1.0f);
384 glTranslated(cPosition.
GetX(), cPosition.
GetY(), cPosition.
GetZ());
386 glRotated(
ToDegrees(cXAngle).GetValue(), 1.0f, 0.0f, 0.0f);
387 glRotated(
ToDegrees(cYAngle).GetValue(), 0.0f, 1.0f, 0.0f);
388 glRotated(
ToDegrees(cZAngle).GetValue(), 0.0f, 0.0f, 1.0f);
396 glDisable(GL_LIGHTING);
401 glColor3f(1.0, 0.0, 1.0);
404 glColor3f(0.0, 1.0, 1.0);
408 glVertex3d(cStart.
GetX(), cStart.
GetY(), cStart.
GetZ());
413 glColor3f(0.0, 0.0, 0.0);
417 glVertex3d(cPoint.
GetX(), cPoint.
GetY(), cPoint.
GetZ());
421 glEnable(GL_LIGHTING);
430 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
431 glDisable(GL_LIGHTING);
433 glColor3f(1.0f, 1.0f, 1.0f);
437 glNormal3d(0.0f, 0.0f, -1.0f);
443 glNormal3d(0.0f, 0.0f, 1.0f);
452 glNormal3d(-1.0f, 0.0f, 0.0f);
458 glNormal3d(0.0f, -1.0f, 0.0f);
464 glNormal3d(1.0f, 0.0f, 0.0f);
470 glNormal3d(0.0f, 1.0f, 0.0f);
476 glEnable(GL_LIGHTING);
478 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
485 m_bFastForwarding =
false;
486 if(nTimerId != -1) killTimer(nTimerId);
495 m_bFastForwarding =
true;
496 if(nTimerId != -1) killTimer(nTimerId);
497 nTimerId = startTimer(1);
504 m_bFastForwarding =
false;
505 if(nTimerId != -1) killTimer(nTimerId);
515 if(m_bFastForwarding) {
517 m_nFrameCounter = m_nFrameCounter % m_nDrawFrameEvery;
518 if(m_nFrameCounter == 0) {
538 m_cSimulator.
Reset();
540 delete m_pcGroundTexture;
541 if(m_bUsingFloorTexture)
delete m_pcFloorTexture;
550 m_nDrawFrameEvery = n_every;
566 QToolTip::showText(pos() + geometry().center(), QString(
"Current camera: #%1").arg(n_camera+1));
582 switch(pc_event->key()) {
586 m_mapPressedKeys[DIRECTION_FORWARDS] =
true;
592 m_mapPressedKeys[DIRECTION_BACKWARDS] =
true;
598 m_mapPressedKeys[DIRECTION_LEFT] =
true;
604 m_mapPressedKeys[DIRECTION_RIGHT] =
true;
609 m_mapPressedKeys[DIRECTION_UP] =
true;
614 m_mapPressedKeys[DIRECTION_DOWN] =
true;
619 QOpenGLWidget::keyPressEvent(pc_event);
628 switch(pc_event->key()) {
632 m_mapPressedKeys[DIRECTION_FORWARDS] =
false;
638 m_mapPressedKeys[DIRECTION_BACKWARDS] =
false;
644 m_mapPressedKeys[DIRECTION_LEFT] =
false;
650 m_mapPressedKeys[DIRECTION_RIGHT] =
false;
655 m_mapPressedKeys[DIRECTION_UP] =
false;
660 m_mapPressedKeys[DIRECTION_DOWN] =
false;
665 QOpenGLWidget::keyPressEvent(pc_event);
682 glDisable(GL_LIGHTING);
684 glEnable(GL_TEXTURE_2D);
687 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
688 #ifdef ARGOS_WITH_FREEIMAGE
689 if(m_bUsingFloorTexture) {
693 m_pcFloorTexture->destroy();
694 m_pcFloorTexture->create();
696 m_pcFloorTexture->setData(QImage(
"/tmp/argos_floor.png"));
697 m_pcFloorTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,
698 QOpenGLTexture::Linear);
703 m_pcFloorTexture->bind();
705 glTexCoord2d(0.0f, 1.0f); glVertex3d(cArenaMinCorner.
GetX(), cArenaMinCorner.
GetY(), 0.0f);
706 glTexCoord2d(1.0f, 1.0f); glVertex3d(cArenaMaxCorner.
GetX(), cArenaMinCorner.
GetY(), 0.0f);
707 glTexCoord2d(1.0f, 0.0f); glVertex3d(cArenaMaxCorner.
GetX(), cArenaMaxCorner.
GetY(), 0.0f);
708 glTexCoord2d(0.0f, 0.0f); glVertex3d(cArenaMinCorner.
GetX(), cArenaMaxCorner.
GetY(), 0.0f);
714 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
716 m_pcGroundTexture->bind();
719 glTexCoord2d(0.0f, cArenaSize.
GetY()); glVertex3d(cArenaMinCorner.
GetX(), cArenaMinCorner.
GetY(), 0.0f);
720 glTexCoord2d(cArenaSize.
GetX(), cArenaSize.
GetY()); glVertex3d(cArenaMaxCorner.
GetX(), cArenaMinCorner.
GetY(), 0.0f);
721 glTexCoord2d(cArenaSize.
GetX(), 0.0f); glVertex3d(cArenaMaxCorner.
GetX(), cArenaMaxCorner.
GetY(), 0.0f);
722 glTexCoord2d(0.0f, 0.0f); glVertex3d(cArenaMinCorner.
GetX(), cArenaMaxCorner.
GetY(), 0.0f);
724 #ifdef ARGOS_WITH_FREEIMAGE
728 glDisable(GL_TEXTURE_2D);
729 if(m_bShowBoundary) {
731 glDisable(GL_CULL_FACE);
732 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
734 glColor3f(0.0f, 0.0f, 0.0f);
738 glVertex3d(cArenaMinCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMaxCorner.
GetZ());
739 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMaxCorner.
GetZ());
740 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMaxCorner.
GetZ());
741 glVertex3d(cArenaMinCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMaxCorner.
GetZ());
746 glVertex3d(cArenaMinCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMinCorner.
GetZ());
747 glVertex3d(cArenaMinCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMaxCorner.
GetZ());
748 glVertex3d(cArenaMinCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMaxCorner.
GetZ());
749 glVertex3d(cArenaMinCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMinCorner.
GetZ());
751 glVertex3d(cArenaMinCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMinCorner.
GetZ());
752 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMinCorner.
GetZ());
753 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMaxCorner.
GetZ());
754 glVertex3d(cArenaMinCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMaxCorner.
GetZ());
756 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMinCorner.
GetZ());
757 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMinCorner.
GetZ());
758 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMaxCorner.
GetZ());
759 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMinCorner.
GetY(), cArenaMaxCorner.
GetZ());
761 glVertex3d(cArenaMinCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMinCorner.
GetZ());
762 glVertex3d(cArenaMinCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMaxCorner.
GetZ());
763 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMaxCorner.
GetZ());
764 glVertex3d(cArenaMaxCorner.
GetX(), cArenaMaxCorner.
GetY(), cArenaMinCorner.
GetZ());
767 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
768 glEnable(GL_CULL_FACE);
771 glEnable(GL_LIGHTING);
795 if(! (pc_event->modifiers() & Qt::ShiftModifier)) {
796 if(! (pc_event->modifiers() & Qt::AltModifier)) {
797 m_bMouseGrabbed =
true;
798 m_cMouseGrabPos = pc_event->pos();
808 m_bMouseGrabbed =
false;
810 pc_event->pos().y());
821 if(m_bMouseGrabbed &&
823 (pc_event->modifiers() & Qt::ControlModifier)) {
826 if(pcEntity ==
nullptr) {
829 if(pcCompEntity !=
nullptr && pcCompEntity->HasComponent(
"body")) {
834 m_bMouseGrabbed =
false;
847 pc_event->pos().y());
852 CVector3 cOldPos(pcEntity->GetOriginAnchor().Position);
853 if(pcEntity->MoveTo(cNewPos, pcEntity->GetOriginAnchor().Orientation)) {
854 m_cUserFunctions.
EntityMoved(pcEntity->GetRootEntity(), cOldPos, cNewPos);
866 m_bMouseGrabbed =
false;
876 if(m_bMouseGrabbed) {
877 if(! (pc_event->modifiers() & Qt::ControlModifier)) {
881 if(pc_event->buttons() == Qt::LeftButton) {
882 if (m_bInvertMouse) m_cCamera.
Rotate( pc_event->pos() - m_cMouseGrabPos);
883 else m_cCamera.
Rotate( m_cMouseGrabPos - pc_event->pos());
884 m_cMouseGrabPos = pc_event->pos();
887 else if(pc_event->buttons() == Qt::RightButton) {
888 QPoint cDelta(pc_event->pos() - m_cMouseGrabPos);
889 m_cCamera.
Move(-cDelta.y(), cDelta.x(), 0);
890 m_cMouseGrabPos = pc_event->pos();
893 else if(pc_event->buttons() == Qt::MiddleButton) {
894 QPoint cDelta(pc_event->pos() - m_cMouseGrabPos);
895 m_cCamera.
Move(0, 0, cDelta.y());
896 m_cMouseGrabPos = pc_event->pos();
910 if(m_sSelectionInfo.
IsSelected && (pc_event->modifiers() & Qt::ControlModifier)) {
913 if(pcEntity ==
nullptr) {
916 if(pcCompEntity !=
nullptr && pcCompEntity->HasComponent(
"body")) {
927 CDegrees cDegrees(pc_event->angleDelta().y() / 8);
929 CQuaternion cOldOrientation(pcEntity->GetOriginAnchor().Orientation);
930 CQuaternion cNewOrientation(cOldOrientation * cRotation);
931 if(pcEntity->MoveTo(pcEntity->GetOriginAnchor().Position, cNewOrientation)) {
932 m_cUserFunctions.
EntityRotated(pcEntity->GetRootEntity(), cOldOrientation, cNewOrientation);
957 SInt32 nForwardsBackwards = 0;
961 if(m_mapPressedKeys[DIRECTION_UP]) nUpDown++;
962 if(m_mapPressedKeys[DIRECTION_DOWN]) nUpDown--;
963 if(m_mapPressedKeys[DIRECTION_LEFT]) nSideways++;
964 if(m_mapPressedKeys[DIRECTION_RIGHT]) nSideways--;
965 if(m_mapPressedKeys[DIRECTION_FORWARDS]) nForwardsBackwards++;
966 if(m_mapPressedKeys[DIRECTION_BACKWARDS]) nForwardsBackwards--;
968 if(nForwardsBackwards != 0 ||
971 m_cCamera.
Move(15 * nForwardsBackwards,
983 QOpenGLWidget::resizeEvent(pc_event);
985 QToolTip::showText(pos() + geometry().center(), QString(
"Size: %1 x %2").arg(pc_event->size().width()).arg(pc_event->size().height()));
994 std::string strBuffer;
998 size_t unEndPos = strBuffer.find_last_not_of(
"/ \t");
999 if(unEndPos != std::string::npos) {
1000 strBuffer = strBuffer.substr(0, unEndPos+1);
1004 if(!cDirectory.exists()) {
1005 THROW_ARGOSEXCEPTION(
"QTOpenGL: frame grabbing directory \"" << strBuffer <<
"\" does not exist. Create it first!");
1008 strBuffer =
"frame_";
1014 Format = strBuffer.c_str();
1020 "headless_grabbing",
1024 strBuffer =
"1600x1200";
1026 "headless_frame_size",
1031 Size = QSize(dims[0], dims[1]);
1035 "headless_frame_rate",
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
signed int SInt32
32-bit signed integer.
unsigned int UInt32
32-bit unsigned integer.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
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.
bool GetClosestEmbodiedEntityIntersectedByRay(SEmbodiedEntityIntersectionItem &s_item, const CRay3 &c_ray)
Returns the closest intersection with an embodied entity to the ray start.
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.
void ParseValues(std::istream &str_input, UInt32 un_num_fields, T *pt_field_buffer, const char ch_delimiter='\n')
CDegrees ToDegrees(const CRadians &c_radians)
Converts CRadians to CDegrees.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
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.
CRadians ToRadians(const CDegrees &c_degrees)
Converts CDegrees to CRadians.
Basic class for an entity that contains other entities.
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
An entity that contains a pointer to the user-defined controller.
std::vector< CVector3 > & GetIntersectionPoints()
Returns the list of intersection points.
std::vector< std::pair< bool, CRay3 > > & GetCheckedRays()
Returns the list of checked rays.
This entity is a link to a body in the physics engine.
const SBoundingBox & GetBoundingBox() const
Returns the bounding box of this embodied entity.
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
std::vector< CEntity * > TVector
A vector of entities.
CEntity & GetRootEntity()
Returns the root entity containing this entity.
bool HasChanged() const
Returns true if the floor color has changed.
void ClearChanged()
Marks the floor color as not changed.
const CQuaternion & GetOrientation() const
const CVector3 & GetPosition() const
CEmbodiedEntity * IntersectedEntity
static Real GetSimulationClockTick()
Returns the simulation clock tick.
CQuaternion Orientation
The orientation of the anchor wrt the global coordinate system.
CVector3 Position
The position of the anchor wrt the global coordinate system.
bool IsExperimentFinished() const
Returns true if the experiment has finished.
void UpdateSpace()
Performs an update step of the space.
void Reset()
Resets the experiment.
CFloorEntity & GetFloorEntity()
Returns the floor entity.
UInt32 GetSimulationClock() const
Returns the current value of the simulation clock.
const CVector3 & GetArenaSize() const
Returns the arena size.
const CVector3 & GetArenaCenter() const
Returns the arena center.
CEntity::TVector & GetRootEntityVector()
Returns a vector of all the root entities in the space.
The exception that wraps all errors in ARGoS.
It defines the basic type CRadians, used to store an angle value in radians.
It defines the basic type CDegrees, used to store an angle value in degrees.
Real GetValue() const
Returns the value in degrees.
void ToEulerAngles(CRadians &c_z_angle, CRadians &c_y_angle, CRadians &c_x_angle) const
bool Intersects(const CPlane &c_plane, CVector3 &c_point) const
Real GetX() const
Returns the x coordinate of this vector.
Real GetY() const
Returns the y coordinate of this vector.
static const CVector3 Z
The z axis.
Real GetZ() const
Returns the z coordinate of this vector.
void SetActivePlacement(UInt32 n_index)
void Move(SInt32 n_forwards_backwards, SInt32 n_sideways, SInt32 n_up_down)
SPlacement & GetActivePlacement()
void Rotate(const QPoint &c_delta)
CDegrees YFieldOfView
The focal length of the camera.
Real LensFocalLength
The focal length of the lens (if this was a real camera)
void CalculateYFieldOfView()
Calculates the value of YFieldOfView.
const QString & GetTextureDir() const
The QTOpenGL user functions.
virtual void EntityMoved(CEntity &c_entity, const CVector3 &c_old_pos, const CVector3 &c_new_pos)
Called every time an entity is moved.
virtual void EntityDeselected(CEntity &c_entity)
Called every time an entity is deselected.
virtual void MouseKeyPressed(QMouseEvent *pc_event)
Called when a mouse key is pressed.
virtual void EntityRotated(CEntity &c_entity, const CQuaternion &c_old_orientation, const CQuaternion &c_new_orientation)
Called every time an entity is rotated.
virtual void MouseMoved(QMouseEvent *pc_event)
Called when the mouse is moved.
virtual void KeyPressed(QKeyEvent *pc_event)
Called when a key press event occurs.
virtual void KeyReleased(QKeyEvent *pc_event)
Called when a key release event occurs.
virtual void Call(CEntity &c_entity)
Calls a user method for the given entity.
virtual void DrawInWorld()
Drawing hook executed after all objects have been drawn.
virtual void EntitySelected(CEntity &c_entity)
Called every time an entity is selected.
virtual void DrawOverlay(QPainter &c_painter)
Drawing hook to put graphics on top of the OpenGL window.
virtual void MouseKeyReleased(QMouseEvent *pc_event)
Called when a mouse key is released.
CEntity * GetSelectedEntity()
Returns the currently selected entity, or NULL if none is selected.
void StepExperiment()
Executes one experiment time step.
CVector3 GetWindowCoordInWorld(int n_x, int n_y)
Returns the position in the world corresponding to the given window coordinate.
virtual void mouseReleaseEvent(QMouseEvent *pc_event)
virtual void wheelEvent(QWheelEvent *pc_event)
void KeyPressed(QKeyEvent *pc_event)
Handles key press events.
CRay3 RayFromWindowCoord(int n_x, int n_y)
Casts a ray from the given window coordinate.
virtual ~CQTOpenGLWidget()
Class destructor.
void SelectEntity(CEntity &c_entity)
Selects the passed entity.
void KeyReleased(QKeyEvent *pc_event)
Handles key release events.
void SetCameraFocalLength(double f_length)
Sets the focal length of the current camera.
void FastForwardExperiment()
Fast forwards the experiment.
void EntitySelected(CEntity *pc_entity)
Emitted when an entity is selected.
void DrawRays(CControllableEntity &c_entity)
Draws a ray.
void PlayExperiment()
Plays the experiment.
void ResetExperiment()
Resets the state of the experiment to its state right after initialization.
virtual void mouseMoveEvent(QMouseEvent *pc_event)
void EntityDeselected(CEntity *pc_entity)
Emitted when an entity is deselected.
void DrawEntity(CPositionalEntity &c_entity)
Draws a positional entity.
void DeselectEntity()
Deselects the currently selected entity.
void SetGrabFrame(bool b_grab_on)
Toggles frame grabbing.
virtual void keyReleaseEvent(QKeyEvent *pc_event)
void DrawBoundingBox(CEmbodiedEntity &c_entity)
Draws the bounding box of an embodied entity.
virtual void keyPressEvent(QKeyEvent *pc_event)
void SetDrawFrameEvery(int n_every)
When fast-forwarding, sets every how many steps a frame must be drawn.
void SelectInScene(UInt32 un_x, UInt32 un_y)
Selects the entity closest to the camera at the given screen coordinates.
virtual void paintGL()
Logic for scene drawing.
CQTOpenGLWidget(QWidget *pc_parent, CQTOpenGLMainWindow &c_main_window, CQTOpenGLUserFunctions &c_user_functions)
Class constructor.
void ExperimentDone()
Emitted when the experiment is finished.
virtual void initializeGL()
Called when the GL context must be initialized.
virtual void mousePressEvent(QMouseEvent *pc_event)
void PauseExperiment()
Pauses the experiment.
virtual void resizeEvent(QResizeEvent *pc_event)
void StepDone(int n_step)
Emitted whenever a time step has been executed.
void SetCamera(int n_camera)
Sets the current camera in use.
virtual void timerEvent(QTimerEvent *pc_event)
void Init(TConfigurationNode &t_tree)