many changes :P

This commit is contained in:
kazu
2016-06-06 22:08:53 +02:00
parent db6b479d86
commit 6243165084
56 changed files with 4399 additions and 245 deletions

82
mapview/3D/misc/Cube.h Normal file
View File

@@ -0,0 +1,82 @@
#ifndef CUBE_H
#define CUBE_H
#include <Indoor/geo/Point3.h>
#include <QtOpenGL>
class Cube {
private:
Point3 pos;
float size;
public:
Cube(Point3 pos, float size) : pos(pos), size(size) {
}
void paintGL() {
float s = size;
glPushMatrix();
glTranslatef(pos.x, pos.z, pos.y);
glColor3f(0,0,1);
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

109
mapview/3D/misc/Polygon.h Normal file
View File

@@ -0,0 +1,109 @@
#ifndef POLYGON_H
#define POLYGON_H
#include <Indoor/floorplan/v2/Floorplan.h>
#include "../../../lib/gpc/gpc.h"
class Polygon {
struct GPCPolygon : gpc_polygon {
GPCPolygon() {
// contour = (gpc_vertex_list*) calloc(0, 1024);
// contour->num_vertices = 0;
// contour->vertex = (gpc_vertex*) calloc(0, 1024);
// hole = (int*) calloc(0, 1024);
num_contours = 0;
contour = nullptr;
hole = nullptr;
}
~GPCPolygon() {
if (contour) {
gpc_free_polygon(this);
//free(contour->vertex); contour->vertex = nullptr;
}
free(contour); contour = nullptr;
free(hole); hole = nullptr;
}
GPCPolygon& operator = (const GPCPolygon& o) = delete;
GPCPolygon& operator = (GPCPolygon& o) {
this->contour = o.contour;
this->hole = o.hole;
this->num_contours = o.num_contours;
o.contour = nullptr;
o.hole = nullptr;
return *this;
}
};
private:
GPCPolygon state;
public:
void add(const Floorplan::Polygon2& poly) {
GPCPolygon cur = toGPC(poly);
//GPCPolygon out;
gpc_polygon_clip(GPC_UNION, &state, &cur, &state);
//state = out;
}
void remove(const Floorplan::Polygon2& poly) {
GPCPolygon cur = toGPC(poly);
//GPCPolygon out;
gpc_polygon_clip(GPC_DIFF, &state, &cur, &state);
//state = out;
}
std::vector<std::vector<Point3>> get(float z) {
gpc_tristrip res;
res.num_strips = 0;
res.strip = nullptr;
//res.strip = (gpc_vertex_list*) malloc(1024);
gpc_polygon_to_tristrip(&state, &res);
std::vector<std::vector<Point3>> trias;
for (int i = 0; i < res.num_strips; ++i) {
gpc_vertex_list lst = res.strip[i];
std::vector<Point3> tria;
for (int j = 0; j < lst.num_vertices; ++j) {
gpc_vertex& vert = lst.vertex[j];
Point3 p3(vert.x, vert.y, z);
tria.push_back(p3);
}
trias.push_back(tria);
}
gpc_free_tristrip(&res);
return std::move(trias);
}
private:
GPCPolygon toGPC(Floorplan::Polygon2 poly) {
std::vector<gpc_vertex> verts;
for (Point2 p2 : poly.points) {
gpc_vertex vert; vert.x = p2.x; vert.y = p2.y;
verts.push_back(vert);
}
GPCPolygon gpol;
gpc_vertex_list list;
list.num_vertices = verts.size();
list.vertex = verts.data();
gpc_add_contour(&gpol, &list, 0);
return gpol;
}
};
#endif // POLYGON_H