diff --git a/MainController.cpp b/MainController.cpp index c88a85f..f33052c 100644 --- a/MainController.cpp +++ b/MainController.cpp @@ -94,7 +94,7 @@ MainController::MainController() { connect(mw, &MainWindow::onGridShowEdges, [&] (const bool show) {mw->getMapView3D()->getGridRenderer()->setShowEdges(show);} ); - mapModel->load("../IndoorMap/maps/SHL32.xml"); + mapModel->load("../IndoorMap/maps/SHL33a.xml"); //mapModel->resize(0.983, 0.983, 1, -0.2, -0.3, 0); diff --git a/mapview/3D/MV3DElementFloorObstacleDoor.h b/mapview/3D/MV3DElementFloorObstacleDoor.h index 00223d6..01bf481 100644 --- a/mapview/3D/MV3DElementFloorObstacleDoor.h +++ b/mapview/3D/MV3DElementFloorObstacleDoor.h @@ -24,7 +24,7 @@ public: /** repaint me */ void paintGL() override { - glColor3f(0,1,0); + glColor3f(0.4, 0.4, 0.4); Plane p(fo->from, fo->to, f->atHeight, fo->height); p.paintGL(); diff --git a/mapview/3D/MV3DElementFloorOutline.h b/mapview/3D/MV3DElementFloorOutline.h index 211548b..541a657 100644 --- a/mapview/3D/MV3DElementFloorOutline.h +++ b/mapview/3D/MV3DElementFloorOutline.h @@ -15,6 +15,14 @@ class MV3DElementFloorOutline : public MV3DElement { Floorplan::Floor* f; Floorplan::FloorOutline* out; + struct ToRender { + Point2 cacheSum; + Polygon* pol = nullptr; + std::vector> trias; + }; + + std::unordered_map elements; + public: /** ctor */ @@ -31,35 +39,82 @@ protected: /** repaint me */ void paintGL() override { + rebuildIfNeeded(); + + for (auto& it : elements) { + + //Polygon& pol = it.second->pol; + std::vector>& trias = it.second->trias; + + if (it.first == "outdoor") { + glColor3f(0.0, 0.5, 0.0); + } else { + glColor3f(0.2, 0.2, 0.2); + } + + glDisable(GL_CULL_FACE); + for (const std::vector& tria : trias) { + glNormal3f(0, 1, 0); + glBegin(GL_TRIANGLE_STRIP); + for (const Point3& p3 : tria) { + glVertex3f(p3.x, p3.z, p3.y); + } + glEnd(); + } + glEnable(GL_CULL_FACE); + + } + + } + + void rebuildIfNeeded() { + + auto filterIndoor = [] (const Floorplan::FloorOutlinePolygon* p) {return p->outdoor == false;}; + auto filterOutdoor = [] (const Floorplan::FloorOutlinePolygon* p) {return p->outdoor == true;}; + + if (elements.empty()) { + elements["indoor"] = new ToRender(); + elements["outdoor"] = new ToRender(); + } + + rebuildIfNeeded(filterIndoor, elements["indoor"]); + rebuildIfNeeded(filterOutdoor, elements["outdoor"]); + + } + + template void rebuildIfNeeded(Filter include, ToRender* dst) { + + const std::vector& polys = *out; + + // get number of points for rebuild-check + Point2 cacheSum(0,0); + for (Floorplan::FloorOutlinePolygon* poly : polys) { + if (!include(poly)) {continue;} + for (Point2 pt : poly->poly.points) { + cacheSum += pt; + } + } + + // already up to date? + if (cacheSum == dst->cacheSum) {return;} + dst->cacheSum = cacheSum; + + // rebuild std::vector add; std::vector rem; - - std::vector polys = *out; - - Polygon pol; + if (dst->pol) {delete dst->pol;} + dst->pol = new Polygon(); for (Floorplan::FloorOutlinePolygon* poly : polys) { + if (!include(poly)) {continue;} switch (poly->method) { - case Floorplan::OutlineMethod::ADD: pol.add(poly->poly); break; - case Floorplan::OutlineMethod::REMOVE: pol.remove(poly->poly); break; + case Floorplan::OutlineMethod::ADD: dst->pol->add(poly->poly); break; + case Floorplan::OutlineMethod::REMOVE: dst->pol->remove(poly->poly); break; default: throw 1; } } - std::vector> trias = pol.get(f->atHeight); - - glColor3f(0.2, 0.2, 0.2); - glDisable(GL_CULL_FACE); - for (const std::vector& tria : trias) { - glBegin(GL_TRIANGLE_STRIP); - for (const Point3& p3 : tria) { - glVertex3f(p3.x, p3.z, p3.y); - } - glEnd(); - } - glEnable(GL_CULL_FACE); - - + dst->trias = dst->pol->get(f->atHeight); } diff --git a/mapview/3D/MV3DElementFloorOutlinePolygon.h b/mapview/3D/MV3DElementFloorOutlinePolygon.h index 00ad604..34ef9ea 100644 --- a/mapview/3D/MV3DElementFloorOutlinePolygon.h +++ b/mapview/3D/MV3DElementFloorOutlinePolygon.h @@ -1,53 +1,60 @@ #ifndef MV3DELEMENTFLOOROUTLINEPOLYGON_H #define MV3DELEMENTFLOOROUTLINEPOLYGON_H -#include +//#include -#include "misc/Cube.h" -#include "MV3DElement.h" +//#include "misc/Cube.h" +//#include "MV3DElement.h" -class MV3DElementFloorOutlinePolygon : public MV3DElement { +//class MV3DElementFloorOutlinePolygon : public MV3DElement { - Floorplan::Floor* f; - Floorplan::FloorOutlinePolygon* poly; +// Floorplan::Floor* f; +// Floorplan::FloorOutlinePolygon* poly; -public: +//public: - /** ctor */ - MV3DElementFloorOutlinePolygon(Floorplan::Floor* f, Floorplan::FloorOutlinePolygon* poly) : f(f), poly(poly) { - ; - } +// /** ctor */ +// MV3DElementFloorOutlinePolygon(Floorplan::Floor* f, Floorplan::FloorOutlinePolygon* poly) : f(f), poly(poly) { +// ; +// } -protected: +//protected: - /** repaint me */ - void paintGL() override { +// /** repaint me */ +// void paintGL() override { - glDisable(GL_CULL_FACE); +// throw "deprecated!!!"; - switch (poly->method) { - case Floorplan::OutlineMethod::ADD: - glColor3f(1,1,1); - break; - case Floorplan::OutlineMethod::REMOVE: - glColor3f(0.3, 0.3, 0.3); - break; - } +// 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; +//// } - 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(); +// if (poly->outdoor) { +// glColor3f(0, 0, 0.5); +// } else { +// glColor3f(0.3, 0.3, 0.3); +// } - glEnable(GL_CULL_FACE); +// 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 diff --git a/mapview/3D/MV3DElementStair.h b/mapview/3D/MV3DElementStair.h index d674a77..8b204ca 100644 --- a/mapview/3D/MV3DElementStair.h +++ b/mapview/3D/MV3DElementStair.h @@ -40,7 +40,10 @@ protected: //const Floorplan::Quad3 quad = part.getQuad(floor); const Point3 p1 = quad.p2-quad.p1; const Point3 p2 = quad.p4-quad.p1; - const Point3 n = Math::normal(p1,p2); + + 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); diff --git a/mapview/3D/MapView3D.cpp b/mapview/3D/MapView3D.cpp index 454da88..de84783 100644 --- a/mapview/3D/MapView3D.cpp +++ b/mapview/3D/MapView3D.cpp @@ -38,21 +38,21 @@ void MapView3D::initializeGL() { // culling, lighting, depth-test, ... glEnable(GL_DEPTH_TEST); - glShadeModel(GL_SMOOTH); + //glShadeModel(GL_SMOOTH); - glEnable(GL_MULTISAMPLE); +// glEnable(GL_MULTISAMPLE); // glEnable(GL_LINE_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); + glEnable(GL_LIGHT1); - //glEnable(GL_LIGHT1); - GLfloat light0_position [] = {+50, 50, +50, 1}; - GLfloat light1_position [] = {-50, 50, -50, 1}; +// GLfloat light0_position [] = {+50, 50, +50, 1}; +// GLfloat light1_position [] = {-50, 50, -50, 1}; - glLightfv ( GL_LIGHT0, GL_POSITION, light0_position ); - glLightfv ( GL_LIGHT1, GL_POSITION, light1_position ); +// glLightfv ( GL_LIGHT0, GL_POSITION, light0_position ); +// glLightfv ( GL_LIGHT1, GL_POSITION, light1_position ); GLfloat light_diffuse []={ 0.7, 0.7, 0.7, 1.0 }; glLightfv ( GL_LIGHT0, GL_DIFFUSE, light_diffuse ); @@ -81,6 +81,12 @@ void MapView3D::paintGL() { glLoadIdentity(); + + + + glScalef(+1, -1, +1); + + // 3) scale glScalef(scale.x, scale.y, scale.z); @@ -93,8 +99,12 @@ void MapView3D::paintGL() { glTranslatef(center.x, center.z, center.y); // 0) swap the y axis - glScalef(+1, -1, +1); + //glScalef(+1, -1, +1); + GLfloat light0_position [] = {100, 50, 100, 1}; + glLightfv ( GL_LIGHT0, GL_POSITION, light0_position ); + GLfloat light1_position [] = {0, 50, 0, 1}; + glLightfv ( GL_LIGHT1, GL_POSITION, light1_position ); // // 1) translate into center @@ -142,10 +152,13 @@ void MapView3D::mouseMoveEvent(QMouseEvent* e) { float dx = mouse.x - e->x(); float dy = mouse.y - e->y(); if (mouse.btn == 1) { + //rot.z += dx/2.0f; // upward + //rot.x -= dy/2.0f; rot.z += dx/2.0f; // upward - rot.x -= dy/2.0f; + rot.x += dy/2.0f; } else if (mouse.btn == 4) { - Point3 vec(-dx / width() * 2 * viewport.size.x, 0, +dy / height() * 2 * viewport.size.y); + //Point3 vec(-dx / width() * 2 * viewport.size.x, 0, +dy / height() * 2 * viewport.size.y); + Point3 vec(-dx / width() * 2 * viewport.size.x, 0, -dy / height() * 2 * viewport.size.y); vec = vec.rot(rot.x/180*M_PI, rot.y/180*M_PI, rot.z/180*M_PI); vec /= scale; center += vec; diff --git a/mapview/model/MMFloorOutlinePolygon.h b/mapview/model/MMFloorOutlinePolygon.h index 9f20541..9cfb835 100644 --- a/mapview/model/MMFloorOutlinePolygon.h +++ b/mapview/model/MMFloorOutlinePolygon.h @@ -5,7 +5,6 @@ #include "MapModelElement.h" #include "../2D/MV2DElementFloorOutlinePolygon.h" -#include "../3D/MV3DElementFloorOutlinePolygon.h" #include @@ -20,13 +19,13 @@ private: Floorplan::Floor* mf; Floorplan::FloorOutlinePolygon* fo; MV2DElementFloorOutlinePolygon mv2d; - MV3DElementFloorOutlinePolygon mv3d; +// MV3DElementFloorOutlinePolygon mv3d; public: /** ctor */ MMFloorOutlinePolygon(MapLayer* parent, Floorplan::Floor* mf, Floorplan::FloorOutlinePolygon* fo) : - MapModelElement(parent), mf(mf), fo(fo), mv2d(*fo), mv3d(mf, fo) { + MapModelElement(parent), mf(mf), fo(fo), mv2d(*fo) { ; }