diff options
author | ccolin | 2020-12-22 16:35:25 +0100 |
---|---|---|
committer | ccolin | 2020-12-22 16:35:25 +0100 |
commit | f20a0f978d4b443a5784c496969f338996d85ca2 (patch) | |
tree | 4ce5b40ea6cd57b4cd654273f54ea02ef3a4705b /src/opengl_widget.cc | |
parent | 89a3f9c4020bea4b4f85f32bdc6a2af13ccd5da0 (diff) |
drone models (broken) and animation
Diffstat (limited to 'src/opengl_widget.cc')
-rw-r--r-- | src/opengl_widget.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc index 0251491..f10a8c6 100644 --- a/src/opengl_widget.cc +++ b/src/opengl_widget.cc @@ -1,5 +1,7 @@ #include "opengl_widget.hh" +#include <QMouseEvent> + static const GLchar *vertex_shader_source = R"glsl( #version 330 core @@ -135,9 +137,43 @@ void OpenGLWidget::resizeGL(int w, int h) { void OpenGLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + QMatrix4x4 trans; + trans.translate(0, 0, -cam_dist); + QMatrix4x4 view = trans * rot; + glUniformMatrix4fv(view_attr, 1, GL_FALSE, view.data()); for (const OpenGLMesh &mesh : meshes) { glUniformMatrix4fv(model_attr, 1, GL_FALSE, mesh.mat.data()); glBindVertexArray(mesh.vao); glDrawArrays(GL_TRIANGLES, 0, mesh.nverts); } } + + +void OpenGLWidget::mousePressEvent(QMouseEvent *e) { + if (e->button() == Qt::LeftButton) { + mouse_pos = e->pos(); + } +} + + +void OpenGLWidget::mouseReleaseEvent(QMouseEvent *e) { + (void) e; + rot_start = rot; +} + + +void OpenGLWidget::mouseMoveEvent(QMouseEvent *e) { + if (e->buttons() & Qt::LeftButton) { + QPoint delta = e->pos() - mouse_pos; + rot = rot_start; + rot.rotate(delta.x() / 5., 0, 1, 0); + rot.rotate(delta.y() / 5., QVector3D(1, 0, 0) * rot); + update(); + } +} + + +void OpenGLWidget::wheelEvent(QWheelEvent *e) { + cam_dist -= e->angleDelta().y() / 1000. * cam_dist; + update(); +} |