worked on android port

opengl1 -> es
This commit is contained in:
root
2018-01-31 17:15:11 +01:00
parent a9bab839b2
commit e5e19779d5
53 changed files with 884 additions and 203 deletions

View File

@@ -43,7 +43,10 @@ SOURCES += \
params/MetaEditModel.cpp \
mapview/2D/MapView2D.cpp \
misc/LINTView.cpp \
mapview/3DNavMesh/QNavMeshSettings.cpp
mapview/3DNavMesh/QNavMeshSettings.cpp \
mapview/3D/misc/Cube.cpp \
mapview/3D/misc/Shader.cpp \
mapview/3D/misc/Window.cpp
HEADERS += MainWindow.h \
@@ -170,7 +173,12 @@ HEADERS += MainWindow.h \
mapview/3DNavMesh/NavMeshView.h \
mapview/3DNavMesh/NavMeshRenderer.h \
mapview/3DNavMesh/NavMeshModel.h \
mapview/3DNavMesh/QNavMeshSettings.h
mapview/3DNavMesh/QNavMeshSettings.h \
fixC11.h \
mapview/3D/misc/Shader.h \
mapview/3D/misc/Camera.h \
mapview/3D/misc/Renderable3D.h \
mapview/3D/misc/Window.h
FORMS += MainWindow.ui

View File

