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

@@ -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);}
}
}
*/
}