From 7884446da166ac397e0031b569937c9c27228235 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 17 Apr 2020 00:25:21 +0200 Subject: [PATCH] Orientation cube, some refinement. --- .../tools/view_25d/lay_plugin/D25View.ui | 20 ++- .../tools/view_25d/lay_plugin/layD25Camera.h | 2 +- .../tools/view_25d/lay_plugin/layD25View.cc | 27 ++++ .../tools/view_25d/lay_plugin/layD25View.h | 2 + .../view_25d/lay_plugin/layD25ViewWidget.cc | 123 +++++++++++++++++- .../view_25d/lay_plugin/layD25ViewWidget.h | 5 +- 6 files changed, 173 insertions(+), 6 deletions(-) diff --git a/src/plugins/tools/view_25d/lay_plugin/D25View.ui b/src/plugins/tools/view_25d/lay_plugin/D25View.ui index efdbd6365..f09a1a654 100644 --- a/src/plugins/tools/view_25d/lay_plugin/D25View.ui +++ b/src/plugins/tools/view_25d/lay_plugin/D25View.ui @@ -61,6 +61,24 @@ + + + 0 + 0 + + + + + 150 + 16777215 + + + + -300 + + + 300 + Qt::Horizontal @@ -91,7 +109,7 @@ Qt::Horizontal - QSizePolicy::Fixed + QSizePolicy::Expanding diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25Camera.h b/src/plugins/tools/view_25d/lay_plugin/layD25Camera.h index 22dd780e4..06680ef47 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25Camera.h +++ b/src/plugins/tools/view_25d/lay_plugin/layD25Camera.h @@ -105,7 +105,7 @@ public: /** * @brief Gets the azimuth angle - * ... + * A positive angle means we look from the left. A negative means we look from the right. */ double cam_azimuth () const; diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25View.cc b/src/plugins/tools/view_25d/lay_plugin/layD25View.cc index aa6c587a4..158e19f3f 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25View.cc +++ b/src/plugins/tools/view_25d/lay_plugin/layD25View.cc @@ -50,6 +50,8 @@ D25View::D25View (QWidget *parent) connect (mp_ui->fit_right, SIGNAL (clicked ()), this, SLOT (fit_button_clicked ())); connect (mp_ui->fit_top, SIGNAL (clicked ()), this, SLOT (fit_button_clicked ())); connect (mp_ui->fit_bottom, SIGNAL (clicked ()), this, SLOT (fit_button_clicked ())); + connect (mp_ui->zoom_slider, SIGNAL (valueChanged (int)), this, SLOT (scale_slider_changed (int))); + connect (mp_ui->d25_view, SIGNAL (scale_factor_changed (double)), this, SLOT (scale_factor_changed (double))); } D25View::~D25View () @@ -58,6 +60,31 @@ D25View::~D25View () mp_ui = 0; } +static QString scale_factor_to_string (double f) +{ + QString s; + s.sprintf ("x %.3g", f); + return s; +} + +void +D25View::scale_slider_changed (int value) +{ + double f = exp (log (10.0) * -0.01 * value); + mp_ui->zoom_factor->setText (scale_factor_to_string (f)); + mp_ui->d25_view->set_scale_factor (f); +} + +void +D25View::scale_factor_changed (double f) +{ + mp_ui->zoom_factor->setText (scale_factor_to_string (f)); + int v = floor (0.5 - log10 (f) * 100.0); + mp_ui->zoom_slider->blockSignals (true); + mp_ui->zoom_slider->setValue (v); + mp_ui->zoom_slider->blockSignals (false); +} + int D25View::exec_dialog (lay::LayoutView *view) { diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25View.h b/src/plugins/tools/view_25d/lay_plugin/layD25View.h index 207ca7751..6f776ed3c 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25View.h +++ b/src/plugins/tools/view_25d/lay_plugin/layD25View.h @@ -56,6 +56,8 @@ protected: private slots: void fit_button_clicked (); + void scale_factor_changed (double f); + void scale_slider_changed (int value); private: Ui::D25View *mp_ui; diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.cc b/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.cc index 1a077e786..48ca09105 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.cc +++ b/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.cc @@ -240,6 +240,8 @@ D25ViewWidget::wheelEvent (QWheelEvent *event) m_scale_factor *= f; m_displacement += hp * (1.0 - f) / m_scale_factor; + emit scale_factor_changed (m_scale_factor); + } else { // compute vector of line of sight @@ -248,16 +250,16 @@ D25ViewWidget::wheelEvent (QWheelEvent *event) // by definition the ray goes through the camera position QVector3D hp = hit_point_with_scene (ray.second); - if (event->modifiers () & Qt::ControlModifier) { + if (! (event->modifiers () & Qt::ControlModifier)) { - // "Ctrl" is closeup + // No Ctrl is closeup double f = event->angleDelta ().y () * (1.0 / (90 * 8)); m_displacement += -((f / m_scale_factor) * std::min (cam_dist (), double ((cam_position () - hp).length ()))) * ray.second; } else { - // No shift is zoom + // "Ctrl" is zoom double f = exp (event->angleDelta ().y () * (1.0 / (90 * 8))); @@ -277,6 +279,8 @@ D25ViewWidget::wheelEvent (QWheelEvent *event) m_displacement = ct.inverted ().map (displacement); + emit scale_factor_changed (m_scale_factor); + } } @@ -382,6 +386,8 @@ D25ViewWidget::fit () m_displacement = (new_center_in_scene - dim * 0.5) / m_scale_factor - bll; refresh (); + + emit scale_factor_changed (m_scale_factor); } void @@ -905,6 +911,117 @@ D25ViewWidget::paintGL () vertexes.draw_to (this, positions, GL_TRIANGLES); + // the orientation cube + + if (! top_view ()) { + + glDisable (GL_DEPTH_TEST); + + int cube_size = 64; + int cube_margin = 20; + + QMatrix4x4 into_top_right_corner; + into_top_right_corner.translate (1.0 - 2.0 / width () * (cube_margin + cube_size / 2), 1.0 - 2.0 / height () * (cube_margin + cube_size / 2)); + // into_top_right_corner.translate (0.5, 0.5, 0.0); + into_top_right_corner.scale (2.0 * cube_size / double (height ()), 2.0 * cube_size / double (height ()), 1.0); + + m_gridplane_program->setUniformValue ("matrix", into_top_right_corner * cam_perspective () * cam_trans ()); + + vertexes.clear (); + + vertexes.add (-1.0, -1.0, 1.0); + vertexes.add (-1.0, -1.0, -1.0); + + vertexes.add (-1.0, 1.0, 1.0); + vertexes.add (-1.0, 1.0, -1.0); + + vertexes.add (1.0, -1.0, 1.0); + vertexes.add (1.0, -1.0, -1.0); + + vertexes.add (1.0, 1.0, 1.0); + vertexes.add (1.0, 1.0, -1.0); + + vertexes.add (-1.0, -1.0, 1.0); + vertexes.add (-1.0, 1.0, 1.0); + + vertexes.add (1.0, -1.0, 1.0); + vertexes.add (1.0, 1.0, 1.0); + + vertexes.add (-1.0, -1.0, 1.0); + vertexes.add (1.0, -1.0, 1.0); + + vertexes.add (-1.0, 1.0, 1.0); + vertexes.add (1.0, 1.0, 1.0); + + vertexes.add (-1.0, -1.0, -1.0); + vertexes.add (-1.0, 1.0, -1.0); + + vertexes.add (1.0, -1.0, -1.0); + vertexes.add (1.0, 1.0, -1.0); + + vertexes.add (-1.0, -1.0, -1.0); + vertexes.add (1.0, -1.0, -1.0); + + vertexes.add (-1.0, 1.0, -1.0); + vertexes.add (1.0, 1.0, -1.0); + + m_gridplane_program->setUniformValue ("color", 1.0, 1.0, 1.0, 0.2f); + + vertexes.draw_to (this, positions, GL_LINES); + + vertexes.clear (); + + // A "K" at the front + vertexes.add (-0.8, -0.8, 1.0); + vertexes.add (-0.8, 0.8, 1.0); + vertexes.add (-0.2, 0.8, 1.0); + + vertexes.add (-0.8, -0.8, 1.0); + vertexes.add (-0.2, -0.8, 1.0); + vertexes.add (-0.2, 0.8, 1.0); + + vertexes.add (0.2, 0.8, 1.0); + vertexes.add (0.8, 0.8, 1.0); + vertexes.add (0.8, 0.6, 1.0); + + vertexes.add (0.2, 0.8, 1.0); + vertexes.add (0.8, 0.6, 1.0); + vertexes.add (0.6, 0.4, 1.0); + + vertexes.add (-0.2, 0.4, 1.0); + vertexes.add (0.2, 0.8, 1.0); + vertexes.add (0.6, 0.4, 1.0); + + vertexes.add (-0.2, 0.4, 1.0); + vertexes.add (0.6, 0.4, 1.0); + vertexes.add (0.2, 0.0, 1.0); + + vertexes.add (-0.2, 0.4, 1.0); + vertexes.add (0.2, 0.0, 1.0); + vertexes.add (-0.2, -0.4, 1.0); + + vertexes.add (-0.2, -0.4, 1.0); + vertexes.add (0.6, -0.4, 1.0); + vertexes.add (0.2, -0.0, 1.0); + + vertexes.add (-0.2, -0.4, 1.0); + vertexes.add (0.2, -0.8, 1.0); + vertexes.add (0.6, -0.4, 1.0); + + vertexes.add (0.2, -0.8, 1.0); + vertexes.add (0.8, -0.6, 1.0); + vertexes.add (0.6, -0.4, 1.0); + + vertexes.add (0.2, -0.8, 1.0); + vertexes.add (0.8, -0.8, 1.0); + vertexes.add (0.8, -0.6, 1.0); + + m_gridplane_program->setUniformValue ("color", 1.0, 1.0, 1.0, 0.3f); + + vertexes.draw_to (this, positions, GL_TRIANGLES); + + } + glDisableVertexAttribArray (positions); m_shapes_program->release (); diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.h b/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.h index 36f8d59b8..ea6d5c790 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.h +++ b/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.h @@ -104,6 +104,9 @@ public: refresh (); } +signals: + void scale_factor_changed (double f); + protected: virtual void camera_changed (); virtual double aspect_ratio () const; @@ -112,7 +115,7 @@ public slots: void fit (); private: - typedef lay::mem_chunks chunks_type; + typedef lay::mem_chunks chunks_type; std::auto_ptr mp_mode; QOpenGLShaderProgram *m_shapes_program, *m_gridplane_program;