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

100 lines
2.1 KiB
C
Raw Normal View History

#pragma once
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QMatrix4x4>
#include "GeometryEngine.h"
#include "SettingsWindow.h"
#include "CameraInterface.h"
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();
// attributes
2016-12-29 13:06:25 +00:00
private:
QOpenGLShaderProgram m_program;
GeometryEngine *m_dataEngine;
2016-12-29 13:06:25 +00:00
2017-02-08 13:29:22 +00:00
QVector4D m_backgroundColorOn;
QVector4D m_backgroundColorOff;
2017-02-08 13:29:22 +00:00
bool m_wireframe;
bool m_lightOn;
bool m_backfaceCulling;
struct {
2017-02-08 13:29:22 +00:00
QVector4D position;
QVector3D intensities;
float attenuationFactor;
float ambientCoefficient;
bool headlight;
} m_light;
struct {
bool left = false;
bool right = false;
QVector2D position;
} m_mouse;
2017-01-20 15:39:17 +00:00
2016-12-29 13:06:25 +00:00
QMatrix4x4 m_projection;
CameraInterface* m_camera;
2016-12-29 13:06:25 +00:00
SettingsWindow* m_settings;
// functions
private:
2017-02-08 13:29:22 +00:00
void setDefaultValues();
void initShaders();
void resetView();
void updateLightPosition();
protected:
void initializeGL() Q_DECL_OVERRIDE;
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
void paintGL() Q_DECL_OVERRIDE;
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;
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
2017-02-05 11:34:24 +00:00
void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
2017-01-05 15:04:51 +00:00
// slots
2017-01-05 15:04:51 +00:00
public slots:
void loadFile(QString name);
void useFreeCamera();
void useOrbitCamera();
void useMoveCamera();
void toggleWireframe();
void toggleLight();
void showSettings();
void setBGColorOff(QVector3D value);
void setBGColorOn(QVector3D value);
void setLightColor(QVector3D value);
void setAttFac(double value);
void setAmbCoef(double value);
void setHeadlight(bool value);
void setBackfaceCulling(bool value);
2017-02-08 13:29:22 +00:00
// signals
signals:
void lightChanged(bool value);
};