code format

This commit is contained in:
2022-12-14 14:14:33 +03:00
parent 09e5342956
commit cdb02fc9be
278 changed files with 15371 additions and 12176 deletions

View File

@@ -1,64 +1,64 @@
/*
QGLView
Ivan Pelipenko peri4ko@yandex.ru
QGLView
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qglview.h"
#include <qad_types.h>
#include <QApplication>
#include <QKeyEvent>
#include <qad_types.h>
QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) {
// setFrameShape(QFrame::NoFrame);
// setViewportUpdateMode(FullViewportUpdate);
// setCacheMode(CacheNone);
// setMouseTracking(true);
// setFocusPolicy(Qt::WheelFocus);
// setScene(new QGraphicsScene());
// setInteractive(true);
// setFrameShape(QFrame::NoFrame);
// setViewportUpdateMode(FullViewportUpdate);
// setCacheMode(CacheNone);
// setMouseTracking(true);
// setFocusPolicy(Qt::WheelFocus);
// setScene(new QGraphicsScene());
// setInteractive(true);
setIcon(QIcon("://icons/qglview.png"));
deleting_ = false;
timer = 0;
deleting_ = false;
timer = 0;
need_init_ = is_first_draw = true;
objects_.is_root = true;
objects_.view_ = this;
backColor_ = Qt::darkGray;
hoverHaloColor_ = QColor(195, 140, 255, 96);
selectionHaloColor_ = QColor(175, 255, 140);
ambientColor_ = QColor(10, 10, 10);
lastPos = QPoint(-1, -1);
lineWidth_ = 1.;
max_anisotropic = 1;
max_texture_chanels = 8;
objects_.is_root = true;
objects_.view_ = this;
backColor_ = Qt::darkGray;
hoverHaloColor_ = QColor(195, 140, 255, 96);
selectionHaloColor_ = QColor(175, 255, 140);
ambientColor_ = QColor(10, 10, 10);
lastPos = QPoint(-1, -1);
lineWidth_ = 1.;
max_anisotropic = 1;
max_texture_chanels = 8;
cameraOrbit_ = lightEnabled_ = true;
shaders_supported = selecting_ = customMouseMove_ = false;
sel_button = Qt::LeftButton;
sel_mod = Qt::NoModifier;
renderer_ = nullptr;
fps_cnt = 0;
sel_button = Qt::LeftButton;
sel_mod = Qt::NoModifier;
renderer_ = nullptr;
fps_cnt = 0;
fps_tm = fps_ = 0.;
sel_obj = hov_obj = nullptr;
fogDensity_ = fogEnd_ = 1.;
fogStart_ = 0.;
fogMode_ = Exp;
hoverHaloFill_ = 0.333f;
selectionHaloFill_ = 0.5f;
//lmode = Simple;
fogStart_ = 0.;
fogMode_ = Exp;
hoverHaloFill_ = 0.333f;
selectionHaloFill_ = 0.5f;
// lmode = Simple;
shader_select = shader_halo = nullptr;
setFeature(qglMSAA, false);
setFeature(qglFXAA, false);
@@ -88,18 +88,18 @@ QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) {
setFeature(qglDepthOfFieldFocus, 1.);
setFeature(qglDepthOfFieldDiaphragm, 8.);
mouse_first = mouseSelect_ = hoverHalo_ = selectionHalo_ = true;
mouseRotate_ = true;
mouseRotate_ = true;
fogEnabled_ = is_init = grabMouse_ = shaders_bind = changed_ = false;
rmode = GLObjectBase::Fill;
sel_mode = QGLView::SingleSelection;
// sel_pen = QPen(Qt::black, 1, Qt::DashLine);
// sel_brush = QBrush(QColor(170, 100, 255, 120));
rmode = GLObjectBase::Fill;
sel_mode = QGLView::SingleSelection;
// sel_pen = QPen(Qt::black, 1, Qt::DashLine);
// sel_brush = QBrush(QColor(170, 100, 255, 120));
camera()->setAim(QVector3D());
camera()->setPos(QVector3D(2, 2, 2));
camera()->setName("Camera");
addObject(camera());
emit cameraPosChanged(camera()->pos());
//camera().aim_ = camera().pos_;
// camera().aim_ = camera().pos_;
ktm_.restart();
}
@@ -139,9 +139,9 @@ void QGLView::addObject(GLObjectBase * o) {
objects_.addChild(o);
o->setView(this);
collectLights();
QList<GLObjectBase*> cl = o->children(true);
QList<GLObjectBase *> cl = o->children(true);
cl << o;
foreach (GLObjectBase * i, cl) {
foreach(GLObjectBase * i, cl) {
emit objectAdded(i);
}
if (is_init) {
@@ -199,7 +199,7 @@ void QGLView::removeLight(int index) {
void QGLView::removeLight(Light * l) {
foreach (Light * i, lights_)
foreach(Light * i, lights_)
if (i == l) removeObject(i);
lights_.removeAll(l);
}
@@ -207,7 +207,8 @@ void QGLView::removeLight(Light * l) {
void QGLView::clearLights(bool deleteAll) {
if (deleteAll)
foreach (Light * i, lights_) delete i;
foreach(Light * i, lights_)
delete i;
lights_.clear();
}
@@ -228,7 +229,7 @@ Light * QGLView::light(int index) {
Light * QGLView::light(const QString & name) {
foreach (Light * i, lights_)
foreach(Light * i, lights_)
if (i->name_ == name) return i;
return nullptr;
}
@@ -237,7 +238,7 @@ Light * QGLView::light(const QString & name) {
void QGLView::selectObject(GLObjectBase * o) {
if (o == sel_obj) return;
GLObjectBase * pso = sel_obj;
sel_obj = o;
sel_obj = o;
emit selectionChanged(sel_obj, pso);
}
@@ -250,7 +251,7 @@ void QGLView::timerEvent(QTimerEvent *) {
renderNow();
if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return;
Qt::KeyboardModifiers km = QApplication::keyboardModifiers();
foreach (int i, keys_)
foreach(int i, keys_)
emit keyEvent((Qt::Key)i, km);
}
@@ -260,19 +261,19 @@ void QGLView::render() {
resizeGL(width(), height());
QRect g_rect(QPoint(), size());
emit glBeforePaint();
//qDebug() << "paintGL";
//QMutexLocker ml_v(&v_mutex);
// qDebug() << "paintGL";
// QMutexLocker ml_v(&v_mutex);
glEnable(GL_CULL_FACE);
//glDisable(GL_CULL_FACE);
// glDisable(GL_CULL_FACE);
camera()->apply(aspect);
//objects_.preparePos(camera());
// objects_.preparePos(camera());
start_rp.cam_offset_matrix = camera()->offsetMatrix();
start_rp.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX);
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
//objects_.buildTransform();
start_rp.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX);
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
// objects_.buildTransform();
/// Selection detect
//glClearFramebuffer(QColor(100, 0, 0, 0));
// glClearFramebuffer(QColor(100, 0, 0, 0));
if (mouseSelect_) {
glReleaseTextures();
glEnableDepth();
@@ -294,8 +295,8 @@ void QGLView::render() {
if (shaders_supported && shader_select->isLinked()) shader_select->bind();
renderSelection();
if (shaders_supported && shader_select->isLinked()) shader_select->release();
uchar cgid[4] = {0, 0, 0, 0};
uint iid = 0;
uchar cgid[4] = {0, 0, 0, 0};
uint iid = 0;
GLObjectBase * so = nullptr;
if (!g_rect.contains(lastPos)) {
if (hov_obj != nullptr) {
@@ -305,13 +306,13 @@ void QGLView::render() {
} else {
glReadPixels(lastPos.x(), height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid);
iid = uint(cgid[0] << 24) | uint(cgid[1] << 16) | uint(cgid[2] << 8) | cgid[3];
so = ids.value(iid, nullptr);
//qDebug() <<cgid[0]<<cgid[1]<<cgid[2]<<cgid[3]<< iid;
so = ids.value(iid, nullptr);
// qDebug() <<cgid[0]<<cgid[1]<<cgid[2]<<cgid[3]<< iid;
if (so != hov_obj) {
emit hoverChanged(so, hov_obj);
hov_obj = so;
}
//if (so != 0) qDebug() << sel_obj->name() << cgid[3];
// if (so != 0) qDebug() << sel_obj->name() << cgid[3];
}
if (selectionHalo_ && sel_obj) {
fbo_selection.setWriteBuffer(2);
@@ -329,9 +330,9 @@ void QGLView::render() {
}
camera()->apply(aspect);
start_rp.cam_offset_matrix = camera()->offsetMatrix();
cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix;
//objects_.preparePos(camera());
start_rp.cam_offset_matrix = camera()->offsetMatrix();
cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix;
// objects_.preparePos(camera());
static GLRendererBase * prev_rend = nullptr;
glShadeModel(GL_SMOOTH);
@@ -355,7 +356,7 @@ void QGLView::render() {
glReleaseTextures();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//glClearFramebuffer(Qt::black, false);
// glClearFramebuffer(Qt::black, false);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_BLEND);
@@ -365,13 +366,13 @@ void QGLView::render() {
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
if (selectionHalo_ && sel_obj) {
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(2));
//qDebug() << "draw sel";
// qDebug() << "draw sel";
glDrawQuad();
}
if (hoverHalo_ && hov_obj) {
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(1));
//qDebug() << "draw hover";
//glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg"));
// qDebug() << "draw hover";
// glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg"));
glDrawQuad();
}
}
@@ -380,11 +381,11 @@ void QGLView::render() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram(0);
//glDisable(GL_BLEND);
//glDisable(GL_LIGHTING);
//glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg"));
//glDrawQuad();
// glDisable(GL_BLEND);
// glDisable(GL_LIGHTING);
// glActiveTexture(GL_TEXTURE0);
// glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg"));
// glDrawQuad();
emit glEndPaint();
@@ -424,14 +425,14 @@ void QGLView::render() {
time.restart();
fps_cnt++;
if (fps_tm < 1000.) return;
fps_ = fps_cnt / fps_tm * 1000.;
fps_tm = 0.;
fps_ = fps_cnt / fps_tm * 1000.;
fps_tm = 0.;
fps_cnt = 0;
}
void QGLView::initialize() {
//initializeOpenGLFunctions();
// initializeOpenGLFunctions();
glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glEnableDepth();
@@ -458,10 +459,10 @@ void QGLView::initialize() {
checkCaps();
shader_select = new QOpenGLShaderProgram(context());
shader_halo = new QOpenGLShaderProgram(context());
shader_halo = new QOpenGLShaderProgram(context());
reloadThisShaders();
is_init = true;
//resizeGL(width(), height());
is_init = true;
// resizeGL(width(), height());
need_init_ = false;
emit glInitializeDone();
}
@@ -478,18 +479,19 @@ void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor
shader_halo->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
shader_halo->setUniformValue("t0", 0);
shader_halo->setUniformValue("dt", QVector2D(1.f / width(), 1.f / height()));
shader_halo->setUniformValue("selected", QVector4D(float((iid >> 24) & 0xFF) / 255.f,
float((iid >> 16) & 0xFF) / 255.f,
float((iid >> 8) & 0xFF) / 255.f,
float( iid & 0xFF) / 255.f));
shader_halo->setUniformValue("selected",
QVector4D(float((iid >> 24) & 0xFF) / 255.f,
float((iid >> 16) & 0xFF) / 255.f,
float((iid >> 8) & 0xFF) / 255.f,
float(iid & 0xFF) / 255.f));
shader_halo->setUniformValue("color", color);
shader_halo->setUniformValue("fill", GLfloat(fill));
//qDebug() << "render halo" << iid << shader_halo->log() << shader_halo->programId();
// qDebug() << "render halo" << iid << shader_halo->log() << shader_halo->programId();
glDisableDepth();
//glClearFramebuffer(color);
// glClearFramebuffer(color);
glDrawQuad(shader_halo);
glDepthMask(GL_TRUE);
//glFlush();
// glFlush();
shader_halo->release();
} else {
glClearFramebuffer(Qt::black, false);
@@ -498,7 +500,7 @@ void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor
void QGLView::renderSelection() {
// cid = 1;
// cid = 1;
ids.clear();
if (shaders_supported) {
if (shader_select) {
@@ -509,7 +511,7 @@ void QGLView::renderSelection() {
}
}
}
//qDebug() << sh_id_loc;
// qDebug() << sh_id_loc;
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
glPushMatrix();
renderSingleSelection(objects_);
@@ -524,32 +526,34 @@ void QGLView::renderSingleSelection(GLObjectBase & o) {
}
if (!o.visible_ || !o.select_) return;
QMatrix4x4 curview = start_rp.view_matrix * start_rp.cam_offset_matrix * o.itransform_;
uint id = qHash((quint64)&o);
uint id = qHash((quint64)&o);
ids.insert(id, &o);
glLineWidth(o.line_width > 0.f ? o.line_width : lineWidth_);
glPointSize(o.line_width > 0.f ? o.line_width : lineWidth_);
if (shaders_supported){
if (shaders_supported) {
if (shader_select) {
if (shader_select->isLinked()) {
setUniformMatrices(shader_select, start_rp.proj_matrix, curview);
shader_select->setUniformValue(sh_id_loc, QVector4D(float((id >> 24) & 0xFF) / 255.f,
float((id >> 16) & 0xFF) / 255.f,
float((id >> 8) & 0xFF) / 255.f,
float(id & 0xFF) / 255.f));
shader_select->setUniformValue(sh_id_loc,
QVector4D(float((id >> 24) & 0xFF) / 255.f,
float((id >> 16) & 0xFF) / 255.f,
float((id >> 8) & 0xFF) / 255.f,
float(id & 0xFF) / 255.f));
}
}
} else {
setGLMatrix(curview);
glColor4f(float((id >> 24) & 0xFF) / 255.f,
float((id >> 16) & 0xFF) / 255.f,
float((id >> 8) & 0xFF) / 255.f,
float(id & 0xFF) / 255.f);
float((id >> 16) & 0xFF) / 255.f,
float((id >> 8) & 0xFF) / 255.f,
float(id & 0xFF) / 255.f);
}
//qDebug() << o.name() << "assign to" << sh_id_loc << cid;
//glColor4f(float((cid >> 24) & 0xFF) / 255.f, float((cid >> 16) & 0xFF) / 255.f, float((cid >> 8) & 0xFF) / 255.f, float(cid & 0xFF) / 255.f);
// ++cid;
// qDebug() << o.name() << "assign to" << sh_id_loc << cid;
// glColor4f(float((cid >> 24) & 0xFF) / 255.f, float((cid >> 16) & 0xFF) / 255.f, float((cid >> 8) & 0xFF) / 255.f, float(cid & 0xFF) /
// 255.f);
// ++cid;
o.draw(nullptr, true);
foreach (GLObjectBase * i, o.children_)
foreach(GLObjectBase * i, o.children_)
renderSingleSelection(*i);
}
@@ -562,7 +566,7 @@ void QGLView::collectLights() {
void QGLView::objectDeleted(GLObjectBase * o) {
if (deleting_) return;
//qDebug() << "del" << o;
// qDebug() << "del" << o;
if (sel_obj == o) selectObject(nullptr);
if (hov_obj == o) hov_obj = nullptr;
collectLights();
@@ -571,23 +575,23 @@ void QGLView::objectDeleted(GLObjectBase * o) {
void QGLView::collectObjectLights(GLObjectBase * o) {
if (o->type_ == GLObjectBase::glLight) {
lights_ << globject_cast<Light * >(o);
lights_ << globject_cast<Light *>(o);
o->view_ = this;
}
foreach (GLObjectBase * i, o->children())
foreach(GLObjectBase * i, o->children())
collectObjectLights(i);
}
void QGLView::objectsCountInternal(int * cnt, GLObjectBase * where) {
++(*cnt);
foreach (GLObjectBase * i, where->children_)
foreach(GLObjectBase * i, where->children_)
objectsCountInternal(cnt, i);
}
void QGLView::removeObjectInternal(GLObjectBase * o, GLObjectBase * where) {
foreach (GLObjectBase * i, where->children_) {
foreach(GLObjectBase * i, where->children_) {
if (o == i)
where->removeChild(i);
else
@@ -599,9 +603,9 @@ void QGLView::removeObjectInternal(GLObjectBase * o, GLObjectBase * where) {
void QGLView::checkCaps() {
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropic);
//glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels);
//qDebug() << max_texture_chanels;
//qDebug() << max_texture_chanels;
// glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels);
// qDebug() << max_texture_chanels;
// qDebug() << max_texture_chanels;
shaders_supported = QOpenGLShaderProgram::hasOpenGLShaderPrograms();
}
@@ -610,7 +614,7 @@ void QGLView::reloadThisShaders() {
if (!shaders_supported) return;
loadShaders(shader_select, "selection", "://shaders");
loadShaders(shader_halo, "selection_halo", "://shaders");
//loadShaders(shader_rope, "rope", "://shaders");
// loadShaders(shader_rope, "rope", "://shaders");
}
void QGLView::glReleaseTextures(int channels) {
@@ -634,7 +638,8 @@ void QGLView::applyFog() {
fog_col[1] = fogColor_.greenF();
fog_col[2] = fogColor_.blueF();
glFogfv(GL_FOG_COLOR, fog_col);
} else glDisable(GL_FOG);
} else
glDisable(GL_FOG);
}
@@ -643,10 +648,10 @@ void QGLView::resizeGL(int width, int height) {
if (width <= 0 || height <= 0) return;
if (prev_size == QSize(width, height)) return;
prev_size = QSize(width, height);
aspect = float(width) / float(height);
aspect = float(width) / float(height);
if (renderer_) renderer_->resize(width, height);
mouse_first = true;
//qDebug() << "resize" << width << height;
// qDebug() << "resize" << width << height;
fbo_selection.resize(width, height);
iaspect = (aspect == 0.f) ? 0. : 1 / aspect;
glViewport(0, 0, width, height);
@@ -655,14 +660,13 @@ void QGLView::resizeGL(int width, int height) {
void QGLView::mouseReleaseEvent(QMouseEvent * e) {
// qDebug() << "mouseReleaseEvent" << e << isActive();
// QGraphicsView::mouseReleaseEvent(e);
//setCursor(QCursor(Qt::ArrowCursor));
// qDebug() << "mouseReleaseEvent" << e << isActive();
// QGraphicsView::mouseReleaseEvent(e);
// setCursor(QCursor(Qt::ArrowCursor));
selecting_ = false;
if (mouseSelect_ && e->button() == Qt::LeftButton) {
if ((lastPos - downPos).manhattanLength() < 8) {
if (sel_obj != hov_obj)
selectObject(hov_obj);
if (sel_obj != hov_obj) selectObject(hov_obj);
}
}
emit glMouseReleaseEvent(e);
@@ -670,38 +674,38 @@ void QGLView::mouseReleaseEvent(QMouseEvent * e) {
void QGLView::mousePressEvent(QMouseEvent * e) {
// qDebug() << "mousePressEvent" << e << isActive();
// QGraphicsView::mousePressEvent(e);
// mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) , QTransform() ) == 0);
// qDebug() << "mousePressEvent" << e << isActive();
// QGraphicsView::mousePressEvent(e);
// mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) , QTransform() ) == 0);
selecting_ = false;
if (!QRect(QPoint(), size()).contains(e->pos())) return;
/// TODO select by rect
//if (e->button() == sel_button && e->modifiers() == sel_mod)
// if (e->button() == sel_button && e->modifiers() == sel_mod)
// selecting_ = true;
lastPos = e->pos();
downPos = lastPos;
//qDebug() << mouseThis_;
// qDebug() << mouseThis_;
emit glMousePressEvent(e);
}
void QGLView::mouseMoveEvent(QMouseEvent * e) {
// qDebug() << "mouseMoveEvent" << e << isActive();
// QGraphicsView::mouseMoveEvent(e);
//lastPos = e->pos();
// qDebug() << "mouseMoveEvent" << e << isActive();
// QGraphicsView::mouseMoveEvent(e);
// lastPos = e->pos();
if (selecting_) {
return;
}
// if (!QRect(QPoint(), size()).contains(e->pos())) return;
//if (scene()->itemAt(mapToScene(e->pos())) != 0) return;
///qDebug() << e->x() << e->y();
// if (!QRect(QPoint(), size()).contains(e->pos())) return;
// if (scene()->itemAt(mapToScene(e->pos())) != 0) return;
/// qDebug() << e->x() << e->y();
QRect g_rect(QPoint(), size());
if (mouseRotate_) {
float dx = e->x() - lastPos.x();
float dy = e->y() - lastPos.y();
if (e->buttons() & Qt::LeftButton) {
//camera().angle_z += dx / 4.;
//camera().angle_xy += dy / 4.;
// camera().angle_z += dx / 4.;
// camera().angle_xy += dy / 4.;
if (cameraOrbit_) {
camera()->orbitZ(dx / 4.f);
camera()->orbitXY(dy / 4.f);
@@ -714,16 +718,16 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
float ad = camera()->distance();
camera()->moveLeft(dx / 1000.f * ad);
camera()->moveUp(dy / 1000.f * ad);
//camera().pos.setX(camera().pos.x() + camera().pos.z() * dx / 500.);
//camera().pos.setY(camera().pos.y() - camera().pos.z() * dy / 500.);
// camera().pos.setX(camera().pos.x() + camera().pos.z() * dx / 500.);
// camera().pos.setY(camera().pos.y() - camera().pos.z() * dy / 500.);
emit cameraPosChanged(camera()->pos());
}
//lights[0]->pos_ = camera().pos();
// lights[0]->pos_ = camera().pos();
}
if (customMouseMove_) emit customMouseMoveEvent(e->pos(), lastPos, e->buttons());
lastPos = e->pos();
if (grabMouse_) {
//if (!isrunning) return;
// if (!isrunning) return;
QCursor::setPos(mapToGlobal(QRect(QPoint(), size()).center()));
static bool mouse_sec = false;
if (mouse_sec) {
@@ -732,13 +736,13 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
}
if (mouse_first) {
mouse_first = false;
mouse_sec = true;
//qDebug() << "first" << e->pos();
mouse_sec = true;
// qDebug() << "first" << e->pos();
return;
}
lastPos = g_rect.center();
int dx = e->x() - lastPos.x();
int dy = e->y() - lastPos.y();
int dx = e->x() - lastPos.x();
int dy = e->y() - lastPos.y();
emit glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers()));
return;
}
@@ -750,21 +754,21 @@ void QGLView::wheelEvent(QWheelEvent * e) {
if (mouseRotate_) {
double ang =
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
e->delta();
e->delta();
#else
e->angleDelta().y();
e->angleDelta().y();
#endif
if (ang > 0) camera()->flyCloser(0.1f); //camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z());
if (ang < 0) camera()->flyFarer(0.1f); //camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z());
if (ang > 0) camera()->flyCloser(0.1f); // camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z());
if (ang < 0) camera()->flyFarer(0.1f); // camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z());
emit cameraPosChanged(camera()->pos());
}
emit glWheelEvent(e);
}
void QGLView::leaveEvent(QEvent * ) {
void QGLView::leaveEvent(QEvent *) {
lastPos = QPoint(-1, -1);
//qDebug() << lastPos;
// qDebug() << lastPos;
}
@@ -789,8 +793,7 @@ void QGLView::focusOutEvent(QFocusEvent *) {
void QGLView::mouseDoubleClickEvent(QMouseEvent * e) {
if (e->buttons().testFlag(QT_MID_BUTTON))
emit doubleClick();
if (e->buttons().testFlag(QT_MID_BUTTON)) emit doubleClick();
}
@@ -811,7 +814,7 @@ QByteArray QGLView::saveCamera() {
}
void QGLView::restoreCamera(const QByteArray &ba) {
void QGLView::restoreCamera(const QByteArray & ba) {
if (ba.isEmpty()) return;
ChunkStream cs(ba);
QVector3D pos, aim, ang;
@@ -850,4 +853,3 @@ void QGLView::restoreFeatures(const QByteArray & ba) {
ds >> f;
features_ = f;
}