merged
This commit is contained in:
@@ -94,7 +94,7 @@ MainController::MainController() {
|
||||
connect(mw, &MainWindow::onGridShowEdges, [&] (const bool show) {mw->getMapView3D()->getGridRenderer()->setShowEdges(show);} );
|
||||
|
||||
|
||||
mapModel->load("../IndoorMap/maps/SHL33_gt.xml");
|
||||
mapModel->load("../IndoorMap/maps/SHL33a.xml");
|
||||
//mapModel->resize(0.983, 0.983, 1, -0.2, -0.3, 0);
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -15,6 +15,14 @@ class MV3DElementFloorOutline : public MV3DElement {
|
||||
Floorplan::Floor* f;
|
||||
Floorplan::FloorOutline* out;
|
||||
|
||||
struct ToRender {
|
||||
Point2 cacheSum;
|
||||
Polygon* pol = nullptr;
|
||||
std::vector<std::vector<Point3>> trias;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, ToRender*> 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<std::vector<Point3>>& 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<Point3>& 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 <typename Filter> void rebuildIfNeeded(Filter include, ToRender* dst) {
|
||||
|
||||
const std::vector<Floorplan::FloorOutlinePolygon*>& 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<gpc_polygon> add;
|
||||
std::vector<gpc_polygon> rem;
|
||||
|
||||
std::vector<Floorplan::FloorOutlinePolygon*> 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<std::vector<Point3>> trias = pol.get(f->atHeight);
|
||||
|
||||
glColor3f(0.2, 0.2, 0.2);
|
||||
glDisable(GL_CULL_FACE);
|
||||
for (const std::vector<Point3>& 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +1,60 @@
|
||||
#ifndef MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
||||
#define MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
//#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
#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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "MapModelElement.h"
|
||||
|
||||
#include "../2D/MV2DElementFloorOutlinePolygon.h"
|
||||
#include "../3D/MV3DElementFloorOutlinePolygon.h"
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
@@ -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) {
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user