#ifndef MAPVIEW_H #define MAPVIEW_H #include <../misc/fixc11.h> #include #include #include #include #include #include #include "elements/Path.h" #include "elements/ColorPoints.h" #include "elements/Object.h" #include "../nav/State.h" namespace Floorplan { class IndoorMap; } class Renderable; class Path; class MapView : public QOpenGLWidget, protected QOpenGLFunctions { Q_OBJECT private: QMatrix4x4 matProject; QMatrix4x4 matView; QVector3D lightPos; QVector3D eyePos; QBasicTimer timer; std::vector elements; Path* path = nullptr; ColorPoints* colorPoints = nullptr; Object* leDude = nullptr; struct LookAt { Point3 eye_m = Point3(0,0,1); Point3 dir = Point3(1,0,-0.1); Point3 dirOffset = Point3(0,0,0); Point3 getDir() const {return dir + dirOffset;} } lookAt; struct MouseState { float x = 0; float y = 0; bool down = false; } mouseState; void rebuildLookat(); void clear(); public: MapView(QWidget* parent = 0); /** set the map to display */ void setMap(Floorplan::IndoorMap* map); /** the position to look at + looking direction */ void setLookAt(const Point3 pos, const Point3 dir = Point3(1, 0, -0.1)); /** set the eye's looking direction (looking from eye into this direction) */ void setLookDir(const Point3 dir); /** set the eye's position (looking from here) */ void setLookEye(const Point3 eye_m); /** set the currently estimated position */ void setCurrentEstimation(const Point3 pos, const Point3 dir); /** set the path to disply */ void setPath(const std::vector& path); /** NOTE: must be called from Qt's main thread! */ /** set the path to disply */ Q_INVOKABLE void setPath(const void* path) { setPath( (const DijkstraPath*) path); } /** NOTE: must be called from Qt's main thread! */ /** set the path to disply */ template void setPath(const DijkstraPath* path) { this->path->set(*path); } /** NOTE: must be called from Qt's main thread! */ void showGridImportance(Grid* grid) { this->colorPoints->setFromGridImportance(grid); } /** NOTE: must be called from Qt's main thread! */ Q_INVOKABLE void showParticles(const void* particles) { showParticles((const std::vector>*) particles); } /** NOTE: must be called from Qt's main thread! */ void showParticles(const std::vector>* particles) { this->colorPoints->setFromParticles(*particles); } enum RenderMode { NORMAL, TRANSPARENT, OUTLINE, }; RenderMode renderMode = RenderMode::NORMAL; void toggleRenderMode(); public slots: void mousePressEvent(QMouseEvent*); void mouseMoveEvent(QMouseEvent*); void mouseReleaseEvent(QMouseEvent*); void keyPressEvent(QKeyEvent*); protected: void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; void initializeGL(); void paintGL(); void resizeGL(int width, int height); private: bool isGLInitialized = false; void draw(); }; #endif // MAPVIEW_H