worked on 3D display

some ui changes
refactoring
new icons
This commit is contained in:
2018-02-03 23:30:55 +01:00
parent e5e19779d5
commit 3b62f23c0e
21 changed files with 1054 additions and 765 deletions

View File

@@ -11,6 +11,8 @@
#include "../3DNavMesh/NavMeshModel.h"
#include "../3DNavMesh/NavMeshRenderer.h"
#include <QPushButton>
MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
rot.x = 0;
@@ -21,12 +23,51 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
center.y = 0;
center.z = 0;
scale.x = 0.05f;
scale.y = 0.05f;
scale.z = 0.05f;
scale.x = 1.0f;
scale.y = 1.0f;
scale.z = 1.0f;
gridRenderer = new GridRenderer();
QString style = "QPushButton:checked{\
background-color: rgb(200, 200, 230);\
border: none; \
}";
QPushButton* btnFloorplan = new QPushButton(UIHelper::getIcon("floorplan"), "", this);
btnFloorplan->setGeometry(16, 16, 32, 32);
btnFloorplan->setCheckable(true);
btnFloorplan->setChecked(true);
btnFloorplan->setStyleSheet(style);
connect(btnFloorplan, &QPushButton::toggled, [btnFloorplan,this] () {
emit onShow3DFloorplan(btnFloorplan->isChecked());
});
QPushButton* btnPerspective = new QPushButton(UIHelper::getIcon("perspective"), "", this);
btnPerspective->setGeometry(16, 16+8+32, 32, 32);
connect(btnPerspective, &QPushButton::clicked, [this] () {
usePerspectiveProjection = !usePerspectiveProjection;
emit update();
});
QPushButton* btnGrid = new QPushButton(UIHelper::getIcon("grid"), "", this);
btnGrid->setCheckable(true);
btnGrid->setChecked(false);
btnGrid->setGeometry(16+16+32, 16, 32, 32);
btnGrid->setStyleSheet(style);
connect(btnGrid, &QPushButton::toggled, [btnGrid, this] () {
emit onShow3DGrid(btnGrid->isChecked());
});
QPushButton* btnNavMesh = new QPushButton(UIHelper::getIcon("mesh"), "", this);
btnNavMesh->setCheckable(true);
btnNavMesh->setChecked(false);
btnNavMesh->setGeometry(16+16+32+16+32, 16, 32, 32);
btnNavMesh->setStyleSheet(style);
connect(btnNavMesh, &QPushButton::toggled, [btnNavMesh, this] () {
emit onShow3DNavMesh(btnNavMesh->isChecked());
});
}
@@ -36,53 +77,13 @@ void MapView3D::initializeGL() {
QOpenGLWidget::initializeGL();
glCullFace(GL_FRONT);
// this should be the default!!
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
//glDisable(GL_CULL_FACE);
glEnable(GL_CULL_FACE);
// culling, lighting, depth-test, ...
// additional settings
glEnable(GL_DEPTH_TEST);
//glShadeModel(GL_SMOOTH);
// glEnable(GL_MULTISAMPLE);
// glEnable(GL_LINE_SMOOTH);
/*
TODO_GL
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
// 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 );
GLfloat light_diffuse []={ 0.7, 0.7, 0.7, 1.0 };
glLightfv ( GL_LIGHT0, GL_DIFFUSE, light_diffuse );
glLightfv ( GL_LIGHT1, GL_DIFFUSE, light_diffuse );
// otherwise scaling the scene kills lighting normals!
glEnable(GL_NORMALIZE);
// allow using glColor3(r,g,b)
glEnable(GL_COLOR_MATERIAL);
// GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
// GLfloat mat_shininess[] = { 50.0 };
// glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
// glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
*/
// background color
//glClearColor(Qt::white);
glClearColor(1,1,1,1);
}
@@ -91,71 +92,13 @@ 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);
// 2) rotate around center
glRotatef(rot.x, 1.0, 0.0, 0.0);
glRotatef(rot.z, 0.0, 1.0, 0.0);
glRotatef(rot.y, 0.0, 0.0, 1.0);
// 1) post translate (mouse moving)
glTranslatef(center.x, center.z, center.y);
// 0) swap the y axis
//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
// glTranslatef(tra.x, tra.y, tra.z);
*/
draw();
}
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);
/*
TODO_GL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-2, +2, -2, +2, 1.0, 25.0);
//glFrustum(-1,1, -1,1, 0.1,20);
viewport.size.x = 2.0f;
viewport.size.y = 2.0f * height / width;
const float w = viewport.size.x;
const float h = viewport.size.y;
glOrtho(-w, +w, -h, +h, -20, +20);
//glScalef(1,-1,1);
//glFrustum(+w, -w, -h, +h, -20, +20);
glMatrixMode(GL_MODELVIEW);
*/
glViewport(0, 0, width, height);
}
@@ -175,9 +118,9 @@ void MapView3D::mouseMoveEvent(QMouseEvent* e) {
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, +dy / height() * 2 * viewport.size.y, 0);
//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 = vec.rot(-rot.x/180*M_PI, -rot.y/180*M_PI, -rot.z/180*M_PI);
vec /= scale;
center += vec;
}
@@ -256,45 +199,44 @@ 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.translate(0,0,-30);
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.translate(center.x, center.y, center.z);
// 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);
if (usePerspectiveProjection) {
float w = width() / 30;
float h = height() / 30;
viewport.size.x = w;
viewport.size.y = h;
P.perspective(45.0f, aspect, 0.01, 100);
} 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, +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) {
@@ -305,12 +247,12 @@ void MapView3D::draw() {
}
if (showGrid && gridModel) {
gridRenderer->paintGL(gridModel->getGrid());
}
// if (showGrid && gridModel) {
// gridRenderer->paintGL(gridModel->getGrid());
// }
if (showNavMesh && navMeshModel) {
navMeshRenderer->paintGL(navMeshModel->getNavMesh(), this);
navMeshRenderer->render(rs, navMeshModel->getNavMesh(), this);
}
// transparant floorplan parts
@@ -322,7 +264,7 @@ void MapView3D::draw() {
}
}
*/
}