This commit is contained in:
2018-05-12 11:00:18 +02:00
40 changed files with 640 additions and 153 deletions

View File

@@ -36,9 +36,11 @@ public:
/** get a list of all nodes that are selectable / moveable */
virtual std::vector<MoveableNode> getMoveableNodes() const = 0;
/** the given node was moved */
/** the given node is currently moved */
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) = 0;
/** the given node was previously moved */
virtual void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) = 0;
/** the given node was selected */
virtual void onNodeSelect(MapView2D* v, const int userIdx) {

View File

@@ -84,6 +84,11 @@ public:
if (userIdx == 0) {ap->pos.x = newPos.x; ap->pos.y = newPos.y;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
virtual void mousePressed(MapView2D* v, const Point2 p) override {
(void) v;

View File

@@ -77,6 +77,12 @@ public:
if (userIdx == 0) {b->pos.x = newPos.x; b->pos.y = newPos.y;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
virtual void onFocus() override {
;
}

View File

@@ -94,6 +94,12 @@ public:
if (userIdx == 0) {elevator->center.x = newPos.x; elevator->center.y = newPos.y;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
virtual void mousePressed(MapView2D* v, const Point2 p) override {
(void) v;

View File

@@ -82,6 +82,12 @@ public:
if (userIdx == 0) {fpl->posOnFloor = newPos;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
virtual void onFocus() override {
;
}

View File

@@ -128,12 +128,16 @@ std::vector<MoveableNode> MV2DElementFloorObstacleDoor::getMoveableNodes() const
return nodes;
}
void MV2DElementFloorObstacleDoor::onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) {
emit v->onElementChange(this);
}
void MV2DElementFloorObstacleDoor::onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) {
switch (userIdx) {
case 0: fo->from = newPos; break;
case 1: fo->to = newPos; break;
}
emit v->onElementChange(this);
// emit v->onElementChange(this);
}
bool MV2DElementFloorObstacleDoor::keyPressEvent(MapView2D* v, QKeyEvent *e) {

View File

@@ -41,9 +41,10 @@ public:
/** get a list of all nodes that are selectable / moveable */
virtual std::vector<MoveableNode> getMoveableNodes() const override;
/** the given node was moved */
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override;
virtual void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override;
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override;
};

View File

@@ -129,6 +129,13 @@ public:
if (userIdx == 1) {fo->to.x = newPos.x; fo->to.y = newPos.y;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
};
#endif // MV2DELEMENTFLOOROBSTACLELINE_H

View File

@@ -102,6 +102,11 @@ void MV2DElementFloorObstacleObject::onNodeMove(MapView2D* v, const int userIdx,
if (userIdx == 0) {fo->pos.x = newPos.x; fo->pos.y = newPos.y;}
}
void MV2DElementFloorObstacleObject::onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
void MV2DElementFloorObstacleObject::mousePressed(MapView2D* v, const Point2 p) {
(void) v;

View File

@@ -34,6 +34,8 @@ public:
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override;
virtual void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override;
virtual void mousePressed(MapView2D* v, const Point2 p) override;
virtual void mouseMove(MapView2D* v, const Point2 p) override;

View File

@@ -103,12 +103,19 @@ public:
}
/** the given node was moved */
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) v;
fo.poly.points[userIdx].x = newPos.x;
fo.poly.points[userIdx].y = newPos.y;
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
// virtual void mousePressed(MapView2D* v, const Point2 p) override {
// (void) v;
// (void) p;

View File

@@ -81,6 +81,11 @@ public:
if (userIdx == 0) {gtp->pos.x = newPos.x; gtp->pos.y = newPos.y;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
/** mouse pressed at the given point */
virtual void mousePressed(MapView2D* v, const Point2 p) override {

View File

@@ -81,6 +81,11 @@ public:
if (userIdx == 0) {poi->pos = newPos;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
/** mouse pressed at the given point */
virtual void mousePressed(MapView2D* v, const Point2 p) override {

View File

@@ -77,6 +77,11 @@ public:
if (userIdx == 0) {reg->posOnMap_m.x = newPos.x; reg->posOnMap_m.y = newPos.y;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
virtual void mousePressed(MapView2D* v, const Point2 p) override {
(void) v;

View File

@@ -307,6 +307,12 @@ public:
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
void onNodeSelect(MapView2D* v, const int userIdx) override {
HasMoveableNodes::onNodeSelect(v, userIdx);
emit v->onElementChange(this);

View File

@@ -79,6 +79,7 @@ public:
if (focus) {pen.setColor(Qt::black);}
if (mat == Material::CONCRETE) {;}
if (mat == Material::GLASS) {pen.setStyle(Qt::PenStyle::DotLine);}
if (mat == Material::METAL) {pen.setColor(QColor(50, 50, 50));}
if (type == ObstacleType::HANDRAIL) {pen.setStyle(Qt::PenStyle::DashLine);}
if (type == ObstacleType::UNKNOWN) {pen.setColor(Qt::red);}
if (type == ObstacleType::PILLAR) {pen.setColor(Qt::red);}

View File

@@ -120,9 +120,10 @@ private:
// // left mouse button?
// if (e->button() == Qt::MouseButton::LeftButton) {
// // element has selectedable nodes? try to select one
// if (dynamic_cast<HasMoveableNodes*>(me)) {
// if (selectNode(m, p, dynamic_cast<HasMoveableNodes*>(me))) {return;}
// }
if (dynamic_cast<HasMoveableNodes*>(me)) {
//if (selectNode(m, p, dynamic_cast<HasMoveableNodes*>(me))) {return;}
if (nodeMoved(m, p, dynamic_cast<HasMoveableNodes*>(me))) {return;}
}
// }
// otherwise: let the element itself process all events
@@ -173,6 +174,21 @@ private:
}
/** moved the currently selected node (now done). true if successful */
bool nodeMoved(MapView2D* v, Point2 p, HasMoveableNodes* elem) {
// no node selected? -> done
if (elem->getSelectedNode() == -1) {return false;}
// snap the node
const Point2 pSnapped = v->getScaler().snap(p);
// moved (done)
elem->onNodeMoved(v, elem->getSelectedNode(), pSnapped);
return true;
}
private:
@@ -232,7 +248,7 @@ private:
const float g = m->getScaler().sm(15); // increase each BBox by 15 px (needed mainly for hor/ver lines)
#warning "which elements to select? among all currently visible? or only among the selected layer?"
#pragma message "which elements to select? among all currently visible? or only among the selected layer?"
// get all elements with bounding-box matchings
std::vector<MapModelElement*> possible;
// for (MapModelElement* el : m->getModel()->getSelectedLayerElements()) {

View File

@@ -2,12 +2,11 @@
#define MV3DELEMENTFLOOROUTLINE_H
#include <Indoor/floorplan/v2/Floorplan.h>
#include <Indoor/geo/GPCPolygon2.h>
#include "misc/Cube.h"
#include "MV3DElement.h"
#include "../../lib/gpc/gpc.h"
#include "misc/Polygon.h"
#include "misc/Outline.h"
class MV3DElementFloorOutline : public MV3DElement {
@@ -17,7 +16,7 @@ class MV3DElementFloorOutline : public MV3DElement {
struct Temp {
Point2 cacheSum;
Polygon* pol = nullptr;
GPCPolygon2* pol = nullptr;
std::vector<std::vector<Point3>> trias;
};
@@ -80,7 +79,7 @@ protected:
std::vector<gpc_polygon> add;
std::vector<gpc_polygon> rem;
if (tmp.pol) {delete tmp.pol;}
tmp.pol = new Polygon();
tmp.pol = new GPCPolygon2();
// all to-be-added polygons (filter!)
for (Floorplan::FloorOutlinePolygon* poly : polys) {

View File

@@ -58,7 +58,7 @@ protected:
rs.shader->setColor(1.0, 0.55, 0.55);
rs.shader->setVertices(data.getVertices().data());
rs.shader->setNormals(data.getNormals().data());
glDrawArrays(GL_TRIANGLES, 0, data.getVertices().size()/3);
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, data.getVertices().size()/3);
rs.shader->unsetVertices();
rs.shader->unsetNormals();
rs.shader->release();

View File

@@ -112,12 +112,16 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
grabGesture(Qt::PinchGesture);
auto format = QSurfaceFormat();
//format.setVersion(4,3);
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setVersion(3, 4);
format.setSamples(2);
//format.setProfile(QSurfaceFormat::CoreProfile);
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setOption(QSurfaceFormat::DebugContext);
setFormat(format);
setFormat(format);
auto ver = format.version();
std::cout << "OpenGL Context Version: " << ver.first << "." << ver.second << std::endl;
}
@@ -126,6 +130,32 @@ void MapView3D::initializeGL() {
//setFormat(QGLFormat(QGL::SampleBuffers));
QOpenGLWidget::initializeGL();
initializeOpenGLFunctions();
logger = new QOpenGLDebugLogger(this);
if (logger->initialize()) {
connect(logger, &QOpenGLDebugLogger::messageLogged, [] (const QOpenGLDebugMessage& debugMessage) {
std::cout << debugMessage.message().toStdString() << std::endl;
});
logger->startLogging(QOpenGLDebugLogger::SynchronousLogging);
}
// Print device info
const GLubyte* vendor = glGetString(GL_VENDOR);
const GLubyte* renderer = glGetString(GL_RENDERER);
const GLubyte* version = glGetString(GL_VERSION);
std::cout << "Device info: ";
if (vendor) {
std::cout << (const char*) vendor << " ";
}
if (renderer) {
std::cout << (const char*) renderer << " ";
}
if (version) {
std::cout << (const char*) version << " ";
}
std::cout << std::endl;
// this should be the default!!
glCullFace(GL_BACK);
@@ -134,8 +164,7 @@ void MapView3D::initializeGL() {
// additional settings
glEnable(GL_DEPTH_TEST);
glClearColor(0.9, 0.9, 1.0, 1.0);
glClearColor(0.5, 0.5, 0.5, 1.0);
}
void MapView3D::paintGL() {
@@ -293,7 +322,7 @@ void MapView3D::layerChange() {
void MapView3D::draw() {
static RenderSettings rs = RenderSettings(new Shader());
static RenderSettings rs = RenderSettings(new Shader(), this);
// view
QMatrix4x4 V;
@@ -305,7 +334,7 @@ void MapView3D::draw() {
V.rotate(rot.z, 0.0, 0.0, 1.0);
V.translate(center.x, center.y, center.z);
float far = 200; // TODO
float farPlane = 200; // TODO
// projection
QMatrix4x4 P;
@@ -316,14 +345,14 @@ void MapView3D::draw() {
float h = height() / 30;
viewport.size.x = w;
viewport.size.y = h;
P.perspective(45.0f, aspect, 0.01, far);
P.perspective(45.0f, aspect, 0.01, farPlane);
} else {
// default size: 50 * 50/aspect meters
float w = 50.0f;
float h = 50.0f * height() / width();
viewport.size.x = w;
viewport.size.y = h;
P.ortho(-w, +w, -h, +h, 0.1f, +far);
P.ortho(-w, +w, -h, +h, 0.1f, +farPlane);
}
rs.shader->bind();

View File

@@ -4,7 +4,8 @@
#include "../../fixC11.h"
#include <QtWidgets>
#include <QtOpenGL>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <Indoor/geo/Point3.h>
@@ -16,13 +17,15 @@ class NavMeshModel;
class FloorplanRenderer;
class FloorplanRendererModel;
class MapView3D : public QOpenGLWidget {
class MapView3D : public QOpenGLWidget, protected QOpenGLFunctions {
Q_OBJECT
bool usePerspectiveProjection = false;
bool useWireframe = false;
QOpenGLDebugLogger* logger = nullptr;
public:
MapView3D(QWidget* parent = 0);

View File

@@ -8,6 +8,7 @@
#include <QPainter>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include "../misc/Renderable3D.h"
#include "../misc/Shader.h"
@@ -35,7 +36,7 @@ public:
rs.shader->setVertices(rt.getVertices());
rs.shader->setNormals(rt.getNormals());
rs.shader->setVertexColor(rt.getRGBA());
glDrawArrays(GL_TRIANGLES, 0, rt.count());
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, rt.count());
rs.shader->unsetVertices();
rs.shader->unsetNormals();
rs.shader->unsetVertexColor();
@@ -45,7 +46,7 @@ public:
rs.shader->setColor(0,0,0,128);
rs.shader->setVertices(rt2.getVertices());
//rs.shader->setVertexColor(rt2.getRGBA());
glDrawArrays(GL_LINES, 0, rt2.count());
rs.funcs->glDrawArrays(GL_LINES, 0, rt2.count());
rs.shader->unsetVertices();
//rs.shader->unsetVertexColor();
}
@@ -56,8 +57,8 @@ public:
/** render the given grid using GL commands */
void renderTransp(const RenderSettings& rs, const RenderTriangle& rt, bool wireframe) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
rs.funcs->glEnable(GL_BLEND);
rs.funcs->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
rs.shader->bind();
rs.shader->setModelMatrix(QMatrix4x4());
@@ -65,7 +66,7 @@ public:
rs.shader->setVertices(rt.getVertices());
rs.shader->setNormals(rt.getNormals());
rs.shader->setVertexColor(rt.getRGBA());
glDrawArrays(GL_TRIANGLES, 0, rt.count());
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, rt.count());
rs.shader->unsetVertices();
rs.shader->unsetNormals();
rs.shader->unsetVertexColor();
@@ -75,14 +76,14 @@ public:
rs.shader->setColor(0,0,0,128);
rs.shader->setVertices(rt2.getVertices());
//rs.shader->setVertexColor(rt2.getRGBA());
glDrawArrays(GL_LINES, 0, rt2.count());
rs.funcs->glDrawArrays(GL_LINES, 0, rt2.count());
rs.shader->unsetVertices();
//rs.shader->unsetVertexColor();
}
rs.shader->release();
glDisable(GL_BLEND);
rs.funcs->glDisable(GL_BLEND);
}

View File

@@ -89,27 +89,37 @@ public:
void rebuild(Floorplan::IndoorMap* im) {
<<<<<<< HEAD
// rebuild the mesh
Ray3D::ModelFactory fac(im);
fac.exportDoors = showDoors;
mesh = fac.getMesh();
=======
>>>>>>> 45592899ee7de1a99f3086205788ff43398fad41
triaTransp.clear();
triaSolid.clear();
for (const Ray3D::Obstacle3D& obs : mesh.elements) {
const int matID = getMaterial(obs);
const Material& mat = mats[matID];
for (const Triangle3& tria : obs.triangles) {
const Point3 n = cross(tria.p2-tria.p1, tria.p3-tria.p1).normalized();
if (mat.a != 255) {
triaTransp.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f);
} else {
triaSolid.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f);
// rebuild the mesh
try {
Ray3D::ModelFactory fac(im);
mesh = fac.getMesh();
for (const Ray3D::Obstacle3D& obs : mesh.elements) {
const int matID = getMaterial(obs);
const Material& mat = mats[matID];
for (const Triangle3& tria : obs.triangles) {
const Point3 n = cross(tria.p2-tria.p1, tria.p3-tria.p1).normalized();
if (mat.a != 255) {
triaTransp.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f);
} else {
triaSolid.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f);
}
}
}
}
catch(const std::exception& e) {
std::cout << "Can't create 3D view. Failed to get mesh from model factory with error: '" << e.what() << "'" << std::endl;
}
}
};

View File

@@ -10,17 +10,17 @@ class RenderTriangle {
struct Vertex{
float x,y,z;
Vertex(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
} __attribute__((packed));
};
struct Normal {
float x,y,z;
Normal(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
} __attribute__((packed));
};
struct RGBA {
float r,g,b,a;
RGBA(const float r, const float g, const float b, const float a) : r(r), g(g), b(b), a(a) {;}
} __attribute__((packed));
};
std::vector<Vertex> vertices;
std::vector<Normal> normals;

View File

@@ -1,6 +1,5 @@
#include "Cube.h"
#include "Shader.h"
#include <QtOpenGL>
static float cube_vertices[] = {
@@ -76,7 +75,7 @@ void Cube::render(const RenderSettings& rs) {
rs.shader->setVertices(cube_vertices);
rs.shader->setNormals(cube_normals);
glDrawArrays(GL_TRIANGLES, 0, 12*3);
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, 12*3);
//glDrawElements(GL_TRIANGLES, +12, GL_INT, cube_vertex_indices);
rs.shader->unsetVertices();
rs.shader->unsetNormals();

View File

@@ -54,7 +54,7 @@ void Handrail::render(const RenderSettings& rs) {
}
rs.shader->setVertices(vertices.data());
glDrawArrays(GL_LINES, 0, vertices.size() / 3);
rs.funcs->glDrawArrays(GL_LINES, 0, vertices.size() / 3);
rs.shader->unsetVertices();
rs.shader->release();

View File

@@ -26,7 +26,7 @@ void Outline::render(const RenderSettings& rs) {
rs.shader->setColor(color.x, color.y, color.z);
rs.shader->setVertices(triangles.getVertices().data());
rs.shader->setNormals(triangles.getNormals().data());
glDrawArrays(GL_TRIANGLES, 0, triangles.getVertices().size() / 3);
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, triangles.getVertices().size() / 3);
rs.shader->unsetVertices();
rs.shader->unsetNormals();

View File

@@ -1,110 +1,112 @@
#ifndef POLYGON_H
#define POLYGON_H
// Duplicated file with Indoor/wifi/estimate/ray3/ModelFactoryHelper.h
//#ifndef POLYGON_H
//#define POLYGON_H
#include <Indoor/floorplan/v2/Floorplan.h>
#include "../../../lib/gpc/gpc.h"
//#include <Indoor/floorplan/v2/Floorplan.h>
//#include "../../../lib/gpc/gpc.h"
class Polygon {
//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;
// 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;
}
};
// }
// 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:
//private:
GPCPolygon state;
// GPCPolygon state;
public:
//public:
void add(const Floorplan::Polygon2& poly) {
GPCPolygon cur = toGPC(poly);
//GPCPolygon out;
gpc_polygon_clip(GPC_UNION, &state, &cur, &state);
//state = out;
}
// 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;
}
// 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) {
// std::vector<std::vector<Point3>> get(float z) {
gpc_tristrip res;
res.num_strips = 0;
res.strip = nullptr;
// gpc_tristrip res;
// res.num_strips = 0;
// res.strip = nullptr;
//res.strip = (gpc_vertex_list*) malloc(1024);
gpc_polygon_to_tristrip(&state, &res);
// //res.strip = (gpc_vertex_list*) malloc(1024);
// gpc_polygon_to_tristrip(&state, &res);
std::vector<std::vector<Point3>> trias;
// 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);
}
// 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);
// gpc_free_tristrip(&res);
return std::move(trias);
// return std::move(trias);
}
// }
private:
//private:
GPCPolygon toGPC(Floorplan::Polygon2 poly) {
// 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);
}
// 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);
// GPCPolygon gpol;
// gpc_vertex_list list;
// list.num_vertices = verts.size();
// list.vertex = verts.data();
// gpc_add_contour(&gpol, &list, 0);
return gpol;
// return gpol;
}
// }
};
//};
#endif // POLYGON_H
//#endif // POLYGON_H

View File

@@ -1,11 +1,15 @@
#ifndef RENDERABLE3D_H
#define RENDERABLE3D_H
#include <QOpenGLFunctions>
class Shader;
struct RenderSettings {
Shader* shader = nullptr;
RenderSettings(Shader* shader) : shader(shader) {;}
Shader* shader = nullptr;
QOpenGLFunctions* funcs = nullptr;
RenderSettings(Shader* shader, QOpenGLFunctions* f) : shader(shader), funcs(f) {;}
};

View File

@@ -22,23 +22,24 @@ Shader::Shader() {
)");
addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, R"(
uniform vec4 color;
uniform lowp vec4 color;
uniform bool useNormal;
uniform bool useVertexColor;
varying highp vec3 v_normal;
varying lowp vec4 v_color;
varying lowp vec4 v_vertex;
void main() {
vec3 lightPos = vec3(0,0,0); // camera
mediump vec3 lightPos = vec3(0,0,0); // camera
//vec3 lightVec = normalize(vec3(0,0,1));
vec3 lightVec = normalize(lightPos - v_vertex.xyz);
float intensity = useNormal ? 0.3 + 0.7 * dot( normalize(v_normal), lightVec ) : 1.0; // light at camera pos
vec4 col = useVertexColor ? v_color : color;
mediump vec3 lightVec = normalize(lightPos - v_vertex.xyz);
lowp float intensity = useNormal ? 0.3 + 0.7 * dot( normalize(v_normal), lightVec ) : 1.0; // light at camera pos
lowp vec4 col = useVertexColor ? v_color : color;
gl_FragColor.rgb = col.rgb * intensity;
gl_FragColor.a = col.a;
}
)");
//bindAttributeLocation("vertices", 0);
if (!link()) {
@@ -50,6 +51,7 @@ Shader::Shader() {
void Shader::setModelMatrix(const QMatrix4x4& m) {
//vao.bind();;
setUniformValue(getUniform("M"), m);
}

View File

@@ -69,20 +69,20 @@ void Window::render(const RenderSettings& rs) {
rs.shader->setColor(0.75, 0.85, 1.0, 0.35);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
rs.funcs->glEnable(GL_BLEND);
rs.funcs->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glDisable(GL_CULL_FACE);
rs.shader->setModelMatrix(mat);
rs.shader->setVertices(window_vertices);
rs.shader->setNormals(window_normals);
glDrawArrays(GL_TRIANGLES, 0, 12);
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, 12);
rs.shader->unsetVertices();
rs.shader->unsetNormals();
//glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
rs.funcs->glDisable(GL_BLEND);
rs.shader->release();

View File

@@ -10,6 +10,7 @@
#include <QPainter>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include "../misc/Renderable3D.h"
#include "../misc/Shader.h"
@@ -88,7 +89,7 @@ public:
rs.shader->setVertices(data.getVertices().data());
rs.shader->setVertexColor(data.getRGBA().data());
glDrawArrays(GL_TRIANGLES, 0, data.getVertices().size()/3);
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, data.getVertices().size()/3);
rs.shader->unsetVertices();
rs.shader->unsetVertexColor();
@@ -132,7 +133,7 @@ public:
rs.shader->setVertices(data.getVertices().data());
rs.shader->setVertexColor(data.getRGBA().data());
glDrawArrays(GL_LINES, 0, data.getVertices().size()/3);
rs.funcs->glDrawArrays(GL_LINES, 0, data.getVertices().size()/3);
rs.shader->unsetVertices();
rs.shader->unsetVertexColor();