changed 3D rendering
added pan/zoom gesture
This commit is contained in:
@@ -31,7 +31,6 @@ SOURCES += \
|
|||||||
params/ElementParamWidget.cpp \
|
params/ElementParamWidget.cpp \
|
||||||
params/LayerParamWidget.cpp \
|
params/LayerParamWidget.cpp \
|
||||||
params/ActionWidget.cpp \
|
params/ActionWidget.cpp \
|
||||||
params/ToolBox.cpp \
|
|
||||||
mapview/model/MapModel.cpp \
|
mapview/model/MapModel.cpp \
|
||||||
tree/MapTreeModel.cpp \
|
tree/MapTreeModel.cpp \
|
||||||
mapview/3D/MapView3D.cpp \
|
mapview/3D/MapView3D.cpp \
|
||||||
@@ -43,12 +42,13 @@ SOURCES += \
|
|||||||
params/MetaEditModel.cpp \
|
params/MetaEditModel.cpp \
|
||||||
mapview/2D/MapView2D.cpp \
|
mapview/2D/MapView2D.cpp \
|
||||||
misc/LINTView.cpp \
|
misc/LINTView.cpp \
|
||||||
mapview/3DNavMesh/QNavMeshSettings.cpp \
|
|
||||||
mapview/3D/misc/Cube.cpp \
|
mapview/3D/misc/Cube.cpp \
|
||||||
mapview/3D/misc/Shader.cpp \
|
mapview/3D/misc/Shader.cpp \
|
||||||
mapview/3D/misc/Window.cpp \
|
mapview/3D/misc/Window.cpp \
|
||||||
mapview/3D/misc/Outline.cpp \
|
mapview/3D/misc/Outline.cpp \
|
||||||
mapview/3D/misc/Handrail.cpp
|
mapview/3D/misc/Handrail.cpp \
|
||||||
|
mapview/3D/navMesh/QNavMeshSettings.cpp \
|
||||||
|
params/ToolBoxWidget.cpp
|
||||||
|
|
||||||
|
|
||||||
HEADERS += MainWindow.h \
|
HEADERS += MainWindow.h \
|
||||||
@@ -111,12 +111,8 @@ HEADERS += MainWindow.h \
|
|||||||
mapview/3D/MV3DElementFloorObstaclePillar.h \
|
mapview/3D/MV3DElementFloorObstaclePillar.h \
|
||||||
mapview/3D/MV3DElementAccessPoint.h \
|
mapview/3D/MV3DElementAccessPoint.h \
|
||||||
mapview/3D/misc/Cube.h \
|
mapview/3D/misc/Cube.h \
|
||||||
mapview/3D/MV3DElementFloorOutlinePolygon.h \
|
|
||||||
mapview/3D/MV3DElementFloorOutline.h \
|
mapview/3D/MV3DElementFloorOutline.h \
|
||||||
mapview/3D/misc/Polygon.h \
|
mapview/3D/misc/Polygon.h \
|
||||||
mapview/3DGrid/GridModel.h \
|
|
||||||
mapview/3DGrid/GridRenderer.h \
|
|
||||||
mapview/3DGrid/MyNode.h \
|
|
||||||
mapview/3D/MV3DElementStair.h \
|
mapview/3D/MV3DElementStair.h \
|
||||||
mapview/model/MMFloorStair.h \
|
mapview/model/MMFloorStair.h \
|
||||||
mapview/model/MMFloorStairs.h \
|
mapview/model/MMFloorStairs.h \
|
||||||
@@ -165,16 +161,20 @@ HEADERS += MainWindow.h \
|
|||||||
mapview/2D/tools/ToolNewGroundTruth.h \
|
mapview/2D/tools/ToolNewGroundTruth.h \
|
||||||
mapview/2D/tools/ToolNewPOI.h \
|
mapview/2D/tools/ToolNewPOI.h \
|
||||||
mapview/3D/MV3DElementElevator.h \
|
mapview/3D/MV3DElementElevator.h \
|
||||||
mapview/3DNavMesh/NavMeshRenderer.h \
|
|
||||||
mapview/3DNavMesh/NavMeshModel.h \
|
|
||||||
mapview/3DNavMesh/QNavMeshSettings.h \
|
|
||||||
fixC11.h \
|
fixC11.h \
|
||||||
mapview/3D/misc/Shader.h \
|
mapview/3D/misc/Shader.h \
|
||||||
mapview/3D/misc/Camera.h \
|
mapview/3D/misc/Camera.h \
|
||||||
mapview/3D/misc/Renderable3D.h \
|
mapview/3D/misc/Renderable3D.h \
|
||||||
mapview/3D/misc/Window.h \
|
mapview/3D/misc/Window.h \
|
||||||
mapview/3D/misc/Outline.h \
|
mapview/3D/misc/Outline.h \
|
||||||
mapview/3D/misc/Handrail.h
|
mapview/3D/misc/Handrail.h \
|
||||||
|
mapview/3D/grid/GridModel.h \
|
||||||
|
mapview/3D/grid/GridRenderer.h \
|
||||||
|
mapview/3D/grid/MyNode.h \
|
||||||
|
mapview/3D/navMesh/NavMeshModel.h \
|
||||||
|
mapview/3D/navMesh/NavMeshRenderer.h \
|
||||||
|
mapview/3D/navMesh/QNavMeshSettings.h \
|
||||||
|
mapview/3D/misc/TriangleData.h
|
||||||
|
|
||||||
|
|
||||||
FORMS += MainWindow.ui
|
FORMS += MainWindow.ui
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
|
||||||
#include "mapview/3DGrid/GridRenderer.h"
|
#include "mapview/3D/grid/GridRenderer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ MainController::MainController() {
|
|||||||
//mapModel->load("/apps/map24b.xml");
|
//mapModel->load("/apps/map24b.xml");
|
||||||
//mapModel->load("/apps/SHL41.xml");
|
//mapModel->load("/apps/SHL41.xml");
|
||||||
|
|
||||||
mapModel->load("/mnt/vm/paper/diss/data/maps/SHL41_nm.xml");
|
//mapModel->load("/mnt/vm/paper/diss/data/maps/SHL41_nm.xml");
|
||||||
//mapModel->load("/apps/paper/diss/data/maps/SHL41_nm.xml");
|
//mapModel->load("/apps/paper/diss/data/maps/SHL41_nm.xml");
|
||||||
|
|
||||||
//mapModel->load("/apps/paper/diss/data/maps/map_elevator2.xml");
|
//mapModel->load("/apps/paper/diss/data/maps/map_elevator2.xml");
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
|
|
||||||
// toolbox
|
// toolbox
|
||||||
QDockWidget* toolBoxWidgetDock = new QDockWidget("", this); toolBoxWidgetDock->setWidget(toolBoxWidget);
|
QDockWidget* toolBoxWidgetDock = new QDockWidget("", this); toolBoxWidgetDock->setWidget(toolBoxWidget);
|
||||||
|
toolBoxWidgetDock->setFixedWidth(64-11);
|
||||||
addDockWidget(Qt::LeftDockWidgetArea, toolBoxWidgetDock);
|
addDockWidget(Qt::LeftDockWidgetArea, toolBoxWidgetDock);
|
||||||
|
|
||||||
// layers
|
// layers
|
||||||
|
|||||||
17
main.cpp
17
main.cpp
@@ -15,19 +15,22 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
QString str = R"(
|
QString str = R"(
|
||||||
|
|
||||||
QDockWidget {
|
QDockWidget {
|
||||||
border: 1px solid #000;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDockWidget::title {
|
QDockWidget::title {
|
||||||
text-align: left; /* align the text to the left */
|
/* text-align: left;
|
||||||
background: #ccc;
|
background: #ccc;
|
||||||
padding: 1px;
|
padding: 1px; */
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDockWidget::title:hover {
|
|
||||||
|
|
||||||
|
/* QDockWidget::title:hover {
|
||||||
background: #bbb;
|
background: #bbb;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ MapView2D::MapView2D(QWidget* parent) : QOpenGLWidget(parent) {
|
|||||||
// defaults
|
// defaults
|
||||||
s.setScale(5);
|
s.setScale(5);
|
||||||
|
|
||||||
|
// android
|
||||||
|
setAttribute(Qt::WA_AcceptTouchEvents);
|
||||||
|
grabGesture(Qt::PanGesture);
|
||||||
|
grabGesture(Qt::PinchGesture);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapView2D::paintGL() {
|
void MapView2D::paintGL() {
|
||||||
@@ -92,3 +97,57 @@ void MapView2D::mouseReleaseEvent(QMouseEvent* e) {
|
|||||||
tools.mouseReleaseEvent(this, e);
|
tools.mouseReleaseEvent(this, e);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// android
|
||||||
|
bool MapView2D::event(QEvent* event) {
|
||||||
|
|
||||||
|
if (event->type() == QEvent::Gesture) {
|
||||||
|
return gestureEvent(static_cast<QGestureEvent*>(event));
|
||||||
|
} else {
|
||||||
|
return QWidget::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MapView2D::gestureEvent(QGestureEvent* event) {
|
||||||
|
//qCDebug(lcExample) << "gestureEvent():" << event;
|
||||||
|
if (QGesture *swipe = event->gesture(Qt::SwipeGesture)) {
|
||||||
|
//swipeTriggered(static_cast<QSwipeGesture *>(swipe));
|
||||||
|
} else if (QGesture *pan = event->gesture(Qt::PanGesture))
|
||||||
|
panTriggered(static_cast<QPanGesture *>(pan));
|
||||||
|
if (QGesture *pinch = event->gesture(Qt::PinchGesture)) {
|
||||||
|
pinchTriggered(static_cast<QPinchGesture *>(pinch));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapView2D::pinchTriggered(QPinchGesture* gesture) {
|
||||||
|
|
||||||
|
tools.pinchTriggered(this, gesture);
|
||||||
|
update();
|
||||||
|
|
||||||
|
// QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
|
||||||
|
// if (changeFlags & QPinchGesture::RotationAngleChanged) {
|
||||||
|
//// qreal rotationDelta = gesture->rotationAngle() - gesture->lastRotationAngle();
|
||||||
|
//// rotationAngle += rotationDelta;
|
||||||
|
//// qCDebug(lcExample) << "pinchTriggered(): rotate by" <<
|
||||||
|
//// rotationDelta << "->" << rotationAngle;
|
||||||
|
// }
|
||||||
|
// if (changeFlags & QPinchGesture::ScaleFactorChanged) {
|
||||||
|
//// currentStepScaleFactor = gesture->totalScaleFactor();
|
||||||
|
//// qCDebug(lcExample) << "pinchTriggered(): zoom by" <<
|
||||||
|
//// gesture->scaleFactor() << "->" << currentStepScaleFactor;
|
||||||
|
// std::cout << gesture->totalScaleFactor() << std::endl;
|
||||||
|
// }
|
||||||
|
// if (gesture->state() == Qt::GestureFinished) {
|
||||||
|
//// scaleFactor *= currentStepScaleFactor;
|
||||||
|
//// currentStepScaleFactor = 1;
|
||||||
|
// }
|
||||||
|
// update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapView2D::panTriggered(QPanGesture* gesture) {
|
||||||
|
tools.panTriggered(this, gesture);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
class MapModel;
|
class MapModel;
|
||||||
class MV2DElement;
|
class MV2DElement;
|
||||||
|
|
||||||
|
class QGestureEvent;
|
||||||
|
class QPinchGesture;
|
||||||
|
class QSwipeGesture;
|
||||||
#include "tools/Tools.h"
|
#include "tools/Tools.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -80,6 +83,12 @@ protected:
|
|||||||
|
|
||||||
void keyPressEvent(QKeyEvent* e);
|
void keyPressEvent(QKeyEvent* e);
|
||||||
|
|
||||||
|
// android
|
||||||
|
bool event(QEvent *e) override;
|
||||||
|
bool gestureEvent(QGestureEvent* event);
|
||||||
|
void pinchTriggered(QPinchGesture* gesture);
|
||||||
|
void panTriggered(QPanGesture* gesture);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAP2D_H
|
#endif // MAP2D_H
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include "../Painter.h"
|
#include "../Painter.h"
|
||||||
|
|
||||||
|
class QPinchGesture;
|
||||||
|
class QPanGesture;
|
||||||
class MapView2D;
|
class MapView2D;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +48,9 @@ public:
|
|||||||
|
|
||||||
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) { (void) m; (void) e; return false; }
|
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) { (void) m; (void) e; return false; }
|
||||||
|
|
||||||
|
virtual bool pinchTriggered(MapView2D* m, QPinchGesture* g) { (void) m; (void) g; return false; }
|
||||||
|
virtual bool panTriggered(MapView2D* m, QPanGesture* g) { (void) m; (void) g; return false; }
|
||||||
|
|
||||||
virtual void paintBefore(MapView2D* m, Painter& p) { (void) m; (void) p; }
|
virtual void paintBefore(MapView2D* m, Painter& p) { (void) m; (void) p; }
|
||||||
virtual void paintAfter(MapView2D* m, Painter& p) { (void) m; (void) p; }
|
virtual void paintAfter(MapView2D* m, Painter& p) { (void) m; (void) p; }
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
class ToolMapZoom : public Tool {
|
class ToolMapZoom : public Tool {
|
||||||
|
|
||||||
|
float startScale = NAN;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const std::string getName() const override {
|
const std::string getName() const override {
|
||||||
@@ -32,6 +34,34 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool pinchTriggered(MapView2D *m, QPinchGesture* g) override {
|
||||||
|
|
||||||
|
Scaler& s = m->getScaler();
|
||||||
|
// https://doc.qt.io/qt-5/qtwidgets-gestures-imagegestures-example.html
|
||||||
|
|
||||||
|
QPinchGesture::ChangeFlags changeFlags = g->changeFlags();
|
||||||
|
if (changeFlags & QPinchGesture::RotationAngleChanged) {
|
||||||
|
// qreal rotationDelta = gesture->rotationAngle() - gesture->lastRotationAngle();
|
||||||
|
// rotationAngle += rotationDelta;
|
||||||
|
// qCDebug(lcExample) << "pinchTriggered(): rotate by" <<
|
||||||
|
// rotationDelta << "->" << rotationAngle;
|
||||||
|
}
|
||||||
|
if (changeFlags & QPinchGesture::ScaleFactorChanged) {
|
||||||
|
if (startScale != startScale) {startScale = s.getScale();}
|
||||||
|
s.setScale(startScale * g->totalScaleFactor());
|
||||||
|
}
|
||||||
|
if (g->state() == Qt::GestureFinished) {
|
||||||
|
startScale = NAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s.getScale() > 1000) {s.setScale(1000);}
|
||||||
|
if (s.getScale() < 5) {s.setScale(5);}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOOLMAPZOOM_H
|
#endif // TOOLMAPZOOM_H
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include "Tool.h"
|
#include "Tool.h"
|
||||||
#include "../MapView2D.h"
|
#include "../MapView2D.h"
|
||||||
|
|
||||||
|
#include <QPanGesture>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this tool allows moving the 2D map
|
* this tool allows moving the 2D map
|
||||||
* using the mouse
|
* using the mouse
|
||||||
@@ -48,6 +50,11 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool panTriggered(MapView2D *m, QPanGesture *g) override {
|
||||||
|
m->getScaler().addOffset(g->delta().x(), g->delta().y());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// virtual void keyPressEvent(MapView2D* m, QKeyEvent* e) override {
|
// virtual void keyPressEvent(MapView2D* m, QKeyEvent* e) override {
|
||||||
// (void) m;
|
// (void) m;
|
||||||
// (void) e;
|
// (void) e;
|
||||||
|
|||||||
@@ -67,25 +67,23 @@ public:
|
|||||||
// the visible map-rect
|
// the visible map-rect
|
||||||
const Rect r = p.getScaler().getMapVisible(w, h, step);
|
const Rect r = p.getScaler().getMapVisible(w, h, step);
|
||||||
|
|
||||||
QRect rx(rs,0,w-1-rs,rs);
|
QRect rx(rs,0,w-0-rs,rs);
|
||||||
QRect ry(0,rs,rs,h-1-rs);
|
QRect ry(0,rs,rs,h-1-rs);
|
||||||
|
|
||||||
// background
|
// background
|
||||||
{
|
{
|
||||||
|
|
||||||
// samller font
|
|
||||||
QFont f = p.p->font(); f.setPointSize(8);
|
|
||||||
p.p->setFont(f);
|
|
||||||
|
|
||||||
// outline
|
// outline
|
||||||
p.setPen(Qt::darkGray);
|
p.setPen(Qt::darkGray);
|
||||||
|
p.setBrush(QColor(240,240,240));
|
||||||
|
|
||||||
|
|
||||||
// x-axis
|
// x-axis
|
||||||
QLinearGradient gx(0,0,0,rs); gx.setColorAt(0, c1); gx.setColorAt(1, c2); p.setBrush(gx);
|
//QLinearGradient gx(0,0,0,rs); gx.setColorAt(0, c1); gx.setColorAt(1, c2); p.setBrush(gx);
|
||||||
p.p->drawRect(rx);
|
p.p->drawRect(rx);
|
||||||
|
|
||||||
// y-axis
|
// y-axis
|
||||||
QLinearGradient gy(0,0,rs,0); gy.setColorAt(0, c2); gy.setColorAt(1, c1); p.setBrush(gy);
|
//QLinearGradient gy(0,0,rs,0); gy.setColorAt(0, c2); gy.setColorAt(1, c1); p.setBrush(gy);
|
||||||
p.p->drawRect(ry);
|
p.p->drawRect(ry);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,6 +99,10 @@ public:
|
|||||||
p.setPenBrush(Qt::black, Qt::NoBrush);
|
p.setPenBrush(Qt::black, Qt::NoBrush);
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
|
// samller font
|
||||||
|
QFont f = p.p->font(); f.setPointSize(8);
|
||||||
|
p.p->setFont(f);
|
||||||
|
|
||||||
// coordinates
|
// coordinates
|
||||||
QRect ru(0,0,rs-1,rs-1);
|
QRect ru(0,0,rs-1,rs-1);
|
||||||
p.p->fillRect(ru, Qt::white);
|
p.p->fillRect(ru, Qt::white);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "../../../fixC11.h"
|
#include "../../../fixC11.h"
|
||||||
#include "Tool.h"
|
#include "Tool.h"
|
||||||
|
|
||||||
|
class QPinchGesture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* combine several tools under the interface for one tool
|
* combine several tools under the interface for one tool
|
||||||
*/
|
*/
|
||||||
@@ -118,6 +120,17 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool pinchTriggered(MapView2D* m, QPinchGesture* g) {//override {
|
||||||
|
if (mainTool) {mainTool->pinchTriggered(m, g);}
|
||||||
|
for (Tool* t : backgroundTools) { if(t->pinchTriggered(m, g)) {return true;} }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool panTriggered(MapView2D* m, QPanGesture* g) {//override {
|
||||||
|
if (mainTool) {mainTool->panTriggered(m, g);}
|
||||||
|
for (Tool* t : backgroundTools) { if(t->panTriggered(m, g)) {return true;} }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void paintBefore(MapView2D* m, Painter& p) {//override {
|
virtual void paintBefore(MapView2D* m, Painter& p) {//override {
|
||||||
for (Tool* t : backgroundTools) {t->paintBefore(m, p);}
|
for (Tool* t : backgroundTools) {t->paintBefore(m, p);}
|
||||||
|
|||||||
@@ -82,11 +82,21 @@ protected:
|
|||||||
if (tmp.pol) {delete tmp.pol;}
|
if (tmp.pol) {delete tmp.pol;}
|
||||||
tmp.pol = new Polygon();
|
tmp.pol = new Polygon();
|
||||||
|
|
||||||
|
// all to-be-added polygons (filter!)
|
||||||
for (Floorplan::FloorOutlinePolygon* poly : polys) {
|
for (Floorplan::FloorOutlinePolygon* poly : polys) {
|
||||||
if (!include(poly)) {continue;}
|
if (!include(poly)) {continue;}
|
||||||
switch (poly->method) {
|
switch (poly->method) {
|
||||||
case Floorplan::OutlineMethod::ADD: tmp.pol->add(poly->poly); break;
|
case Floorplan::OutlineMethod::ADD: tmp.pol->add(poly->poly); break;
|
||||||
|
case Floorplan::OutlineMethod::REMOVE: break;
|
||||||
|
default: throw 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// all to-be-removed polygons (NO filter!)
|
||||||
|
for (Floorplan::FloorOutlinePolygon* poly : polys) {
|
||||||
|
switch (poly->method) {
|
||||||
case Floorplan::OutlineMethod::REMOVE: tmp.pol->remove(poly->poly); break;
|
case Floorplan::OutlineMethod::REMOVE: tmp.pol->remove(poly->poly); break;
|
||||||
|
case Floorplan::OutlineMethod::ADD: break;
|
||||||
default: throw 1;
|
default: throw 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
#ifndef MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
|
||||||
#define MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
|
||||||
|
|
||||||
//#include <Indoor/floorplan/v2/Floorplan.h>
|
|
||||||
|
|
||||||
//#include "misc/Cube.h"
|
|
||||||
//#include "MV3DElement.h"
|
|
||||||
|
|
||||||
//class MV3DElementFloorOutlinePolygon : public MV3DElement {
|
|
||||||
|
|
||||||
// Floorplan::Floor* f;
|
|
||||||
// Floorplan::FloorOutlinePolygon* poly;
|
|
||||||
|
|
||||||
//public:
|
|
||||||
|
|
||||||
// /** ctor */
|
|
||||||
// MV3DElementFloorOutlinePolygon(Floorplan::Floor* f, Floorplan::FloorOutlinePolygon* poly) : f(f), poly(poly) {
|
|
||||||
// ;
|
|
||||||
// }
|
|
||||||
|
|
||||||
//protected:
|
|
||||||
|
|
||||||
|
|
||||||
// /** repaint me */
|
|
||||||
// void paintGL() override {
|
|
||||||
|
|
||||||
// throw "deprecated!!!";
|
|
||||||
|
|
||||||
// glDisable(GL_CULL_FACE);
|
|
||||||
|
|
||||||
//// switch (poly->method) {
|
|
||||||
//// case Floorplan::OutlineMethod::ADD:
|
|
||||||
//// glColor3f(1,1,1);
|
|
||||||
//// break;
|
|
||||||
//// case Floorplan::OutlineMethod::REMOVE:
|
|
||||||
//// glColor3f(0.3, 0.3, 0.3);
|
|
||||||
//// break;
|
|
||||||
//// }
|
|
||||||
|
|
||||||
// if (poly->outdoor) {
|
|
||||||
// glColor3f(0, 0, 0.5);
|
|
||||||
// } else {
|
|
||||||
// glColor3f(0.3, 0.3, 0.3);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// glBegin(GL_POLYGON);
|
|
||||||
// glNormal3f(0,1,0);
|
|
||||||
// for (Point2 p2 : poly->poly.points) {
|
|
||||||
// Point3 p3(p2.x, p2.y, f->atHeight);
|
|
||||||
// glVertex3f(p3.x, p3.z, p3.y);
|
|
||||||
// }
|
|
||||||
// glEnd();
|
|
||||||
|
|
||||||
// glEnable(GL_CULL_FACE);
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
//};
|
|
||||||
|
|
||||||
#endif // MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "misc/Cube.h"
|
#include "misc/Cube.h"
|
||||||
#include "MV3DElement.h"
|
#include "MV3DElement.h"
|
||||||
#include "misc/Shader.h"
|
#include "misc/Shader.h"
|
||||||
|
#include "misc/TriangleData.h"
|
||||||
|
|
||||||
class MV3DElementStair : public MV3DElement {
|
class MV3DElementStair : public MV3DElement {
|
||||||
|
|
||||||
@@ -25,11 +26,7 @@ protected:
|
|||||||
/** repaint me */
|
/** repaint me */
|
||||||
void render(const RenderSettings& rs) override {
|
void render(const RenderSettings& rs) override {
|
||||||
|
|
||||||
//glDisable(GL_CULL_FACE);
|
TriangleData data;
|
||||||
|
|
||||||
|
|
||||||
std::vector<float> vertices;
|
|
||||||
std::vector<float> normals;
|
|
||||||
|
|
||||||
const std::vector<Floorplan::StairPart> parts = stair->getParts();
|
const std::vector<Floorplan::StairPart> parts = stair->getParts();
|
||||||
const std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(parts, floor);
|
const std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(parts, floor);
|
||||||
@@ -46,66 +43,26 @@ protected:
|
|||||||
Point3 n = Math::normal(p1,p2);
|
Point3 n = Math::normal(p1,p2);
|
||||||
if (n.z < 0) {n = -n;}
|
if (n.z < 0) {n = -n;}
|
||||||
|
|
||||||
vertices.insert(vertices.end(), {quad.p1.x, quad.p1.y, quad.p1.z});
|
// upper side
|
||||||
vertices.insert(vertices.end(), {quad.p2.x, quad.p2.y, quad.p2.z});
|
data.addTriangle(quad.p1, quad.p2, quad.p3, n);
|
||||||
vertices.insert(vertices.end(), {quad.p3.x, quad.p3.y, quad.p3.z});
|
data.addTriangle(quad.p3, quad.p4, quad.p1, n);
|
||||||
|
|
||||||
vertices.insert(vertices.end(), {quad.p3.x, quad.p3.y, quad.p3.z});
|
// lower side
|
||||||
vertices.insert(vertices.end(), {quad.p4.x, quad.p4.y, quad.p4.z});
|
data.addTriangle(quad.p2, quad.p1, quad.p3, -n);
|
||||||
vertices.insert(vertices.end(), {quad.p1.x, quad.p1.y, quad.p1.z});
|
data.addTriangle(quad.p4, quad.p3, quad.p1, -n);
|
||||||
|
|
||||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
||||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
||||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
||||||
|
|
||||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
||||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
||||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.shader->bind();
|
rs.shader->bind();
|
||||||
rs.shader->setModelMatrix(QMatrix4x4());
|
rs.shader->setModelMatrix(QMatrix4x4());
|
||||||
rs.shader->setColor(1.0, 0.55, 0.55);
|
rs.shader->setColor(1.0, 0.55, 0.55);
|
||||||
rs.shader->setVertices(vertices.data());
|
rs.shader->setVertices(data.getVertices().data());
|
||||||
rs.shader->setNormals(normals.data());
|
rs.shader->setNormals(data.getNormals().data());
|
||||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size()/3);
|
glDrawArrays(GL_TRIANGLES, 0, data.getVertices().size()/3);
|
||||||
rs.shader->unsetVertices();
|
rs.shader->unsetVertices();
|
||||||
rs.shader->unsetNormals();
|
rs.shader->unsetNormals();
|
||||||
rs.shader->release();
|
rs.shader->release();
|
||||||
|
|
||||||
/*
|
|
||||||
TODO_GL
|
|
||||||
//glColor3f(1.0, 0.55, 0.55);
|
|
||||||
glColor3f(0.3, 0.3, 0.3);
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
|
|
||||||
const std::vector<Floorplan::StairPart> parts = stair->getParts();
|
|
||||||
const std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(parts, floor);
|
|
||||||
|
|
||||||
for (int i = 0; i < (int) parts.size(); ++i) {
|
|
||||||
|
|
||||||
//const Floorplan::StairPart& part = parts[i];
|
|
||||||
const Floorplan::Quad3& quad = quads[i];
|
|
||||||
|
|
||||||
//const Floorplan::Quad3 quad = part.getQuad(floor);
|
|
||||||
const Point3 p1 = quad.p2-quad.p1;
|
|
||||||
const Point3 p2 = quad.p4-quad.p1;
|
|
||||||
|
|
||||||
Point3 n = Math::normal(p1,p2);
|
|
||||||
if (n.z < 0) {n = -n;}
|
|
||||||
|
|
||||||
glNormal3f(n.x, n.z, n.z);
|
|
||||||
glVertex3f(quad.p1.x, quad.p1.z, quad.p1.y);
|
|
||||||
glVertex3f(quad.p2.x, quad.p2.z, quad.p2.y);
|
|
||||||
glVertex3f(quad.p3.x, quad.p3.z, quad.p3.y);
|
|
||||||
glVertex3f(quad.p4.x, quad.p4.z, quad.p4.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isTransparent() const override {
|
bool isTransparent() const override {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
#include "../model/MapModelElement.h"
|
#include "../model/MapModelElement.h"
|
||||||
#include "../model/MapModel.h"
|
#include "../model/MapModel.h"
|
||||||
|
|
||||||
#include "../3DGrid/GridModel.h"
|
#include "../3D/grid/GridModel.h"
|
||||||
#include "../3DGrid/GridRenderer.h"
|
#include "../3D/grid/GridRenderer.h"
|
||||||
|
|
||||||
#include "../3DNavMesh/NavMeshModel.h"
|
#include "../3D/navMesh/NavMeshModel.h"
|
||||||
#include "../3DNavMesh/NavMeshRenderer.h"
|
#include "../3D/navMesh/NavMeshRenderer.h"
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,6 @@ static float cube_normals[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//static Shader* shader = nullptr;
|
|
||||||
|
|
||||||
Cube::Cube(Point3 pos, float size) : pos(pos), size(size,size,size), rot(0,0,0) {
|
Cube::Cube(Point3 pos, float size) : pos(pos), size(size,size,size), rot(0,0,0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef CUBE_H
|
#ifndef CUBE_H
|
||||||
#define CUBE_H
|
#define CUBE_H
|
||||||
|
|
||||||
|
#include "../../../fixC11.h"
|
||||||
#include <Indoor/geo/Point3.h>
|
#include <Indoor/geo/Point3.h>
|
||||||
#include "Renderable3D.h"
|
#include "Renderable3D.h"
|
||||||
|
|
||||||
@@ -26,82 +27,6 @@ public:
|
|||||||
|
|
||||||
void render(const RenderSettings& rs) override;
|
void render(const RenderSettings& rs) override;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
void paintGL(Shader* shader);
|
|
||||||
|
|
||||||
TODO_GL
|
|
||||||
|
|
||||||
glColor3f(color.x, color.y, color.z);
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
|
|
||||||
// 3) move to destination
|
|
||||||
glTranslatef(pos.x, pos.z, pos.y); // swap yz
|
|
||||||
|
|
||||||
// 2) rotate
|
|
||||||
glRotatef(rot.x, 1, 0, 0);
|
|
||||||
glRotatef(rot.y, 0, 0, 1); // swap yz
|
|
||||||
glRotatef(rot.z, 0, 1, 0);
|
|
||||||
|
|
||||||
// 1) scale
|
|
||||||
glScalef(size.x, size.z, size.y); // swap yz
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
|
|
||||||
// bottom
|
|
||||||
glNormal3f(0,-1,0);
|
|
||||||
glVertex3f(+s, -s, -s);
|
|
||||||
glVertex3f(+s, -s, +s);
|
|
||||||
glVertex3f(-s, -s, +s);
|
|
||||||
glVertex3f(-s, -s, -s);
|
|
||||||
|
|
||||||
// top
|
|
||||||
glNormal3f(0,+1,0);
|
|
||||||
glVertex3f(-s, +s, -s);
|
|
||||||
glVertex3f(-s, +s, +s);
|
|
||||||
glVertex3f(+s, +s, +s);
|
|
||||||
glVertex3f(+s, +s, -s);
|
|
||||||
|
|
||||||
// left
|
|
||||||
glNormal3f(-1,0,0);
|
|
||||||
glVertex3f(-s, -s, -s);
|
|
||||||
glVertex3f(-s, -s, +s);
|
|
||||||
glVertex3f(-s, +s, +s);
|
|
||||||
glVertex3f(-s, +s, -s);
|
|
||||||
|
|
||||||
// right
|
|
||||||
glNormal3f(+1,0,0);
|
|
||||||
glVertex3f(+s, +s, -s);
|
|
||||||
glVertex3f(+s, +s, +s);
|
|
||||||
glVertex3f(+s, -s, +s);
|
|
||||||
glVertex3f(+s, -s, -s);
|
|
||||||
|
|
||||||
// front
|
|
||||||
glNormal3f(0,0,+1);
|
|
||||||
glVertex3f(+s, +s, +s);
|
|
||||||
glVertex3f(-s, +s, +s);
|
|
||||||
glVertex3f(-s, -s, +s);
|
|
||||||
glVertex3f(+s, -s, +s);
|
|
||||||
|
|
||||||
// rear
|
|
||||||
glNormal3f(0,0,-1);
|
|
||||||
glVertex3f(+s, -s, -s);
|
|
||||||
glVertex3f(-s, -s, -s);
|
|
||||||
glVertex3f(-s, +s, -s);
|
|
||||||
glVertex3f(+s, +s, -s);
|
|
||||||
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CUBE_H
|
#endif // CUBE_H
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "../../../fixC11.h"
|
||||||
|
|
||||||
#include "Handrail.h"
|
#include "Handrail.h"
|
||||||
|
|
||||||
#include <Indoor/geo/Point3.h>
|
#include <Indoor/geo/Point3.h>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "../../../fixC11.h"
|
||||||
|
|
||||||
#include "Outline.h"
|
#include "Outline.h"
|
||||||
|
|
||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
@@ -19,17 +21,15 @@ void Outline::render(const RenderSettings& rs) {
|
|||||||
|
|
||||||
// show both sides
|
// show both sides
|
||||||
//glDisable(GL_CULL_FACE);
|
//glDisable(GL_CULL_FACE);
|
||||||
glEnable(GL_CULL_FACE);
|
//glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
rs.shader->setColor(color.x, color.y, color.z);
|
rs.shader->setColor(color.x, color.y, color.z);
|
||||||
rs.shader->setVertices(vertices.data());
|
rs.shader->setVertices(triangles.getVertices().data());
|
||||||
rs.shader->setNormals(normals.data());
|
rs.shader->setNormals(triangles.getNormals().data());
|
||||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size() / 3);
|
glDrawArrays(GL_TRIANGLES, 0, triangles.getVertices().size() / 3);
|
||||||
rs.shader->unsetVertices();
|
rs.shader->unsetVertices();
|
||||||
rs.shader->unsetNormals();
|
rs.shader->unsetNormals();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
rs.shader->release();
|
rs.shader->release();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,8 +39,7 @@ void Outline::setColor(float r, float g, float b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Outline::clear() {
|
void Outline::clear() {
|
||||||
normals.clear();
|
triangles.clear();
|
||||||
vertices.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Outline::add(std::vector<std::vector<Point3>>& triangles) {
|
void Outline::add(std::vector<std::vector<Point3>>& triangles) {
|
||||||
@@ -54,18 +53,22 @@ void Outline::add(std::vector<std::vector<Point3>>& triangles) {
|
|||||||
|
|
||||||
const Point3 n = cross(p2-p1, p3-p1);
|
const Point3 n = cross(p2-p1, p3-p1);
|
||||||
if (n.z < 0) {
|
if (n.z < 0) {
|
||||||
vertices.push_back(p1.x); vertices.push_back(p1.y); vertices.push_back(p1.z);
|
|
||||||
vertices.push_back(p3.x); vertices.push_back(p3.y); vertices.push_back(p3.z);
|
|
||||||
vertices.push_back(p2.x); vertices.push_back(p2.y); vertices.push_back(p2.z);
|
|
||||||
} else {
|
|
||||||
vertices.push_back(p1.x); vertices.push_back(p1.y); vertices.push_back(p1.z);
|
|
||||||
vertices.push_back(p2.x); vertices.push_back(p2.y); vertices.push_back(p2.z);
|
|
||||||
vertices.push_back(p3.x); vertices.push_back(p3.y); vertices.push_back(p3.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
normals.push_back(0); normals.push_back(0); normals.push_back(1);
|
// upper side (floor)
|
||||||
normals.push_back(0); normals.push_back(0); normals.push_back(1);
|
this->triangles.addTriangle(p1, p3, p2, Point3(0,0,+1));
|
||||||
normals.push_back(0); normals.push_back(0); normals.push_back(1);
|
|
||||||
|
// facing downwards (ceiling)
|
||||||
|
this->triangles.addTriangle(p1, p2, p3, Point3(0,0,-1));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// upper side (floor)
|
||||||
|
this->triangles.addTriangle(p1, p2, p3, Point3(0,0,+1));
|
||||||
|
|
||||||
|
// facing downwards (ceiling)
|
||||||
|
this->triangles.addTriangle(p1, p3, p2, Point3(0,0,-1));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
#include "Renderable3D.h"
|
#include "Renderable3D.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <Indoor/geo/Point3.h>
|
#include <Indoor/geo/Point3.h>
|
||||||
|
#include "TriangleData.h"
|
||||||
|
|
||||||
class Outline : public Renderable3D {
|
class Outline : public Renderable3D {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<float> vertices;
|
TriangleData triangles;
|
||||||
std::vector<float> normals;
|
|
||||||
Point3 color;
|
Point3 color;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
77
mapview/3D/misc/TriangleData.h
Normal file
77
mapview/3D/misc/TriangleData.h
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#ifndef TRIANGLEDATA_H
|
||||||
|
#define TRIANGLEDATA_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <Indoor/geo/Point3.h>
|
||||||
|
|
||||||
|
class TriangleData {
|
||||||
|
|
||||||
|
std::vector<float> vertices;
|
||||||
|
std::vector<float> normals;
|
||||||
|
std::vector<float> rgba;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void addTriangle(Point3 p1, Point3 p2, Point3 p3) {
|
||||||
|
|
||||||
|
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||||
|
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||||
|
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n) {
|
||||||
|
|
||||||
|
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||||
|
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||||
|
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||||
|
|
||||||
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||||
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||||
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n, const float r, const float g, const float b, const float a) {
|
||||||
|
|
||||||
|
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||||
|
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||||
|
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||||
|
|
||||||
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||||
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||||
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||||
|
|
||||||
|
rgba.insert(rgba.end(), {r,g,b,a});
|
||||||
|
rgba.insert(rgba.end(), {r,g,b,a});
|
||||||
|
rgba.insert(rgba.end(), {r,g,b,a});
|
||||||
|
rgba.insert(rgba.end(), {r,g,b,a});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void addLine(Point3 p1, Point3 p2, const float r, const float g, const float b, const float a) {
|
||||||
|
|
||||||
|
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||||
|
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||||
|
|
||||||
|
rgba.insert(rgba.end(), {r,g,b,a});
|
||||||
|
rgba.insert(rgba.end(), {r,g,b,a});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
vertices.clear();
|
||||||
|
normals.clear();
|
||||||
|
rgba.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<float>& getVertices() {return vertices;}
|
||||||
|
|
||||||
|
const std::vector<float>& getNormals() {return normals;}
|
||||||
|
|
||||||
|
const std::vector<float>& getRGBA() {return rgba;}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TRIANGLEDATA_H
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "../../../fixC11.h"
|
||||||
|
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
|
||||||
|
|||||||
157
mapview/3D/navMesh/NavMeshRenderer.h
Normal file
157
mapview/3D/navMesh/NavMeshRenderer.h
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
#ifndef NAVMESHRENDERER_H
|
||||||
|
#define NAVMESHRENDERER_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <Indoor/navMesh/NavMesh.h>
|
||||||
|
#include <Indoor/navMesh/NavMeshTriangle.h>
|
||||||
|
#include <Indoor/navMesh/NavMeshType.h>
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QOpenGLWidget>
|
||||||
|
|
||||||
|
#include "../misc/Renderable3D.h"
|
||||||
|
#include "../misc/Shader.h"
|
||||||
|
#include "../misc/TriangleData.h"
|
||||||
|
|
||||||
|
class NavMeshRenderer {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// settings
|
||||||
|
//GridRendererColorMode colorMode = GridRendererColorMode::SHOW_NODE_IMPORTANCE;
|
||||||
|
bool showEdges = false;
|
||||||
|
|
||||||
|
struct Color {
|
||||||
|
float r,g,b;
|
||||||
|
Color() : r(1), g(0), b(0) {;}
|
||||||
|
Color(float r, float g, float b) : r(r), g(g), b(b) {;}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** node color depending on the node's type. see ctor */
|
||||||
|
Color colors[200];
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** ctor */
|
||||||
|
NavMeshRenderer() {
|
||||||
|
|
||||||
|
colors[GridNode::TYPE_FLOOR] = Color(0.4, 0.4, 0.4);
|
||||||
|
colors[GridNode::TYPE_STAIR] = Color(0,0,1);
|
||||||
|
colors[GridNode::TYPE_ELEVATOR] = Color(0,0,1);
|
||||||
|
colors[GridNode::TYPE_DOOR] = Color(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
colors[GridNode::TYPE_OUTDOOR] = Color(0.0, 0.5, 0.0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// void setNodeColorMode(const GridRendererColorMode mode) {this->colorMode = mode;}
|
||||||
|
void setShowEdges(const bool show) {this->showEdges = show;}
|
||||||
|
|
||||||
|
|
||||||
|
/** render the given grid using GL commands */
|
||||||
|
void render(const RenderSettings& rs, NM::NavMesh<NM::NavMeshTriangle>* navMesh, QOpenGLWidget* dst) {
|
||||||
|
|
||||||
|
if (navMesh == nullptr) {return;}
|
||||||
|
|
||||||
|
|
||||||
|
rs.shader->bind();
|
||||||
|
rs.shader->setModelMatrix(QMatrix4x4());
|
||||||
|
|
||||||
|
TriangleData data;
|
||||||
|
|
||||||
|
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
||||||
|
|
||||||
|
Point3 color;
|
||||||
|
|
||||||
|
switch (tria->getType()) {
|
||||||
|
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.8, 0.8, 0.8); break;
|
||||||
|
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.1, 0.8, 0.1); break;
|
||||||
|
case (int) NM::NavMeshType::DOOR: color = Point3(0.7, 0.7, 0.8); break;
|
||||||
|
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.5, 0.5, 0.5); break;
|
||||||
|
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.6, 0.6, 0.6); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.addTriangle(tria->getP1(), tria->getP3(), tria->getP2(), Point3(0,0,1), color.x, color.y, color.z, 1.0f);
|
||||||
|
|
||||||
|
// vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z});
|
||||||
|
// vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z});
|
||||||
|
// vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z});
|
||||||
|
|
||||||
|
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||||
|
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||||
|
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
rs.shader->setVertices(data.getVertices().data());
|
||||||
|
rs.shader->setVertexColor(data.getRGBA().data());
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, data.getVertices().size()/3);
|
||||||
|
rs.shader->unsetVertices();
|
||||||
|
rs.shader->unsetVertexColor();
|
||||||
|
|
||||||
|
data.clear();
|
||||||
|
|
||||||
|
|
||||||
|
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
||||||
|
|
||||||
|
Point3 color;
|
||||||
|
|
||||||
|
switch (tria->getType()) {
|
||||||
|
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.6, 0.6, 0.6); break;
|
||||||
|
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.0, 0.6, 0.0); break;
|
||||||
|
case (int) NM::NavMeshType::DOOR: color = Point3(0.5, 0.5, 0.6); break;
|
||||||
|
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.4, 0.4, 0.4); break;
|
||||||
|
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.4, 0.4, 0.4); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float o = 0.001f;
|
||||||
|
data.addLine(tria->getP1(), tria->getP2(), color.x, color.y, color.z, 1);
|
||||||
|
data.addLine(tria->getP2(), tria->getP3(), color.x, color.y, color.z, 1);
|
||||||
|
data.addLine(tria->getP3(), tria->getP1(), color.x, color.y, color.z, 1);
|
||||||
|
|
||||||
|
// vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z+o});
|
||||||
|
// vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z+o});
|
||||||
|
|
||||||
|
// vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z+o});
|
||||||
|
// vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z+o});
|
||||||
|
|
||||||
|
// vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z+o});
|
||||||
|
// vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z+o});
|
||||||
|
|
||||||
|
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||||
|
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||||
|
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||||
|
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||||
|
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||||
|
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
rs.shader->setVertices(data.getVertices().data());
|
||||||
|
rs.shader->setVertexColor(data.getRGBA().data());
|
||||||
|
glDrawArrays(GL_LINES, 0, data.getVertices().size()/3);
|
||||||
|
rs.shader->unsetVertices();
|
||||||
|
rs.shader->unsetVertexColor();
|
||||||
|
|
||||||
|
rs.shader->release();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// std::vector<MyNode> lint() {
|
||||||
|
// std::vector<MyNode> vec;
|
||||||
|
// lintStair(vec);
|
||||||
|
// return vec;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void lintStair(std::vector<MyNode>& vec) {
|
||||||
|
// for (MyNode& n1 : *grid) {
|
||||||
|
// if (n1.getNumNeighbors() <= 5) { vec.push_back(n1);}
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAVMESHRENDERER_H
|
||||||
@@ -1,237 +0,0 @@
|
|||||||
#ifndef NAVMESHRENDERER_H
|
|
||||||
#define NAVMESHRENDERER_H
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <Indoor/navMesh/NavMesh.h>
|
|
||||||
#include <Indoor/navMesh/NavMeshTriangle.h>
|
|
||||||
#include <Indoor/navMesh/NavMeshType.h>
|
|
||||||
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QOpenGLWidget>
|
|
||||||
|
|
||||||
#include "../3D/misc/Renderable3D.h"
|
|
||||||
#include "../3D/misc/Shader.h"
|
|
||||||
|
|
||||||
class NavMeshRenderer {
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// settings
|
|
||||||
//GridRendererColorMode colorMode = GridRendererColorMode::SHOW_NODE_IMPORTANCE;
|
|
||||||
bool showEdges = false;
|
|
||||||
|
|
||||||
struct Color {
|
|
||||||
float r,g,b;
|
|
||||||
Color() : r(1), g(0), b(0) {;}
|
|
||||||
Color(float r, float g, float b) : r(r), g(g), b(b) {;}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** node color depending on the node's type. see ctor */
|
|
||||||
Color colors[200];
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
/** ctor */
|
|
||||||
NavMeshRenderer() {
|
|
||||||
|
|
||||||
colors[GridNode::TYPE_FLOOR] = Color(0.4, 0.4, 0.4);
|
|
||||||
colors[GridNode::TYPE_STAIR] = Color(0,0,1);
|
|
||||||
colors[GridNode::TYPE_ELEVATOR] = Color(0,0,1);
|
|
||||||
colors[GridNode::TYPE_DOOR] = Color(0.0, 0.0, 0.0);
|
|
||||||
|
|
||||||
colors[GridNode::TYPE_OUTDOOR] = Color(0.0, 0.5, 0.0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// void setNodeColorMode(const GridRendererColorMode mode) {this->colorMode = mode;}
|
|
||||||
void setShowEdges(const bool show) {this->showEdges = show;}
|
|
||||||
|
|
||||||
|
|
||||||
/** render the given grid using GL commands */
|
|
||||||
void render(const RenderSettings& rs, NM::NavMesh<NM::NavMeshTriangle>* navMesh, QOpenGLWidget* dst) {
|
|
||||||
|
|
||||||
if (navMesh == nullptr) {return;}
|
|
||||||
|
|
||||||
|
|
||||||
rs.shader->bind();
|
|
||||||
rs.shader->setModelMatrix(QMatrix4x4());
|
|
||||||
|
|
||||||
std::vector<float> vertices;
|
|
||||||
std::vector<float> colors;
|
|
||||||
|
|
||||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
|
||||||
|
|
||||||
Point3 color;
|
|
||||||
|
|
||||||
switch (tria->getType()) {
|
|
||||||
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.8, 0.8, 0.8); break;
|
|
||||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.1, 0.8, 0.1); break;
|
|
||||||
case (int) NM::NavMeshType::DOOR: color = Point3(0.7, 0.7, 0.8); break;
|
|
||||||
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.5, 0.5, 0.5); break;
|
|
||||||
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.6, 0.6, 0.6); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z});
|
|
||||||
vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z});
|
|
||||||
vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z});
|
|
||||||
|
|
||||||
colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
|
||||||
colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
|
||||||
colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
rs.shader->setVertices(vertices.data());
|
|
||||||
rs.shader->setVertexColor(colors.data());
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size()/3);
|
|
||||||
rs.shader->unsetVertices();
|
|
||||||
rs.shader->unsetVertexColor();
|
|
||||||
|
|
||||||
vertices.clear();
|
|
||||||
colors.clear();
|
|
||||||
|
|
||||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
|
||||||
|
|
||||||
Point3 color;
|
|
||||||
|
|
||||||
switch (tria->getType()) {
|
|
||||||
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.6, 0.6, 0.6); break;
|
|
||||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.0, 0.6, 0.0); break;
|
|
||||||
case (int) NM::NavMeshType::DOOR: color = Point3(0.5, 0.5, 0.6); break;
|
|
||||||
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.4, 0.4, 0.4); break;
|
|
||||||
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.4, 0.4, 0.4); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float o = 0.001f;
|
|
||||||
vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z+o});
|
|
||||||
vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z+o});
|
|
||||||
|
|
||||||
vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z+o});
|
|
||||||
vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z+o});
|
|
||||||
|
|
||||||
vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z+o});
|
|
||||||
vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z+o});
|
|
||||||
|
|
||||||
colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
|
||||||
colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
|
||||||
colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
|
||||||
colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
|
||||||
colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
|
||||||
colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
rs.shader->setVertices(vertices.data());
|
|
||||||
rs.shader->setVertexColor(colors.data());
|
|
||||||
glDrawArrays(GL_LINES, 0, vertices.size()/3);
|
|
||||||
rs.shader->unsetVertices();
|
|
||||||
rs.shader->unsetVertexColor();
|
|
||||||
|
|
||||||
rs.shader->release();
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
TODO_GL
|
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
|
|
||||||
const float s = 2;
|
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
|
||||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (tria->getType()) {
|
|
||||||
case (int) NM::NavMeshType::FLOOR_INDOOR: glColor3f(0.8, 0.8, 0.8); break;
|
|
||||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: glColor3f(0.1, 0.8, 0.1); break;
|
|
||||||
case (int) NM::NavMeshType::DOOR: glColor3f(0.7, 0.7, 0.8); break;
|
|
||||||
case (int) NM::NavMeshType::STAIR_LEVELED: glColor3f(0.5, 0.5, 0.5); break;
|
|
||||||
case (int) NM::NavMeshType::STAIR_SKEWED: glColor3f(0.6, 0.6, 0.6); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertex3f(tria->getP1().x, tria->getP1().z, tria->getP1().y);
|
|
||||||
glVertex3f(tria->getP2().x, tria->getP2().z, tria->getP2().y);
|
|
||||||
glVertex3f(tria->getP3().x, tria->getP3().z, tria->getP3().y);
|
|
||||||
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
|
|
||||||
glEnable(GL_MULTISAMPLE);
|
|
||||||
//glEnable(GL_LINE_SMOOTH);
|
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
//glColor3f(0.2,0.2,0.2);
|
|
||||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
|
||||||
|
|
||||||
switch (tria->getType()) {
|
|
||||||
case (int) NM::NavMeshType::FLOOR_INDOOR: glColor3f(0.6, 0.6, 0.6); break;
|
|
||||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: glColor3f(0.0, 0.6, 0.0); break;
|
|
||||||
case (int) NM::NavMeshType::DOOR: glColor3f(0.5, 0.5, 0.6); break;
|
|
||||||
case (int) NM::NavMeshType::STAIR_LEVELED: glColor3f(0.4, 0.4, 0.4); break;
|
|
||||||
case (int) NM::NavMeshType::STAIR_SKEWED: glColor3f(0.4, 0.4, 0.4); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertex3f(tria->getP1().x, tria->getP1().z+0.01, tria->getP1().y);
|
|
||||||
glVertex3f(tria->getP2().x, tria->getP2().z+0.01, tria->getP2().y);
|
|
||||||
|
|
||||||
glVertex3f(tria->getP2().x, tria->getP2().z+0.01, tria->getP2().y);
|
|
||||||
glVertex3f(tria->getP3().x, tria->getP3().z+0.01, tria->getP3().y);
|
|
||||||
|
|
||||||
glVertex3f(tria->getP3().x, tria->getP3().z+0.01, tria->getP3().y);
|
|
||||||
glVertex3f(tria->getP1().x, tria->getP1().z+0.01, tria->getP1().y);
|
|
||||||
|
|
||||||
// glBegin(GL_LINE_LOOP);
|
|
||||||
// glVertex3f(tria->getP1().x, tria->getP1().z+0.01, tria->getP1().y);
|
|
||||||
// glVertex3f(tria->getP2().x, tria->getP2().z+0.01, tria->getP2().y);
|
|
||||||
// glVertex3f(tria->getP3().x, tria->getP3().z+0.01, tria->getP3().y);
|
|
||||||
// glEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
|
||||||
|
|
||||||
|
|
||||||
// qp.drawText(20,20, "sdfsdkflsdfjasfklsdklfsdklfsdf");
|
|
||||||
// qp.drawText(20,-20, "sdfsdkflsdfjasfklsdklfsdklfsdf");
|
|
||||||
// qp.drawText(0.5,0.5, "sdfsdkflsdfjasfklsdklfsdklfsdf");
|
|
||||||
// qp.end();
|
|
||||||
|
|
||||||
// renderText(1,1,1, "123");
|
|
||||||
|
|
||||||
const QString str1 = "Triangles: " + QString::number(navMesh->getNumTriangles());
|
|
||||||
const QString str2 = "Size: ~" + QString::number(navMesh->getNumTriangles() * sizeof(NM::NavMeshTriangle) / 1024) + " kB";
|
|
||||||
|
|
||||||
glColor3f(0.0, 0.0, 0.0);
|
|
||||||
dst->renderText(20,20, str1);
|
|
||||||
dst->renderText(20,35, str2);
|
|
||||||
|
|
||||||
// dst->renderText(0,0, "2342342342342423423423423423423432");
|
|
||||||
// dst->renderText(0.1, 0.1, 0.1, "lsdfsdfsdfsdfsdfsdfsdfol");
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// std::vector<MyNode> lint() {
|
|
||||||
// std::vector<MyNode> vec;
|
|
||||||
// lintStair(vec);
|
|
||||||
// return vec;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void lintStair(std::vector<MyNode>& vec) {
|
|
||||||
// for (MyNode& n1 : *grid) {
|
|
||||||
// if (n1.getNumNeighbors() <= 5) { vec.push_back(n1);}
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // NAVMESHRENDERER_H
|
|
||||||
@@ -22,9 +22,6 @@ class MapModel : public QObject, public MapLayerListener {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
///** wrapper-classes for all elements */
|
|
||||||
//std::vector<MapModelElement*> selElements;
|
|
||||||
|
|
||||||
/** the map's root-layer containing all other layers */
|
/** the map's root-layer containing all other layers */
|
||||||
MapLayer* root = nullptr;
|
MapLayer* root = nullptr;
|
||||||
|
|
||||||
@@ -74,6 +71,7 @@ public:
|
|||||||
if (root) {delete root; root = nullptr;}
|
if (root) {delete root; root = nullptr;}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** load map from file */
|
||||||
void load(const std::string& file) {
|
void load(const std::string& file) {
|
||||||
|
|
||||||
emit aboutToReset();
|
emit aboutToReset();
|
||||||
@@ -90,6 +88,7 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** save map to file */
|
||||||
void save(const std::string& file) {
|
void save(const std::string& file) {
|
||||||
|
|
||||||
Floorplan::Writer::writeToFile(im, file);
|
Floorplan::Writer::writeToFile(im, file);
|
||||||
|
|||||||
Reference in New Issue
Block a user