fixed some issues
This commit is contained in:
@@ -94,7 +94,7 @@ MainController::MainController() {
|
|||||||
connect(mw, &MainWindow::onGridShowEdges, [&] (const bool show) {mw->getMapView3D()->getGridRenderer()->setShowEdges(show);} );
|
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);
|
//mapModel->resize(0.983, 0.983, 1, -0.2, -0.3, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
/** repaint me */
|
/** repaint me */
|
||||||
void paintGL() override {
|
void paintGL() override {
|
||||||
|
|
||||||
glColor3f(0,1,0);
|
glColor3f(0.4, 0.4, 0.4);
|
||||||
Plane p(fo->from, fo->to, f->atHeight, fo->height);
|
Plane p(fo->from, fo->to, f->atHeight, fo->height);
|
||||||
p.paintGL();
|
p.paintGL();
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ class MV3DElementFloorOutline : public MV3DElement {
|
|||||||
Floorplan::Floor* f;
|
Floorplan::Floor* f;
|
||||||
Floorplan::FloorOutline* out;
|
Floorplan::FloorOutline* out;
|
||||||
|
|
||||||
|
struct ToRender {
|
||||||
|
Point2 cacheSum;
|
||||||
|
Polygon* pol = nullptr;
|
||||||
|
std::vector<std::vector<Point3>> trias;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unordered_map<std::string, ToRender*> elements;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** ctor */
|
/** ctor */
|
||||||
@@ -31,26 +39,22 @@ protected:
|
|||||||
/** repaint me */
|
/** repaint me */
|
||||||
void paintGL() override {
|
void paintGL() override {
|
||||||
|
|
||||||
std::vector<gpc_polygon> add;
|
rebuildIfNeeded();
|
||||||
std::vector<gpc_polygon> rem;
|
|
||||||
|
|
||||||
std::vector<Floorplan::FloorOutlinePolygon*> polys = *out;
|
for (auto& it : elements) {
|
||||||
|
|
||||||
Polygon pol;
|
//Polygon& pol = it.second->pol;
|
||||||
|
std::vector<std::vector<Point3>>& trias = it.second->trias;
|
||||||
for (Floorplan::FloorOutlinePolygon* poly : polys) {
|
|
||||||
switch (poly->method) {
|
|
||||||
case Floorplan::OutlineMethod::ADD: pol.add(poly->poly); break;
|
|
||||||
case Floorplan::OutlineMethod::REMOVE: pol.remove(poly->poly); break;
|
|
||||||
default: throw 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::vector<Point3>> trias = pol.get(f->atHeight);
|
|
||||||
|
|
||||||
|
if (it.first == "outdoor") {
|
||||||
|
glColor3f(0.0, 0.5, 0.0);
|
||||||
|
} else {
|
||||||
glColor3f(0.2, 0.2, 0.2);
|
glColor3f(0.2, 0.2, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
for (const std::vector<Point3>& tria : trias) {
|
for (const std::vector<Point3>& tria : trias) {
|
||||||
|
glNormal3f(0, 1, 0);
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
glBegin(GL_TRIANGLE_STRIP);
|
||||||
for (const Point3& p3 : tria) {
|
for (const Point3& p3 : tria) {
|
||||||
glVertex3f(p3.x, p3.z, p3.y);
|
glVertex3f(p3.x, p3.z, p3.y);
|
||||||
@@ -59,7 +63,58 @@ protected:
|
|||||||
}
|
}
|
||||||
glEnable(GL_CULL_FACE);
|
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;
|
||||||
|
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: dst->pol->add(poly->poly); break;
|
||||||
|
case Floorplan::OutlineMethod::REMOVE: dst->pol->remove(poly->poly); break;
|
||||||
|
default: throw 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dst->trias = dst->pol->get(f->atHeight);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,53 +1,60 @@
|
|||||||
#ifndef MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
#ifndef MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
||||||
#define MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
#define MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
||||||
|
|
||||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
//#include <Indoor/floorplan/v2/Floorplan.h>
|
||||||
|
|
||||||
#include "misc/Cube.h"
|
//#include "misc/Cube.h"
|
||||||
#include "MV3DElement.h"
|
//#include "MV3DElement.h"
|
||||||
|
|
||||||
class MV3DElementFloorOutlinePolygon : public MV3DElement {
|
//class MV3DElementFloorOutlinePolygon : public MV3DElement {
|
||||||
|
|
||||||
Floorplan::Floor* f;
|
// Floorplan::Floor* f;
|
||||||
Floorplan::FloorOutlinePolygon* poly;
|
// Floorplan::FloorOutlinePolygon* poly;
|
||||||
|
|
||||||
public:
|
//public:
|
||||||
|
|
||||||
/** ctor */
|
// /** ctor */
|
||||||
MV3DElementFloorOutlinePolygon(Floorplan::Floor* f, Floorplan::FloorOutlinePolygon* poly) : f(f), poly(poly) {
|
// MV3DElementFloorOutlinePolygon(Floorplan::Floor* f, Floorplan::FloorOutlinePolygon* poly) : f(f), poly(poly) {
|
||||||
;
|
// ;
|
||||||
}
|
// }
|
||||||
|
|
||||||
protected:
|
//protected:
|
||||||
|
|
||||||
|
|
||||||
/** repaint me */
|
// /** repaint me */
|
||||||
void paintGL() override {
|
// void paintGL() override {
|
||||||
|
|
||||||
glDisable(GL_CULL_FACE);
|
// throw "deprecated!!!";
|
||||||
|
|
||||||
switch (poly->method) {
|
// glDisable(GL_CULL_FACE);
|
||||||
case Floorplan::OutlineMethod::ADD:
|
|
||||||
glColor3f(1,1,1);
|
|
||||||
break;
|
|
||||||
case Floorplan::OutlineMethod::REMOVE:
|
|
||||||
glColor3f(0.3, 0.3, 0.3);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//// 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);
|
// if (poly->outdoor) {
|
||||||
glNormal3f(0,1,0);
|
// glColor3f(0, 0, 0.5);
|
||||||
for (Point2 p2 : poly->poly.points) {
|
// } else {
|
||||||
Point3 p3(p2.x, p2.y, f->atHeight);
|
// glColor3f(0.3, 0.3, 0.3);
|
||||||
glVertex3f(p3.x, p3.z, p3.y);
|
// }
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
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
|
#endif // MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
||||||
|
|||||||
@@ -40,7 +40,10 @@ protected:
|
|||||||
//const Floorplan::Quad3 quad = part.getQuad(floor);
|
//const Floorplan::Quad3 quad = part.getQuad(floor);
|
||||||
const Point3 p1 = quad.p2-quad.p1;
|
const Point3 p1 = quad.p2-quad.p1;
|
||||||
const Point3 p2 = quad.p4-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);
|
glNormal3f(n.x, n.z, n.z);
|
||||||
glVertex3f(quad.p1.x, quad.p1.z, quad.p1.y);
|
glVertex3f(quad.p1.x, quad.p1.z, quad.p1.y);
|
||||||
glVertex3f(quad.p2.x, quad.p2.z, quad.p2.y);
|
glVertex3f(quad.p2.x, quad.p2.z, quad.p2.y);
|
||||||
|
|||||||
@@ -38,21 +38,21 @@ void MapView3D::initializeGL() {
|
|||||||
|
|
||||||
// culling, lighting, depth-test, ...
|
// culling, lighting, depth-test, ...
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glShadeModel(GL_SMOOTH);
|
//glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
glEnable(GL_MULTISAMPLE);
|
// glEnable(GL_MULTISAMPLE);
|
||||||
// glEnable(GL_LINE_SMOOTH);
|
// glEnable(GL_LINE_SMOOTH);
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glEnable(GL_LIGHT0);
|
glEnable(GL_LIGHT0);
|
||||||
|
glEnable(GL_LIGHT1);
|
||||||
|
|
||||||
//glEnable(GL_LIGHT1);
|
|
||||||
|
|
||||||
GLfloat light0_position [] = {+50, 50, +50, 1};
|
// GLfloat light0_position [] = {+50, 50, +50, 1};
|
||||||
GLfloat light1_position [] = {-50, 50, -50, 1};
|
// GLfloat light1_position [] = {-50, 50, -50, 1};
|
||||||
|
|
||||||
glLightfv ( GL_LIGHT0, GL_POSITION, light0_position );
|
// glLightfv ( GL_LIGHT0, GL_POSITION, light0_position );
|
||||||
glLightfv ( GL_LIGHT1, GL_POSITION, light1_position );
|
// glLightfv ( GL_LIGHT1, GL_POSITION, light1_position );
|
||||||
|
|
||||||
GLfloat light_diffuse []={ 0.7, 0.7, 0.7, 1.0 };
|
GLfloat light_diffuse []={ 0.7, 0.7, 0.7, 1.0 };
|
||||||
glLightfv ( GL_LIGHT0, GL_DIFFUSE, light_diffuse );
|
glLightfv ( GL_LIGHT0, GL_DIFFUSE, light_diffuse );
|
||||||
@@ -81,6 +81,12 @@ void MapView3D::paintGL() {
|
|||||||
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
glScalef(+1, -1, +1);
|
||||||
|
|
||||||
|
|
||||||
// 3) scale
|
// 3) scale
|
||||||
glScalef(scale.x, scale.y, scale.z);
|
glScalef(scale.x, scale.y, scale.z);
|
||||||
|
|
||||||
@@ -93,8 +99,12 @@ void MapView3D::paintGL() {
|
|||||||
glTranslatef(center.x, center.z, center.y);
|
glTranslatef(center.x, center.z, center.y);
|
||||||
|
|
||||||
// 0) swap the y axis
|
// 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
|
// // 1) translate into center
|
||||||
@@ -142,10 +152,13 @@ void MapView3D::mouseMoveEvent(QMouseEvent* e) {
|
|||||||
float dx = mouse.x - e->x();
|
float dx = mouse.x - e->x();
|
||||||
float dy = mouse.y - e->y();
|
float dy = mouse.y - e->y();
|
||||||
if (mouse.btn == 1) {
|
if (mouse.btn == 1) {
|
||||||
|
//rot.z += dx/2.0f; // upward
|
||||||
|
//rot.x -= dy/2.0f;
|
||||||
rot.z += dx/2.0f; // upward
|
rot.z += dx/2.0f; // upward
|
||||||
rot.x -= dy/2.0f;
|
rot.x += dy/2.0f;
|
||||||
} else if (mouse.btn == 4) {
|
} 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 = vec.rot(rot.x/180*M_PI, rot.y/180*M_PI, rot.z/180*M_PI);
|
||||||
vec /= scale;
|
vec /= scale;
|
||||||
center += vec;
|
center += vec;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "MapModelElement.h"
|
#include "MapModelElement.h"
|
||||||
|
|
||||||
#include "../2D/MV2DElementFloorOutlinePolygon.h"
|
#include "../2D/MV2DElementFloorOutlinePolygon.h"
|
||||||
#include "../3D/MV3DElementFloorOutlinePolygon.h"
|
|
||||||
|
|
||||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||||
|
|
||||||
@@ -20,13 +19,13 @@ private:
|
|||||||
Floorplan::Floor* mf;
|
Floorplan::Floor* mf;
|
||||||
Floorplan::FloorOutlinePolygon* fo;
|
Floorplan::FloorOutlinePolygon* fo;
|
||||||
MV2DElementFloorOutlinePolygon mv2d;
|
MV2DElementFloorOutlinePolygon mv2d;
|
||||||
MV3DElementFloorOutlinePolygon mv3d;
|
// MV3DElementFloorOutlinePolygon mv3d;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** ctor */
|
/** ctor */
|
||||||
MMFloorOutlinePolygon(MapLayer* parent, Floorplan::Floor* mf, Floorplan::FloorOutlinePolygon* fo) :
|
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