From 83cf7e041a8356770435552b3028707b64b37f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Fri, 19 Jul 2019 16:11:11 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@578 a8b55f48-bf90-11e4-a774-851b48703e85 --- qglview/glprimitives.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ qglview/glprimitives.h | 8 ++++++++ qglview/glwidget.cpp | 7 ++++++- qglview/glwidget.h | 3 +++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/qglview/glprimitives.cpp b/qglview/glprimitives.cpp index f87c887..7d307db 100644 --- a/qglview/glprimitives.cpp +++ b/qglview/glprimitives.cpp @@ -175,3 +175,46 @@ void GLPrimitiveEllipsoid::init() { is_init = true; vbo.rebuffer(); } + + +void GLPrimitiveAxis::draw(QOpenGLShaderProgram * prog, bool simplest) { + float bs = 1.f; + float as = 0.1f; + float aw = 0.07f; + float cr_x = 0.8f, cg_y = 0.75f, cb_z = 0.8f; + glBegin(GL_LINES); + glColor3f(cr_x, 0, 0); + glVertex3f(-bs, 0, 0); + glVertex3f(bs, 0, 0); + glVertex3f(bs, 0, 0); + glVertex3f(bs-as, aw, 0); + glVertex3f(bs, 0, 0); + glVertex3f(bs-as, -aw, 0); + glVertex3f(bs, 0, 0); + glVertex3f(bs-as, 0, aw); + glVertex3f(bs, 0, 0); + glVertex3f(bs-as, 0, -aw); + glColor3f(0, cg_y, 0); + glVertex3f(0, -bs, 0); + glVertex3f(0, bs, 0); + glVertex3f(0, bs, 0); + glVertex3f(0, bs-as, aw); + glVertex3f(0, bs, 0); + glVertex3f(0, bs-as, -aw); + glVertex3f(0, bs, 0); + glVertex3f(aw, bs-as, 0); + glVertex3f(0, bs, 0); + glVertex3f(-aw, bs-as, 0); + glColor3f(0, 0, cb_z); + glVertex3f(0, 0, -bs); + glVertex3f(0, 0, bs); + glVertex3f(0, 0, bs); + glVertex3f(aw, 0, bs-as); + glVertex3f(0, 0, bs); + glVertex3f(-aw, 0, bs-as); + glVertex3f(0, 0, bs); + glVertex3f(0, aw, bs-as); + glVertex3f(0, 0, bs); + glVertex3f(0, -aw, bs-as); + glEnd(); +} diff --git a/qglview/glprimitives.h b/qglview/glprimitives.h index bdacff0..ad3e8f1 100644 --- a/qglview/glprimitives.h +++ b/qglview/glprimitives.h @@ -74,4 +74,12 @@ private: }; +class GLPrimitiveAxis: public GLObjectBase +{ +public: + GLPrimitiveAxis() {accept_fog = accept_light = cast_shadow = rec_shadow = select_ = false;} + virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false); +}; + + #endif // GLPRIMITIVE_CUBE_H diff --git a/qglview/glwidget.cpp b/qglview/glwidget.cpp index 17d99c4..ab09a45 100644 --- a/qglview/glwidget.cpp +++ b/qglview/glwidget.cpp @@ -104,6 +104,11 @@ qreal GLWidget::selectionHaloFillAlpha() const { } +void GLWidget::addObject(GLObjectBase * o) { + view_->addObject(o); +} + + void GLWidget::stop() { view_->stop(); } @@ -113,7 +118,7 @@ void GLWidget::start(float freq, GLRendererBase * r) { if (r == nullptr) r = new RendererSimple(view_); GLRendererBase * pr = nullptr; view_->setRenderer(r, &pr); - if (pr != nullptr) delete pr; + if (pr != nullptr && pr != r) delete pr; view_->start(freq); } diff --git a/qglview/glwidget.h b/qglview/glwidget.h index 2ab2550..04a0ae6 100644 --- a/qglview/glwidget.h +++ b/qglview/glwidget.h @@ -6,6 +6,7 @@ class QGLView; class GLRendererBase; +class GLObjectBase; class GLWidget : public QWidget { @@ -48,6 +49,8 @@ public: QColor selectionHaloColor() const; qreal selectionHaloFillAlpha() const; + void addObject(GLObjectBase * o); + public slots: void stop(); void start(float freq = 60.0, GLRendererBase * r = nullptr);