/*
QGLView
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#define GL_GLEXT_PROTOTYPES
#include
#include "renderer_service.h"
#include "renderer.h"
#include "qglview.h"
#include "glmesh.h"
#include
using namespace QGLEngineShaders;
RendererService::RendererService(Renderer * r_): r(r_) {
line_width = 1;
axis_camera = new Camera();
axis_camera->setAim(QVector3D());
axis_camera->setFOV(45.);
axis_mesh = Primitive::arrow(12);
axis_objects.resize(3);
const QVector3D _rot[3] = {QVector3D(0,1,0), QVector3D(-1,0,0), QVector3D(0,0,1)};
for (int i = 0; i < 3; ++i) {
axis_objects[i].color = QVector4D(0,0,0,1);
axis_objects[i].color[i] = 1.;
QMatrix4x4 m; m.rotate(90., _rot[i]);
m.transposed().copyDataTo(axis_objects[i].modelmatrix);
}
box_vp_scale = 1.;
box_mesh = Primitive::cube();
}
RendererService::~RendererService() {
delete box_mesh;
delete axis_camera;
delete axis_mesh;
}
void RendererService::init(int width, int height) {
axis_mesh->loadObjects(r->view, axis_objects);
resize(width, height);
}
void RendererService::resize(int width, int height) {
axis_viewport = preferredIconSize(10.);
line_width = lineThickness();
box_vp_scale = 30. * appScale() / qMax(qMin(width, height), 1);
//qDebug() << axis_viewport;
}
void RendererService::fillBoxObjects() {
box_objects.clear();
Object o;
QList ll = r->view->scene()->lights_used;
QMatrix4x4 v_mat = r->view->camera()->viewMatrix() * r->view->camera()->offsetMatrix();
QMatrix4x4 lmat;
double vps = tan(r->view->camera()->FOV() / 2. * deg2rad) * box_vp_scale;
foreach (Light * l, ll) {
QVector4D lpos = QVector4D(l->worldPos(), 1.);
double dist = -(v_mat * lpos).z();
lmat.translate(lpos.toVector3D());
lmat.scale(dist * vps);
lmat.transposed().copyDataTo(o.modelmatrix);
box_objects << o;
}
}
void RendererService::setObjectsColor(QVector