a lot of work on th map-creator
This commit is contained in:
35
mapview/3D/MV3DElementFloorObstacleDoor.h
Normal file
35
mapview/3D/MV3DElementFloorObstacleDoor.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef MV3DELEMENTFLOOROBSTACLEDOOR_H
|
||||
#define MV3DELEMENTFLOOROBSTACLEDOOR_H
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
#include <Indoor/math/Math.h>
|
||||
|
||||
#include "MV3DElement.h"
|
||||
#include "misc/Plane.h"
|
||||
|
||||
|
||||
|
||||
class MV3DElementFloorObstacleDoor : public MV3DElement {
|
||||
|
||||
Floorplan::Floor* f;
|
||||
Floorplan::FloorObstacleDoor* fo;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
MV3DElementFloorObstacleDoor(Floorplan::Floor* f, Floorplan::FloorObstacleDoor* fo) : f(f), fo(fo) {
|
||||
;
|
||||
}
|
||||
|
||||
/** repaint me */
|
||||
void paintGL() override {
|
||||
|
||||
glColor3f(0,1,0);
|
||||
Plane p(fo->from, fo->to, f->atHeight, fo->height);
|
||||
p.paintGL();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // MV3DELEMENTFLOOROBSTACLEDOOR_H
|
||||
@@ -2,9 +2,12 @@
|
||||
#define MV3DELEMENTFLOOROBSTACLEWALL_H
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
#include <Indoor/math/Math.h>
|
||||
|
||||
#include "MV3DElement.h"
|
||||
|
||||
|
||||
|
||||
class MV3DElementFloorObstacleWall : public MV3DElement {
|
||||
|
||||
Floorplan::Floor* f;
|
||||
@@ -19,39 +22,39 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
Point3 cross(Point3 u, Point3 v) {
|
||||
float x = u.y*v.z - u.z*v.y;
|
||||
float y = u.z*v.x - u.x*v.z;
|
||||
float z = u.x*v.y - u.y*v.x;
|
||||
return Point3(x,y,z);
|
||||
}
|
||||
|
||||
/** repaint me */
|
||||
void paintGL() override {
|
||||
|
||||
float y1 = f->atHeight;
|
||||
float y2 = y1+f->height;
|
||||
|
||||
|
||||
struct Wall {
|
||||
|
||||
Point2 from;
|
||||
Point2 to;
|
||||
float atHeight;
|
||||
float height;
|
||||
|
||||
Wall(const Point2 from, const Point2 to, float atHeight, float height) :
|
||||
from(from), to(to), atHeight(atHeight), height(height) {;}
|
||||
|
||||
void paintGL() {
|
||||
|
||||
Point3 p1 = Point3(fo->from.x, y1, fo->from.y);
|
||||
Point3 p2 = Point3(fo->to.x, y1, fo->to.y);
|
||||
Point3 p3 = Point3(fo->to.x, y2, fo->to.y);
|
||||
Point3 p4 = Point3(fo->from.x, y2, fo->from.y);
|
||||
float y1 = atHeight;
|
||||
float y2 = atHeight + height;
|
||||
|
||||
Point3 v1 = p2-p1;
|
||||
Point3 v2 = p3-p1;
|
||||
Point3 n = cross(v1, v2);
|
||||
n/=n.length();
|
||||
// polygon edges
|
||||
Point3 p1 = Point3(from.x, y1, from.y);
|
||||
Point3 p2 = Point3(to.x, y1, to.y);
|
||||
Point3 p3 = Point3(to.x, y2, to.y);
|
||||
Point3 p4 = Point3(from.x, y2, from.y);
|
||||
|
||||
// align normals to virtual viewport
|
||||
Point3 view(99,99,99);
|
||||
if ((view-n).length() > (view+n).length()) {n = -n;}
|
||||
// calculate normal
|
||||
// Point3 v1 = p2-p1;
|
||||
// Point3 v2 = p3-p1;
|
||||
// Point3 n = cross(v1, v2);
|
||||
// n/=n.length();
|
||||
Point3 n = Math::normal(p2-p1, p3-p1);
|
||||
|
||||
if (fo->type == Floorplan::ObstacleType::WALL) {
|
||||
// align normals to virtual viewport
|
||||
Point3 view(99,99,99);
|
||||
if ((view-n).length() > (view+n).length()) {n = -n;}
|
||||
|
||||
// fill the wall
|
||||
glColor3f(0.75, 0.75, 0.75);
|
||||
@@ -67,17 +70,85 @@ protected:
|
||||
|
||||
}
|
||||
|
||||
glColor3f(0,0,0);
|
||||
};
|
||||
|
||||
// glDisable(GL_LIGHTING);
|
||||
// glBegin(GL_LINE_STRIP);
|
||||
// glVertex3f(p1.x, p1.y, p1.z);
|
||||
// glVertex3f(p2.x, p2.y, p2.z);
|
||||
// glVertex3f(p3.x, p3.y, p3.z);
|
||||
// glVertex3f(p4.x, p4.y, p4.z);
|
||||
// glVertex3f(p1.x, p1.y, p1.z);
|
||||
// glEnd();
|
||||
// glEnable(GL_LIGHTING);
|
||||
struct Handrail {
|
||||
|
||||
Point2 from;
|
||||
Point2 to;
|
||||
float atHeight;
|
||||
float height;
|
||||
|
||||
Handrail(const Point2 from, const Point2 to, float atHeight, float height) :
|
||||
from(from), to(to), atHeight(atHeight), height(height) {;}
|
||||
|
||||
void paintGL() {
|
||||
|
||||
float y1 = atHeight;
|
||||
float y2 = atHeight + height;
|
||||
|
||||
// polygon edges
|
||||
Point3 p1 = Point3(from.x, y1, from.y);
|
||||
Point3 p2 = Point3(to.x, y1, to.y);
|
||||
|
||||
Point3 p3 = Point3(from.x, y2, from.y);
|
||||
Point3 p4 = Point3(to.x, y2, to.y);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glBegin(GL_LINES);
|
||||
|
||||
glColor3f(1,1,1);
|
||||
|
||||
// top
|
||||
glVertex3f(p3.x, p3.y, p3.z);
|
||||
glVertex3f(p4.x, p4.y, p4.z);
|
||||
|
||||
// start bar
|
||||
glVertex3f(p1.x, p1.y, p1.z);
|
||||
glVertex3f(p3.x, p3.y, p3.z);
|
||||
|
||||
// end bar
|
||||
glVertex3f(p2.x, p2.y, p2.z);
|
||||
glVertex3f(p4.x, p4.y, p4.z);
|
||||
|
||||
glColor3f(0.6, 0.6, 0.6);
|
||||
|
||||
// intermediate bars
|
||||
const Point3 d1 = p2-p1;
|
||||
const Point3 d2 = p4-p3;
|
||||
const int numBars = d2.length() / 1;
|
||||
for (int i = 1; i < numBars; ++i) {
|
||||
const Point3 s = p1 + d1 * i / numBars;
|
||||
const Point3 e = p3 + d2 * i / numBars;
|
||||
glVertex3f(s.x, s.y, s.z);
|
||||
glVertex3f(e.x, e.y, e.z);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/** repaint me */
|
||||
void paintGL() override {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (fo->type == Floorplan::ObstacleType::WALL) {
|
||||
|
||||
Wall wall(fo->from, fo->to, f->atHeight, f->height);
|
||||
wall.paintGL();
|
||||
|
||||
} else if (fo->type == Floorplan::ObstacleType::HANDRAIL) {
|
||||
|
||||
Handrail rail(fo->from, fo->to, f->atHeight, 1.0);
|
||||
rail.paintGL();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
59
mapview/3D/MV3DElementStair.h
Normal file
59
mapview/3D/MV3DElementStair.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef MV3DELEMENTSTAIR_H
|
||||
#define MV3DELEMENTSTAIR_H
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
#include "misc/Cube.h"
|
||||
#include "MV3DElement.h"
|
||||
|
||||
class MV3DElementStair : public MV3DElement {
|
||||
|
||||
Floorplan::Floor* floor;
|
||||
Floorplan::Stair* stair;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
MV3DElementStair(Floorplan::Floor* floor, Floorplan::Stair* stair) : floor(floor), stair(stair) {
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/** repaint me */
|
||||
void paintGL() override {
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glColor3f(1.0, 0.55, 0.55);
|
||||
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;
|
||||
const Point3 n = Math::normal(p1,p2);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // MV3DELEMENTSTAIR_H
|
||||
@@ -21,6 +21,8 @@ MapView3D::MapView3D(QWidget *parent) : QGLWidget(parent) {
|
||||
scale.y = 0.05f;
|
||||
scale.z = 0.05f;
|
||||
|
||||
gridRenderer = new GridRenderer();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -40,10 +42,10 @@ void MapView3D::initializeGL() {
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHT1);
|
||||
//glEnable(GL_LIGHT1);
|
||||
|
||||
GLfloat light0_position [] = {+5, 5, +5, 1};
|
||||
GLfloat light1_position [] = {-5, 5, -5, 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 );
|
||||
@@ -75,8 +77,6 @@ void MapView3D::paintGL() {
|
||||
|
||||
glLoadIdentity();
|
||||
|
||||
|
||||
|
||||
// 3) scale
|
||||
glScalef(scale.x, scale.y, scale.z);
|
||||
|
||||
@@ -180,8 +180,7 @@ void MapView3D::draw() {
|
||||
if (gridModel) {
|
||||
|
||||
// show grid
|
||||
GridRenderer renderer(gridModel->getGrid());
|
||||
renderer.paintGL();
|
||||
gridRenderer->paintGL(gridModel->getGrid());
|
||||
|
||||
} else {
|
||||
|
||||
@@ -189,6 +188,7 @@ void MapView3D::draw() {
|
||||
for (MapModelElement* el : getModel()->getVisibleElements()) {
|
||||
if (el->getMV3D()) {el->getMV3D()->paintGL();}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
class MapModel;
|
||||
class GridModel;
|
||||
class GridRenderer;
|
||||
|
||||
class MapView3D : public QGLWidget {
|
||||
|
||||
@@ -23,20 +24,31 @@ public:
|
||||
update();
|
||||
}
|
||||
|
||||
void layerChange() {
|
||||
update();
|
||||
}
|
||||
|
||||
/** get the underlying data-model */
|
||||
MapModel* getModel() {return model;}
|
||||
|
||||
/** get the renderer to use for the grid */
|
||||
GridRenderer* getGridRenderer() {return gridRenderer;}
|
||||
|
||||
|
||||
/** show 3D rendered floorplan */
|
||||
void showFloorplan();
|
||||
|
||||
/** show 3D rendered grid derived from the floorplan */
|
||||
void showGrid();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** the underlying data-model */
|
||||
MapModel* model = nullptr;
|
||||
|
||||
GridModel* gridModel = nullptr;
|
||||
GridRenderer* gridRenderer = nullptr;
|
||||
|
||||
Point3 rot;
|
||||
Point3 center;
|
||||
|
||||
52
mapview/3D/misc/Plane.h
Normal file
52
mapview/3D/misc/Plane.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef PLANE_H
|
||||
#define PLANE_H
|
||||
|
||||
#include <Indoor/geo/Point3.h>
|
||||
#include <QtOpenGL>
|
||||
|
||||
class Plane {
|
||||
|
||||
private:
|
||||
|
||||
Point3 p1;
|
||||
Point3 p2;
|
||||
Point3 p3;
|
||||
Point3 p4;
|
||||
Point3 n;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** construct from 2D line and heights */
|
||||
Plane(const Point2 from, const Point2 to, const float atHeight, const float height) {
|
||||
|
||||
p1 = Point3(from.x, from.y, atHeight);
|
||||
p2 = Point3(to.x, to.y, atHeight);
|
||||
p3 = Point3(to.x, to.y, atHeight+height);
|
||||
p4 = Point3(from.x, from.y, atHeight+height);
|
||||
|
||||
const Point2 perp = (to-from).perpendicular();
|
||||
n = Point3(perp.x, perp.y, 0);
|
||||
|
||||
}
|
||||
|
||||
void paintGL() {
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
// bottom
|
||||
glNormal3f(n.x, n.z, n.y);
|
||||
glVertex3f(p1.x, p1.z, p1.y);
|
||||
glVertex3f(p2.x, p2.z, p2.y);
|
||||
glVertex3f(p3.x, p3.z, p3.y);
|
||||
glVertex3f(p4.x, p4.z, p4.y);
|
||||
|
||||
glEnd();
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // PLANE_H
|
||||
Reference in New Issue
Block a user