SWBF2-Classic-Msh-Viewer/QtMeshViewer/Header/OglViewerWidget.h

86 lines
1.7 KiB
C
Raw Normal View History

#pragma once
#include "geometryengine.h"
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QVector2D>
#include <QBasicTimer>
#include <QOpenGLShaderProgram>
2016-12-29 12:37:15 +00:00
class GeometryEngine;
class OglViewerWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
explicit OglViewerWidget(QWidget *parent = 0);
~OglViewerWidget();
2017-01-03 10:47:27 +00:00
signals:
2017-01-07 14:59:16 +00:00
void loadFile(QString);
2017-01-03 10:47:27 +00:00
2016-12-29 13:06:25 +00:00
private:
struct {
bool left = false;
bool right = false;
QVector2D position;
} m_mouse;
struct {
bool x = true;
bool y = true;
bool z = true;
} m_rotDirections;
struct {
QVector3D position = { 1,1,1 };
QVector3D intensities = { 1,1,1 };
float attenuationFactor = 0.2f;
float ambientCoefficient = 0.005f;
} m_light;
2017-01-20 15:39:17 +00:00
QVector4D m_backgroundColor = {0.5f, 0.8f, 1.0f, 1.0f};
2016-12-29 13:06:25 +00:00
QOpenGLShaderProgram m_program;
GeometryEngine *m_dataEngine;
QMatrix4x4 m_projection;
2016-12-30 12:28:07 +00:00
QVector3D m_translation;
2016-12-29 13:06:25 +00:00
QQuaternion m_rotation;
bool m_wireframe = false;
bool m_lightOn = false;
protected:
void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
2016-12-30 12:28:07 +00:00
void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
2017-01-03 10:47:27 +00:00
void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
void initializeGL() Q_DECL_OVERRIDE;
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
void paintGL() Q_DECL_OVERRIDE;
2016-12-29 12:37:15 +00:00
private:
void initShaders();
void setConnections();
void updateLightPosition();
private slots:
void resetView();
2017-01-05 15:04:51 +00:00
public slots:
void changeDirection(int direction);
void toggleWireframe();
void toggleLight();
};