@@ -1,3 +1,5 @@
#include "fixC11.h"
#include "MainController.h"
#include "MainWindow.h"
@@ -102,7 +104,8 @@ MainController::MainController() {
//mapModel->load("/apps/map24b.xml");
//mapModel->load("/apps/SHL41.xml");
mapModel->load("/mnt/vm/paper/diss/data/maps/SHL41_nm.xml");
//mapModel->load("/mnt/vm/paper/diss/data/maps/SHL41_nm.xml");
mapModel->load("/apps/paper/diss/data/maps/SHL41_nm.xml");
//mapModel->load("/apps/paper/diss/data/maps/map_elevator2.xml");
//mapModel->load("/apps/paper/diss/data/maps/map_issue6.xml");

View File

@@ -1,6 +1,8 @@
#ifndef MAINCONTROLLER_H
#define MAINCONTROLLER_H
#include "fixC11.h"
#include <QObject>
#include <QModelIndex>
#include "MainWindow.h"

View File

@@ -1,3 +1,5 @@
#include "fixC11.h"
#include "MainWindow.h"
#include "ui_MainWindow.h"

View File

@@ -1,6 +1,8 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "fixC11.h"
#include <QMainWindow>
class MapView2D;

View File

@@ -1,6 +1,8 @@
#ifndef UIHELPER_H
#define UIHELPER_H
#include "fixC11.h"
#include <QImage>
#include <QPainter>
#include <QRgb>

60
fixC11.h Normal file
View File

@@ -0,0 +1,60 @@
#ifndef FIXC11_H
#define FIXC11_H
#ifdef ANDROID
#include <cmath>
#include <sstream>
#include <cstdio>
namespace std {
//template <typename T> T sqrt(const T val) {return ::sqrt(val);}
//}
template <typename T> inline string to_string(const T val) {
stringstream ss;
ss << val;
return ss.str();
}
template <typename T> inline T round(const T val) {
return ::round(val);
}
// http://stackoverflow.com/questions/19478687/no-member-named-stoi-in-namespace-std
inline int stoi(const std::string& str) {
std::istringstream is(str);
int val; is >> val; return val;
}
// analog zu oben
inline float stof(const std::string& str) {
std::istringstream is(str);
float val; is >> val; return val;
}
// analog zu oben
inline double stod(const std::string& str) {
std::istringstream is(str);
double val; is >> val; return val;
}
// analog zu oben
inline uint64_t stol(const std::string& str) {
std::istringstream is(str);
uint64_t val; is >> val; return val;
}
// inline int sprintf(char* str, const char * format, ...) {
// //return ::sprintf(str, format, ...);
// return 0;
// }
}
#endif
#endif // FIXC11_H

View File

@@ -1,3 +1,5 @@
#include "fixC11.h"
#include "MainController.h"
#include <QApplication>

View File

@@ -1,3 +1,5 @@
#include "../../fixC11.h"
#include "MapView2D.h"
#include <QPainter>

View File

@@ -4,6 +4,8 @@
#include <QWidget>
#include <QOpenGLWidget>
#include "../../fixC11.h"
#include "Scaler.h"
class MapModel;
class MV2DElement;

View File

@@ -5,6 +5,8 @@
#include <QMouseEvent>
#include <QObject>
#include "../../../fixC11.h"
#include "../Painter.h"
class MapView2D;

View File

@@ -2,6 +2,7 @@
#define TOOLS_H
#include <vector>
#include "../../../fixC11.h"
#include "Tool.h"
/**

View File

@@ -2,12 +2,13 @@
#define MV3DELEMENT_H
#include "MapView3D.h"
#include "misc/Renderable3D.h"
/**
* represents one drawable
* element shown within the MapView3D
*/
class MV3DElement {
class MV3DElement : public Renderable3D {
public:
@@ -16,8 +17,8 @@ public:
public:
/** repaint me */
virtual void paintGL() = 0;
/** OLD: repaint me */
//virtual void paintGL() = 0;
/** is this a transparent element? */
virtual bool isTransparent() const = 0;

View File

@@ -22,11 +22,11 @@ protected:
/** repaint me */
void paintGL() override {
void render(const RenderSettings& rs) override {
Cube cube(ap->getPos(f), 0.25);
glColor3f(0,0,1);
cube.paintGL();
cube.setColor(0,0,1);
cube.render(rs);
}

View File

@@ -24,18 +24,16 @@ public:
}
/** repaint me */
void paintGL() override {
void render(const RenderSettings& rs) override {
const Point3 pos(e->center.x, e->center.y, f->getStartingZ() + e->height_m/2);
const Point3 size(e->width/2, e->depth/2, e->height_m/2.0001); // z-fighting
const Point3 rot(0,0,e->rotation * 180 / M_PI);
// fill color
glColor3f(0.2, 0.2, 0.2);
// build
Cube cube(pos, size, rot);
cube.paintGL();
cube.setColor(0.2, 0.2, 0.2);
cube.render(rs);
}

View File

@@ -23,11 +23,11 @@ protected:
/** repaint me */
void paintGL() override {
void render(const RenderSettings& rs) override {
Cube cube(fpl->getPosition(*f), 0.15);
glColor3f(1,0,1);
cube.paintGL();
cube.setColor(1,0,1);
cube.render(rs);
}

View File

@@ -23,7 +23,7 @@ public:
}
/** repaint me */
void paintGL() override {
void render(const RenderSettings& rs) override {
const Point2 from = fo->from;
const Point2 to = fo->to;
@@ -44,12 +44,10 @@ public:
const Point3 size(sx, sy, sz);
const Point3 rot(0,0,deg);
// fill color
glColor3f(0.395, 0.263, 0.129);
// build
Cube cube(pos, size, rot);
cube.paintGL();
cube.setColor(0.395, 0.263, 0.129);
cube.render(rs);
//glColor3f(0.4, 0.4, 0.4);
//Plane p(fo->from, fo->to, f->atHeight, fo->height);

View File

@@ -5,6 +5,8 @@
#include <Indoor/math/Math.h>
#include "misc/Cube.h"
#include "misc/Window.h"
#include "MV3DElement.h"
@@ -37,7 +39,7 @@ protected:
Wall(const Point2 from, const Point2 to, const float thickness_m, const Floorplan::Material mat, float atHeight, float height) :
from(from), to(to), thickness_m(thickness_m), mat(mat), atHeight(atHeight), height(height) {;}
void paintGL() {
void render(const RenderSettings& rs) {
const float rad = -std::atan2(to.y - from.y, to.x - from.x);
const float deg = rad * 180 / M_PI;
@@ -50,154 +52,27 @@ protected:
const Point3 pos(cen2.x, cen2.y, atHeight + height/2);
// div by 2.01 to prevent overlapps and z-fi
const float sx = from.getDistance(to) / 2.01f;
const float sy = thickness_m / 2.01f;
const float sz = height / 2.01f; // prevent overlaps
const float sx = from.getDistance(to) / 2.02f;
const float sy = thickness_m / 2.02f;
const float sz = height / 2.02f; // prevent overlaps
const Point3 size(sx, sy, sz);
const Point3 rot(0,0,deg);
// fill color
if (mat == Floorplan::Material::CONCRETE) {
glColor3f(0.5, 0.5, 0.5);
} else {
glColor3f(0.75, 0.75, 0.75);
}
// build
Cube cube(pos, size, rot);
cube.paintGL();
/*
float y1 = atHeight;
float y2 = atHeight + height;
const Point2 p01 = from + dirPerp * w;
const Point2 p02 = from - dirPerp * w;
const Point2 p03 = to - dirPerp * w;
const Point2 p04 = to + dirPerp * w;
// fill the wall
if (mat == Floorplan::Material::CONCRETE) {
glColor3f(0.5, 0.5, 0.5);
cube.setColor(0.5, 0.5, 0.5);
} else {
glColor3f(0.75, 0.75, 0.75);
cube.setColor(0.75, 0.75, 0.75);
}
cube.render(rs);
auto renderQuad = [&] (const Point2 p1, const Point2 p2) {
glVertex3f(p1.x, y1, p1.y);
glVertex3f(p2.x, y1, p2.y);
glVertex3f(p2.x, y2, p2.y);
glVertex3f(p1.x, y2, p1.y);
};
glDisable(GL_CULL_FACE);
glBegin(GL_QUADS);
//glNormal3f(n.x, n.y, n.z);
// short
renderQuad(p01, p02);
renderQuad(p03, p04);
// long
renderQuad(p02, p03);
renderQuad(p04, p01);
//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);
glEnd();
glBegin(GL_CULL_FACE);
*/
/*
// 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);
// 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);
// align normals to virtual viewport
Point3 view(99,99,99);
if ((view-n).length() > (view+n).length()) {n = -n;}
glDisable(GL_CULL_FACE);
glBegin(GL_QUADS);
glNormal3f(n.x, n.y, n.z);
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);
glEnd();
glEnable(GL_CULL_FACE);
*/
}
};
struct Window {
Point2 from;
Point2 to;
float atHeight;
float height;
Window(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(to.x, y2, to.y);
Point3 p4 = Point3(from.x, y2, from.y);
// calculate normal
Point3 n = Math::normal(p2-p1, p3-p1);
// align normals to virtual viewport
Point3 view(99,99,99);
if ((view-n).length() > (view+n).length()) {n = -n;}
glColor4f(0.75, 0.85, 1.0, 0.35);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
glBegin(GL_QUADS);
glNormal3f(n.x, n.y, n.z);
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);
glEnd();
glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
}
};
struct Handrail {
struct Handrail : public Renderable3D {
Point2 from;
Point2 to;
@@ -207,7 +82,7 @@ protected:
Handrail(const Point2 from, const Point2 to, float atHeight, float height) :
from(from), to(to), atHeight(atHeight), height(height) {;}
void paintGL() {
void render(const RenderSettings& rs) override {
float y1 = atHeight;
float y2 = atHeight + height;
@@ -219,6 +94,10 @@ protected:
Point3 p3 = Point3(from.x, y2, from.y);
Point3 p4 = Point3(to.x, y2, to.y);
/*
TODO_GL
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
@@ -252,27 +131,29 @@ protected:
glEnd();
glEnable(GL_LIGHTING);
*/
}
};
/** repaint me */
void paintGL() override {
void render(const RenderSettings& rs) override {
if (fo->material == Floorplan::Material::GLASS) {
Window win(fo->from, fo->to, f->atHeight, f->height);
win.paintGL();
win.render(rs);
} else if (fo->type == Floorplan::ObstacleType::WALL) {
Wall wall(fo->from, fo->to, fo->thickness_m, fo->material, f->atHeight, f->height);
wall.paintGL();
wall.render(rs);
} else if (fo->type == Floorplan::ObstacleType::HANDRAIL) {
Handrail rail(fo->from, fo->to, f->atHeight, 1.0);
rail.paintGL();
rail.render(rs);
}

View File

@@ -9,6 +9,7 @@
#include "../../lib/gpc/gpc.h"
#include "misc/Polygon.h"
#include "misc/Shader.h"
class MV3DElementFloorOutline : public MV3DElement {
@@ -37,15 +38,60 @@ protected:
/** repaint me */
void paintGL() override {
void render(const RenderSettings& rs) override {
rebuildIfNeeded();
rs.shader->bind();
glDisable(GL_CULL_FACE);
QMatrix4x4 mat;
rs.shader->setModelMatrix(mat);
for (auto& it : elements) {
//Polygon& pol = it.second->pol;
std::vector<std::vector<Point3>>& trias = it.second->trias;
if (it.first == "outdoor") {
rs.shader->setColor(0.0, 0.5, 0.0);
} else {
rs.shader->setColor(0.2, 0.2, 0.2);
}
std::vector<float> values;
std::vector<float> normals;
for (const std::vector<Point3>& tria : trias) {
for (int i = 2; i < tria.size(); ++i) {
const Point3 p1 = tria[i-2];
const Point3 p2 = tria[i-1];
const Point3 p3 = tria[i-0];
values.push_back(p1.x); values.push_back(p1.y); values.push_back(p1.z);
values.push_back(p2.x); values.push_back(p2.y); values.push_back(p2.z);
values.push_back(p3.x); values.push_back(p3.y); values.push_back(p3.z);
normals.push_back(0); normals.push_back(1); normals.push_back(0);
normals.push_back(0); normals.push_back(1); normals.push_back(0);
normals.push_back(0); normals.push_back(1); normals.push_back(0);
}
}
rs.shader->setVertices(values.data());
rs.shader->setNormals(normals.data());
glDrawArrays(GL_TRIANGLES, 0, values.size() / 3);
rs.shader->unsetVertices();
rs.shader->unsetNormals();
/*
TODO_GL
if (it.first == "outdoor") {
glColor3f(0.0, 0.5, 0.0);
} else {
@@ -63,8 +109,14 @@ protected:
}
glEnable(GL_CULL_FACE);
*/
}
glEnable(GL_CULL_FACE);
rs.shader->release();
}
void rebuildIfNeeded() {

View File

@@ -21,11 +21,11 @@ protected:
/** repaint me */
void paintGL() override {
void render(const RenderSettings& rs) override {
Cube cube(reg->posOnMap_m, 0.5);
glColor3f(0,0,0);
cube.paintGL();
cube.setColor(0,0,0);
cube.render(rs);
}

View File

@@ -22,10 +22,12 @@ protected:
/** repaint me */
void paintGL() override {
void render(const RenderSettings& rs) override {
glDisable(GL_CULL_FACE);
/*
TODO_GL
//glColor3f(1.0, 0.55, 0.55);
glColor3f(0.3, 0.3, 0.3);
glBegin(GL_QUADS);
@@ -55,7 +57,7 @@ protected:
glEnd();
glEnable(GL_CULL_FACE);
*/
}
bool isTransparent() const override {

View File

@@ -1,5 +1,6 @@
#include "MapView3D.h"
#include "../../fixC11.h"
#include "MapView3D.h"
#include "../model/MapModelElement.h"
#include "../model/MapModel.h"
@@ -10,11 +11,11 @@
#include "../3DNavMesh/NavMeshModel.h"
#include "../3DNavMesh/NavMeshRenderer.h"
MapView3D::MapView3D(QWidget *parent) : QGLWidget(parent) {
MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
rot.x = 45;
rot.x = 0;
rot.y = 0;
rot.z = 45;
rot.z = 0;
center.x = 0;
center.y = 0;
@@ -33,9 +34,10 @@ void MapView3D::initializeGL() {
//setFormat(QGLFormat(QGL::SampleBuffers));
QGLWidget::initializeGL();
QOpenGLWidget::initializeGL();
glCullFace(GL_FRONT);
glFrontFace(GL_CCW);
//glDisable(GL_CULL_FACE);
glEnable(GL_CULL_FACE);
@@ -46,6 +48,10 @@ void MapView3D::initializeGL() {
// glEnable(GL_MULTISAMPLE);
// glEnable(GL_LINE_SMOOTH);
/*
TODO_GL
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
@@ -73,8 +79,11 @@ void MapView3D::initializeGL() {
// glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
// glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
*/
// background color
qglClearColor(Qt::white);
//glClearColor(Qt::white);
glClearColor(1,1,1,1);
}
@@ -82,14 +91,14 @@ void MapView3D::paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*
TODO_GL
glLoadIdentity();
glScalef(+1, -1, +1);
// 3) scale
glScalef(scale.x, scale.y, scale.z);
@@ -113,6 +122,8 @@ void MapView3D::paintGL() {
// // 1) translate into center
// glTranslatef(tra.x, tra.y, tra.z);
*/
draw();
@@ -123,7 +134,12 @@ void MapView3D::resizeGL(int width, int height) {
//int side = qMin(width, height);
//glViewport((width - side) / 2, (height - side) / 2, side, side);
glViewport(0, 0, width, height);
//glViewport(0, 0, width, height);
/*
TODO_GL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@@ -138,9 +154,9 @@ void MapView3D::resizeGL(int width, int height) {
//glFrustum(+w, -w, -h, +h, -20, +20);
glMatrixMode(GL_MODELVIEW);
*/
}
@@ -155,13 +171,12 @@ 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.z -= dx/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);
//Point3 vec(-dx * 2 / width() , 0, +dy * 2 / height());
vec = vec.rot(rot.x/180*M_PI, rot.y/180*M_PI, rot.z/180*M_PI);
vec /= scale;
center += vec;
@@ -235,14 +250,57 @@ void MapView3D::setShowNavMesh(bool show) {
}
#include "misc/Shader.h"
void MapView3D::draw() {
static RenderSettings rs = RenderSettings(new Shader());
glViewport(0, 0, width(), height());
//glCullFace(GL_FRONT);
//glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
// view
QMatrix4x4 V;
V.scale(scale.x, scale.y, scale.z);
V.rotate(rot.x, 1.0, 0.0, 0.0);
V.rotate(rot.y, 0.0, 1.0, 0.0);
V.rotate(rot.z, 0.0, 0.0, 1.0);
V.translate(center.x, center.z, center.y);
V.translate(0,0,-50);
// V.lookAt(QVector3D(30,-25,25), QVector3D(30,10,0), QVector3D(0,1,0));
// projection
QMatrix4x4 P;
float aspect = (float) width() / (float) height();
float w = 2.0f;
float h = 2.0f * height() / width();
viewport.size.x = w;
viewport.size.y = h;
//P.ortho(-w, +w, +h, -h, 0.1f, +30); // glOrtho(-w, +w, -h, +h, -20, +20);
P.perspective(45.0f, aspect, 0.01, 100);
rs.shader->bind();
rs.shader->setViewMatrix(V);
rs.shader->setProjectionMatrix(P);
Cube cube(Point3(0,0,0), 1);
cube.setColor(1,0,0);
cube.render(rs);
/*
// solid floorplan parts
if (showFloorplan) {
std::vector<MapModelElement*> elements = getModel()->getVisibleElements();
for (MapModelElement* el : elements) {
if (el->getMV3D() && !el->getMV3D()->isTransparent()) {el->getMV3D()->paintGL();}
if (el->getMV3D() && !el->getMV3D()->isTransparent()) {el->getMV3D()->render(rs);}
}
}
@@ -260,9 +318,11 @@ void MapView3D::draw() {
std::vector<MapModelElement*> elements = getModel()->getVisibleElements();
for (MapModelElement* el : elements) {
if (el->getMV3D() && el->getMV3D()->isTransparent()) {el->getMV3D()->paintGL();}
if (el->getMV3D() && el->getMV3D()->isTransparent()) {el->getMV3D()->render(rs);}
}
}
*/
}

View File

@@ -1,6 +1,8 @@
#ifndef MAPVIEW3D_H
#define MAPVIEW3D_H
#include "../../fixC11.h"
#include <QtWidgets>
#include <QtOpenGL>
@@ -12,7 +14,7 @@ class GridRenderer;
class NavMeshRenderer;
class NavMeshModel;
class MapView3D : public QGLWidget {
class MapView3D : public QOpenGLWidget {
Q_OBJECT

23
mapview/3D/misc/Camera.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef CAMERA_H
#define CAMERA_H
#include <QMatrix4x4>
#include <QMatrix3x3>
class Camera {
QMatrix4x4 V;
QMatrix4x4 P;
public:
Camera() {
}
QMatrix4x4 getV() const {return V;}
QMatrix4x4 getP() const {return P;}
};
#endif // CAMERA_H

259
mapview/3D/misc/Cube.cpp Normal file
View File

@@ -0,0 +1,259 @@
#include "Cube.h"
#include "Shader.h"
#include <QtOpenGL>
//static float cube_vertices[] = {
//1 -1.0000, -1.0000, -1.0000,
//2 -1.0000, 1.0000, -1.0000,
//3 1.0000, 1.0000, -1.0000,
//4 1.0000, -1.0000, -1.0000,
//5 -1.0000, -1.0000, 1.0000,
//6 1.0000, -1.0000, 1.0000,
//7 1.0000, 1.0000, 1.0000,
//8 -1.0000, 1.0000, 1.0000,
//};
//static int cube_vertex_indices[] = {
// 1, 2, 3,
// 3, 4, 1,
// 5, 6, 7,
// 7, 8, 5,
// 1, 4, 6,
// 6, 5, 1,
// 4, 3, 7,
// 7, 6, 4,
// 3, 2, 8,
// 8, 7, 3,
// 2, 1, 5,
// 5, 8, 2,
//};
static float cube_vertices[] = {
-1, -1, 0,
+1, -1, 0,
0, +1, 0,
// -1.0000, -1.0000, -1.0000, -1.0000, 1.0000, -1.0000, 1.0000, 1.0000, -1.0000,
// 1.0000, 1.0000, -1.0000, 1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000,
// -1.0000, -1.0000, 1.0000, 1.0000, -1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
// 1.0000, 1.0000, 1.0000, -1.0000, 1.0000, 1.0000, -1.0000, -1.0000, 1.0000,
// -1.0000, -1.0000, -1.0000, 1.0000, -1.0000, -1.0000, 1.0000, -1.0000, 1.0000,
// 1.0000, -1.0000, 1.0000, -1.0000, -1.0000, 1.0000, -1.0000, -1.0000, -1.0000,
// 1.0000, -1.0000, -1.0000, 1.0000, 1.0000, -1.0000, 1.0000, 1.0000, 1.0000,
// 1.0000, 1.0000, 1.0000, 1.0000, -1.0000, 1.0000, 1.0000, -1.0000, -1.0000,
// 1.0000, 1.0000, -1.0000, -1.0000, 1.0000, -1.0000, -1.0000, 1.0000, 1.0000,
// -1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, -1.0000,
// -1.0000, 1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000, 1.0000,
// -1.0000, -1.0000, 1.0000, -1.0000, 1.0000, 1.0000, -1.0000, 1.0000, -1.0000,
};
//static float cube_normals[] = {
// 0.0000, 0.0000, -1.0000,
// 0.0000, 0.0000, 1.0000,
// 0.0000, -1.0000, 0.0000,
// 1.0000, 0.0000, 0.0000,
// 0.0000, 1.0000, 0.0000,
// -1.0000, 0.0000, 0.0000,
//};
static float cube_normals[] = {
0.0000, 0.0000, -1.0000, 0.0000, 0.0000, -1.0000, 0.0000, 0.0000, -1.0000,
0.0000, 0.0000, -1.0000, 0.0000, 0.0000, -1.0000, 0.0000, 0.0000, -1.0000,
0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000,
0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000,
0.0000, -1.0000, 0.0000, 0.0000, -1.0000, 0.0000, 0.0000, -1.0000, 0.0000,
0.0000, -1.0000, 0.0000, 0.0000, -1.0000, 0.0000, 0.0000, -1.0000, 0.0000,
1.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000,
1.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000,
0.0000, 1.0000, 0.0000,0.0000, 1.0000, 0.0000,0.0000, 1.0000, 0.0000,
0.0000, 1.0000, 0.0000,0.0000, 1.0000, 0.0000,0.0000, 1.0000, 0.0000,
-1.0000, 0.0000, 0.0000,-1.0000, 0.0000, 0.0000,-1.0000, 0.0000, 0.0000,
-1.0000, 0.0000, 0.0000,-1.0000, 0.0000, 0.0000,-1.0000, 0.0000, 0.0000,
};
//static int cube_normal_indices[] = {
// 1, 1, 1,
// 1, 1, 1,
// 2, 2, 2,
// 2, 2, 2,
// 3, 3, 3,
// 3, 3, 3,
// 4, 4, 4,
// 4, 4, 4,
// 5, 5, 5,
// 5, 5, 5,
// 6, 6, 6,
// 6, 6, 6,
//};
//static float cube_vertices[] = {
// // bottom
// +1, -1, -1,
// +1, -1, +1,
// -1, -1, +1,
// -1, -1, +1,
// -1, -1, -1,
// +1, -1, -1,
// // top
// -1, +1, -1,
// -1, +1, +1,
// +1, +1, +1,
// +1, +1, +1,
// +1, +1, -1,
// -1, +1, -1,
// // left
// -1, -1, -1,
// -1, -1, +1,
// -1, +1, +1,
// -1, +1, +1,
// -1, +1, -1,
// -1, -1, -1,
// // right
// +1, +1, -1,
// +1, +1, +1,
// +1, -1, +1,
// +1, -1, +1,
// +1, -1, -1,
// +1, +1, -1,
// // front
// +1, +1, +1,
// -1, +1, +1,
// -1, -1, +1,
// -1, -1, +1,
// +1, -1, +1,
// +1, +1, +1,
// // rear
// +1, -1, -1,
// -1, -1, -1,
// -1, +1, -1,
// -1, +1, -1,
// +1, +1, -1,
// +1, -1, -1,
//};
//static float cube_normals[] = {
// // bottom
// 0,-1,0,
// 0,-1,0,
// 0,-1,0,
// 0,-1,0,
// 0,-1,0,
// 0,-1,0,
// // top
// 0,+1,0,
// 0,+1,0,
// 0,+1,0,
// 0,+1,0,
// 0,+1,0,
// 0,+1,0,
// // left
// -1,0,0,
// -1,0,0,
// -1,0,0,
// -1,0,0,
// -1,0,0,
// -1,0,0,
// // right
// +1,0,0,
// +1,0,0,
// +1,0,0,
// +1,0,0,
// +1,0,0,
// +1,0,0,
// // front
// 0,0,+1,
// 0,0,+1,
// 0,0,+1,
// 0,0,+1,
// 0,0,+1,
// 0,0,+1,
// // rear
// 0,0,-1,
// 0,0,-1,
// 0,0,-1,
// 0,0,-1,
// 0,0,-1,
// 0,0,-1,
//};
static Shader* shader = nullptr;
Cube::Cube(Point3 pos, float size) : pos(pos), size(size,size,size), rot(0,0,0) {
}
Cube::Cube(Point3 pos, Point3 size, Point3 rot) : pos(pos), size(size), rot(rot) {
}
void Cube::setColor(float r, float g, float b) {
this->color = Point3(r,g,b);
}
void Cube::render(const RenderSettings& rs) {
rs.shader->bind();
QMatrix4x4 mat;
mat.translate(pos.x, pos.y, pos.z);
mat.rotate(rot.x, 1, 0, 0);
mat.rotate(rot.y, 0, 1, 0);
mat.rotate(rot.z, 0, 0, 1);
mat.scale(size.x, size.y, size.z);
// mat.scale(0.1, 0.1, 0.1);
rs.shader->setModelMatrix(mat);
// shader->setViewMatrix(V);
// shader->setProjectionMatrix(P);
rs.shader->setColor(color.x, color.y, color.z);
rs.shader->setVertices(cube_vertices);
rs.shader->setNormals(cube_normals);
glDrawArrays(GL_TRIANGLES, 0, 1*3);
//glDrawElements(GL_TRIANGLES, 12, GL_INT, cube_vertex_indices);
rs.shader->unsetVertices();
rs.shader->unsetNormals();
rs.shader->release();
};

View File

@@ -2,9 +2,11 @@
#define CUBE_H
#include <Indoor/geo/Point3.h>
#include <QtOpenGL>
#include "Renderable3D.h"
class Cube {
class Shader;
class Cube : public Renderable3D {
private:
@@ -12,20 +14,28 @@ private:
Point3 size;
Point3 rot;
Point3 color;
public:
Cube(Point3 pos, float size) : pos(pos), size(size,size,size), rot(0,0,0) {
Cube(Point3 pos, float size);
}
Cube(Point3 pos, Point3 size, Point3 rot);
Cube(Point3 pos, Point3 size, Point3 rot) : pos(pos), size(size), rot(rot) {
void setColor(float r, float g, float b);
}
void render(const RenderSettings& rs) override;
void paintGL() {
float s = 1;
/*
void paintGL(Shader* shader);
TODO_GL
glColor3f(color.x, color.y, color.z);
glPushMatrix();
@@ -90,7 +100,7 @@ public:
glPopMatrix();
}
*/
};

View File

@@ -0,0 +1,20 @@
#ifndef RENDERABLE3D_H
#define RENDERABLE3D_H
class Shader;
struct RenderSettings {
Shader* shader = nullptr;
RenderSettings(Shader* shader) : shader(shader) {;}
};
class Renderable3D {
public:
virtual void render(const RenderSettings& rs) = 0;
};
#endif // RENDERABLE3D_H

View File

@@ -0,0 +1,88 @@
#include "Shader.h"
#include <iostream>
Shader::Shader() {
addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, R"(
attribute highp vec3 a_vertex;
attribute highp vec3 a_normal;
uniform highp mat4 M;
uniform highp mat4 V;
uniform highp mat4 P;
varying highp vec3 normal;
void main() {
gl_Position = vec4(a_vertex, 1.0);
normal = normalize( V*M*vec4(a_normal, 0.0) );
}
)");
addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, R"(
uniform vec4 color;
varying highp vec3 normal;
void main() {
float intensity = dot( normal, normalize(vec3(-1,-1,-3)) );
gl_FragColor.rgb = color.rgb * intensity;
gl_FragColor.a = color.a;
}
)");
//bindAttributeLocation("vertices", 0);
if (!link()) {
std::cout << log().toStdString() << std::endl;
throw std::runtime_error("shader link error");
}
}
void Shader::setModelMatrix(const QMatrix4x4& m) {
//setUniformValue(getUniform("M"), m);
}
void Shader::setViewMatrix(const QMatrix4x4& m) {
//setUniformValue(getUniform("V"), m);
}
void Shader::setProjectionMatrix(const QMatrix4x4& m) {
//setUniformValue(getUniform("P"), m);
}
int Shader::getUniform(const char* name) {
int loc = uniformLocation(name);
if (loc == -1) {throw std::runtime_error("error");}
return loc;
}
int Shader::getAttribute(const char* name) {
int loc = attributeLocation(name);
if (loc == -1) {throw std::runtime_error("error");}
return loc;
}
void Shader::setColor(const float r, const float g, const float b) {
setUniformValue(getUniform("color"), QVector4D(r,g,b,1));
}
void Shader::setColor(const float r, const float g, const float b, const float a) {
setUniformValue(getUniform("color"), QVector4D(r,g,b,a));
}
void Shader::setVertices(const float* values) {
const int loc = getAttribute("a_vertex");
enableAttributeArray(loc);
setAttributeArray(loc, GL_FLOAT, values, 3);
}
void Shader::unsetVertices() {
const int loc = getAttribute("a_vertex");
disableAttributeArray(loc);
}
void Shader::setNormals(const float* values) {
const int loc = getAttribute("a_normal");
enableAttributeArray(loc);
setAttributeArray(loc, GL_FLOAT, values, 3);
}
void Shader::unsetNormals() {
const int loc = getAttribute("a_normal");
disableAttributeArray(loc);
}

33
mapview/3D/misc/Shader.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef SHADER_H
#define SHADER_H
#include <QOpenGLShaderProgram>
class Shader : public QOpenGLShaderProgram {
public:
Shader();
void setModelMatrix(const QMatrix4x4& m);
void setViewMatrix(const QMatrix4x4& m);
void setProjectionMatrix(const QMatrix4x4& m);
void setColor(const float r, const float g, const float b);
void setColor(const float r, const float g, const float b, const float a);
void setVertices(const float*);
void unsetVertices();
void setNormals(const float*);
void unsetNormals();
int getUniform(const char*);
int getAttribute(const char*);
};
#endif // SHADER_H

View File

@@ -0,0 +1,87 @@
#include "Window.h"
#include "Shader.h"
#include <Indoor/geo/Point3.h>
#include <Indoor/math/Math.h>
static float window_vertices[] = {
+1, 0, +1,
-1, 0, +1,
-1, 0, -1,
-1, 0, -1,
+1, 0, -1,
+1, 0, +1,
-1, 0, +1,
+1, 0, +1,
-1, 0, -1,
+1, 0, -1,
-1, 0, -1,
+1, 0, +1,
};
static float window_normals[] = {
0,-1,0,
0,-1,0,
0,-1,0,
0,-1,0,
0,-1,0,
0,-1,0,
0,+1,0,
0,+1,0,
0,+1,0,
0,+1,0,
0,+1,0,
0,+1,0,
};
Window::Window(const Point2 from, const Point2 to, float atHeight, float height) :
from(from), to(to), atHeight(atHeight), height(height) {
const Point2 cen = (from+to)/2;
const float sx = from.getDistance(to) / 2.0f;
const float sz = height / 2.0f;
const float rad = -std::atan2(to.y - from.y, to.x - from.x);
const float deg = rad * 180 / M_PI;
mat.translate(cen.x, cen.y, atHeight + height/2);
mat.rotate(deg, 0, 0, 1);
mat.scale(sx, 1, sz);
}
void Window::render(const RenderSettings& rs) {
rs.shader->bind();
rs.shader->setColor(0.75, 0.85, 1.0, 0.35);
glEnable(GL_BLEND);
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.shader->unsetVertices();
rs.shader->unsetNormals();
//glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
rs.shader->release();
}

26
mapview/3D/misc/Window.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef WINDOW_H
#define WINDOW_H
#include "Renderable3D.h"
#include <Indoor/geo/Point2.h>
#include <QMatrix4x4>
class Window : public Renderable3D {
Point2 from;
Point2 to;
float atHeight;
float height;
QMatrix4x4 mat;
public:
Window(const Point2 from, const Point2 to, float atHeight, float height);
virtual void render(const RenderSettings& rs) override;
};
#endif // WINDOW_H

View File

@@ -50,6 +50,10 @@ public:
/** render the given grid using GL commands */
void paintGL(Grid<MyNode>* grid) {
/*
TODO_GL
glDisable(GL_LIGHTING);
const float sz = 1.0f; // scale-z: more/less z-spacing
@@ -100,6 +104,8 @@ public:
}
glEnd();
// std::vector<MyNode> vec = lint();
// glPointSize(4.0f);
// glBegin(GL_POINTS);
@@ -114,6 +120,8 @@ public:
glEnable(GL_LIGHTING);
*/
}
// std::vector<MyNode> lint() {

View File

@@ -57,15 +57,14 @@ public:
if (navMesh == nullptr) {return;}
// QPainter qp;
// qp.begin(dst);
/*
TODO_GL
glDisable(GL_LIGHTING);
const float s = 2;
glBegin(GL_TRIANGLES);
for (const NM::NavMeshTriangle* tria : *navMesh) {
@@ -153,6 +152,10 @@ public:
// dst->renderText(0,0, "2342342342342423423423423423423432");
// dst->renderText(0.1, 0.1, 0.1, "lsdfsdfsdfsdfsdfsdfsdfol");
*/
}
// std::vector<MyNode> lint() {

View File

@@ -3,6 +3,8 @@
#include <QObject>
#include "../../fixC11.h"
#include "MapLayer.h"
#include "MapModelElement.h"
#include "MapModelListener.h"

View File

@@ -1,6 +1,8 @@
#ifndef GNUPLOTEXPORT_H
#define GNUPLOTEXPORT_H
#include "fixC11.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include <Indoor/grid/Grid.h>

View File

@@ -1,3 +1,5 @@
#include "../fixC11.h"
#include "LINTView.h"
#include <QStringListModel>

View File

@@ -1,6 +1,8 @@
#ifndef LINTVIEW_H
#define LINTVIEW_H
#include "fixC11.h"
#include <QListView>
class QStringListModel;
#include <Indoor/floorplan/v2/Floorplan.h>

View File

@@ -1,6 +1,8 @@
#ifndef ACTIONWIDGET_H
#define ACTIONWIDGET_H
#include "fixC11.h"
#include <QWidget>
class ActionWidget : public QWidget {

View File

@@ -1,6 +1,8 @@
#ifndef EDITFIELDS_H
#define EDITFIELDS_H
#include "fixC11.h"
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>

View File

@@ -1,3 +1,5 @@
#include "../fixC11.h"
#include "ElementParamWidget.h"
#include "../mapview/model/MapModelElement.h"

View File

@@ -1,6 +1,8 @@
#ifndef PARAMWIDGET_H
#define PARAMWIDGET_H
#include "fixC11.h"
#include <QWidget>
#include "../mapview/model/MapModelElement.h"

View File

@@ -1,3 +1,5 @@
#include "../fixC11.h"
#include "LayerParamWidget.h"
#include <QGridLayout>

View File

@@ -1,6 +1,8 @@
#ifndef LAYERPARAMWIDGET_H
#define LAYERPARAMWIDGET_H
#include "fixC11.h"
#include <QWidget>
class MapLayer;

View File

@@ -1,3 +1,5 @@
#include "../fixC11.h"
#include "LayerTree.h"
#include <QTreeView>

View File

@@ -1,6 +1,8 @@
#ifndef LAYERTREE_H
#define LAYERTREE_H
#include "fixC11.h"
#include <QWidget>
class QTreeView;

View File

@@ -1,3 +1,5 @@
#include "../fixC11.h"
#include "MetaEditModel.h"

View File

@@ -1,6 +1,8 @@
#ifndef METAEDITMODEL_H
#define METAEDITMODEL_H
#include "fixC11.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include <QAbstractTableModel>

View File

@@ -1,3 +1,5 @@
#include "../fixC11.h"
#include "MetaEditWidget.h"
#include "MetaEditModel.h"

View File

@@ -1,9 +1,13 @@
#ifndef METAEDITWIDGET_H
#define METAEDITWIDGET_H
#include "fixC11.h"
#include <QWidget>
#include <Indoor/floorplan/v2/Floorplan.h>
#include "../fixC11.h"
class MetaEditModel;
class QTableView;

View File

@@ -1,6 +1,8 @@
#ifndef STAIRBUILDER_H
#define STAIRBUILDER_H
#include "fixC11.h"
#include <QWidget>
class StairBuilder : public QWidget

View File

@@ -1,3 +1,5 @@
#include "../fixC11.h"
#include "ToolBoxWidget.h"
#include <QVBoxLayout>

View File

@@ -1,6 +1,8 @@
#ifndef TOOLBOX_H
#define TOOLBOX_H
#include "fixC11.h"
#include <QWidget>
class MapLayer;

View File

@@ -1,6 +1,8 @@
#ifndef MAPTREE_H
#define MAPTREE_H
#include "../fixC11.h"
#include <QAbstractItemModel>
#include "../mapview/model/MapModel.h"