git-svn-id: svn://db.shs.com.ru/libs@627 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -41,13 +41,23 @@ RendererService::RendererService(Renderer * r_): r(r_) {
|
||||
QMatrix4x4 m; m.rotate(90., _rot[i]);
|
||||
m.transposed().copyDataTo(axis_objects[i].modelmatrix);
|
||||
}
|
||||
box_vp_scale = 1.;
|
||||
box_mesh = Primitive::cube();
|
||||
box_vp_scale = box_full_scale = 1.;
|
||||
box_mesh = Primitive::cube();
|
||||
box_mesh_f = Primitive::cubeFrame();
|
||||
omni_mesh = Primitive::ellipsoid(2, 1);
|
||||
omni_mesh_f = Primitive::ellipsoidFrame(2, 1);
|
||||
omni_mesh ->scalePoints(1.5);
|
||||
omni_mesh_f->scalePoints(1.5);
|
||||
box_mesh ->scalePoints(1.3);
|
||||
omni_mesh ->scalePoints(1.3);
|
||||
}
|
||||
|
||||
|
||||
RendererService::~RendererService() {
|
||||
delete box_mesh;
|
||||
delete box_mesh_f;
|
||||
delete omni_mesh;
|
||||
delete omni_mesh_f;
|
||||
delete axis_camera;
|
||||
delete axis_mesh;
|
||||
}
|
||||
@@ -62,25 +72,26 @@ void RendererService::init(int width, int 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);
|
||||
box_vp_scale = 25. * appScale() / qMax(qMin(width, height), 1);
|
||||
//qDebug() << axis_viewport;
|
||||
}
|
||||
|
||||
|
||||
void RendererService::fillBoxObjects() {
|
||||
box_objects.clear();
|
||||
void RendererService::fillOmniObjects() {
|
||||
cur_objects.clear();
|
||||
Object o;
|
||||
QList<Light*> 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;
|
||||
box_full_scale = 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();
|
||||
QMatrix4x4 lmat;
|
||||
lmat.translate(lpos.toVector3D());
|
||||
lmat.scale(dist * vps);
|
||||
lmat.scale(dist * box_full_scale);
|
||||
lmat.transposed().copyDataTo(o.modelmatrix);
|
||||
box_objects << o;
|
||||
o.object_id = l->id_;
|
||||
cur_objects << o;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,32 +106,35 @@ void RendererService::setObjectsColor(QVector<Object> & ol, QColor col) {
|
||||
void RendererService::renderService() {
|
||||
QOpenGLShaderProgram * prog = 0;
|
||||
QOpenGLExtraFunctions * f = r->view;
|
||||
if (r->bindShader(Renderer::srService, &prog)) {
|
||||
f->glEnable(GL_MULTISAMPLE);
|
||||
glEnableDepth();
|
||||
f->glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glEnableDepth();
|
||||
|
||||
f->glEnable(GL_MULTISAMPLE);
|
||||
glEnableDepth();
|
||||
f->glClear(GL_DEPTH_BUFFER_BIT);
|
||||
if (r->bindShader(Renderer::srServiceFrame, &prog)) {
|
||||
prog->setUniformValue("qgl_ProjMatrix", r->view->camera()->projectionMatrix(r->view->aspect));
|
||||
|
||||
/// lights
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glDisable(GL_CULL_FACE);
|
||||
r->setUniformCamera(prog, r->view->camera());
|
||||
fillBoxObjects();
|
||||
fillOmniObjects();
|
||||
|
||||
setObjectsColor(box_objects, Qt::white);
|
||||
glLineWidth(line_width*3);
|
||||
box_mesh->loadObjects(f, box_objects);
|
||||
box_mesh->draw(f, box_objects.size());
|
||||
setObjectsColor(cur_objects, Qt::white);
|
||||
prog->setUniformValue("line_width", 2.f);
|
||||
prog->setUniformValue("z_offset", 0.f);
|
||||
omni_mesh_f->loadObjects(f, cur_objects);
|
||||
omni_mesh_f->draw(f, cur_objects.size());
|
||||
|
||||
setObjectsColor(box_objects, Qt::black);
|
||||
glLineWidth(line_width);
|
||||
box_mesh->loadObjects(f, box_objects);
|
||||
box_mesh->draw(f, box_objects.size());
|
||||
setObjectsColor(cur_objects, Qt::black);
|
||||
prog->setUniformValue("line_width", 1.f);
|
||||
prog->setUniformValue("z_offset", -1.E-3f);
|
||||
omni_mesh_f->loadObjects(f, cur_objects);
|
||||
omni_mesh_f->draw(f, cur_objects.size());
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
}
|
||||
if (r->bindShader(Renderer::srServiceFill, &prog)) {
|
||||
|
||||
/// axis
|
||||
f->glViewport(0, 0, axis_viewport.width(), axis_viewport.height());
|
||||
@@ -130,7 +144,6 @@ void RendererService::renderService() {
|
||||
axis_mesh->draw(f, axis_objects.size());
|
||||
f->glViewport(0, 0, r->view->width(), r->view->height());
|
||||
|
||||
|
||||
f->glDisable(GL_MULTISAMPLE);
|
||||
}
|
||||
f->glDisable(GL_MULTISAMPLE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user