]> git.sur5r.net Git - fstl/blobdiff - src/canvas.cpp
Made models non-mirrored
[fstl] / src / canvas.cpp
index 290885b6e32457c9e4044d72681094f8a680b581..bfbc3c03686a18ec26e802a0bf89864fc1e20e5e 100644 (file)
@@ -1,6 +1,8 @@
 #include <QMouseEvent>
 #include <QDebug>
 
+#include <cmath>
+
 #include "canvas.h"
 #include "backdrop.h"
 #include "glmesh.h"
@@ -28,12 +30,17 @@ void Canvas::load_mesh(Mesh* m)
                 pow(m->xmax() - m->xmin(), 2) +
                 pow(m->ymax() - m->ymin(), 2) +
                 pow(m->zmax() - m->zmin(), 2));
-
     update();
 
     delete m;
 }
 
+void Canvas::set_status(const QString &s)
+{
+    status = s;
+    update();
+}
+
 void Canvas::initializeGL()
 {
     mesh_shader.addShaderFromSourceFile(QGLShader::Vertex, ":/gl/mesh.vert");
@@ -41,19 +48,26 @@ void Canvas::initializeGL()
     mesh_shader.link();
 
     backdrop = new Backdrop();
-
-    glClearColor(0.0, 0.0, 0.0, 0.0);
-    glEnable(GL_DEPTH_TEST);
 }
 
-void Canvas::paintGL()
+void Canvas::paintEvent(QPaintEvent *event)
 {
+    Q_UNUSED(event);
+
+    glClearColor(0.0, 0.0, 0.0, 0.0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+    glEnable(GL_DEPTH_TEST);
 
     backdrop->draw();
     if (mesh)  draw_mesh();
+
+    QPainter painter(this);
+    painter.setRenderHint(QPainter::Antialiasing);
+    if (!status.isNull())
+        painter.drawText(10, height() - 10, status);
 }
 
+
 void Canvas::draw_mesh()
 {
     mesh_shader.bind();
@@ -93,11 +107,11 @@ QMatrix4x4 Canvas::view_matrix() const
     QMatrix4x4 m;
     if (width() > height())
     {
-        m.scale(height() / float(width()), 1, 0.5);
+        m.scale(-height() / float(width()), 1, 0.5);
     }
     else
     {
-        m.scale(1, width() / float(height()), 0.5);
+        m.scale(-1, width() / float(height()), 0.5);
     }
     return m;
 }
@@ -125,7 +139,7 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
     {
         auto p = event->pos();
         auto d = p - mouse_pos;
-        yaw = fmod(yaw + d.x(), 360);
+        yaw = fmod(yaw - d.x(), 360);
         tilt = fmax(0, fmin(180, tilt - d.y()));
         mouse_pos = p;
         update();