2016-12-24 16:03:37 +01:00
|
|
|
#pragma once
|
|
|
|
#include <QOpenGLWidget>
|
|
|
|
#include <QOpenGLFunctions>
|
|
|
|
#include <QOpenGLShaderProgram>
|
2017-01-28 16:54:36 +01:00
|
|
|
#include <QMatrix4x4>
|
|
|
|
#include "GeometryEngine.h"
|
|
|
|
#include "SettingsWindow.h"
|
2017-02-02 18:01:08 +01:00
|
|
|
#include "CameraInterface.h"
|
2016-12-29 13:37:15 +01:00
|
|
|
|
2016-12-24 16:03:37 +01:00
|
|
|
|
|
|
|
class GeometryEngine;
|
|
|
|
|
|
|
|
class OglViewerWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit OglViewerWidget(QWidget *parent = 0);
|
|
|
|
~OglViewerWidget();
|
|
|
|
|
2017-01-28 16:54:36 +01:00
|
|
|
// attributes
|
2016-12-29 14:06:25 +01:00
|
|
|
private:
|
2017-01-28 16:54:36 +01:00
|
|
|
QOpenGLShaderProgram m_program;
|
|
|
|
GeometryEngine *m_dataEngine;
|
2016-12-29 14:06:25 +01:00
|
|
|
|
2017-02-08 14:29:22 +01:00
|
|
|
QVector4D m_backgroundColorOn;
|
|
|
|
QVector4D m_backgroundColorOff;
|
2017-01-28 16:54:36 +01:00
|
|
|
|
2017-02-08 14:29:22 +01:00
|
|
|
bool m_wireframe;
|
|
|
|
bool m_lightOn;
|
|
|
|
bool m_backfaceCulling;
|
2017-01-07 12:46:06 +01:00
|
|
|
|
2017-01-17 17:48:54 +01:00
|
|
|
struct {
|
2017-02-08 14:29:22 +01:00
|
|
|
QVector4D position;
|
|
|
|
QVector3D intensities;
|
|
|
|
float attenuationFactor;
|
|
|
|
float ambientCoefficient;
|
|
|
|
bool headlight;
|
2017-01-17 17:48:54 +01:00
|
|
|
} m_light;
|
|
|
|
|
2017-01-28 16:54:36 +01:00
|
|
|
struct {
|
|
|
|
bool left = false;
|
|
|
|
bool right = false;
|
|
|
|
QVector2D position;
|
|
|
|
} m_mouse;
|
2017-01-20 16:39:17 +01:00
|
|
|
|
2016-12-29 14:06:25 +01:00
|
|
|
QMatrix4x4 m_projection;
|
2017-02-02 18:01:08 +01:00
|
|
|
CameraInterface* m_camera;
|
2016-12-29 14:06:25 +01:00
|
|
|
|
2017-02-02 18:01:08 +01:00
|
|
|
SettingsWindow* m_settings;
|
2017-01-21 15:22:43 +01:00
|
|
|
|
2017-01-28 16:54:36 +01:00
|
|
|
// functions
|
|
|
|
private:
|
2017-02-08 14:29:22 +01:00
|
|
|
void setDefaultValues();
|
2017-01-28 16:54:36 +01:00
|
|
|
void initShaders();
|
|
|
|
void resetView();
|
|
|
|
void updateLightPosition();
|
|
|
|
|
2016-12-24 16:03:37 +01:00
|
|
|
protected:
|
2017-01-28 16:54:36 +01:00
|
|
|
void initializeGL() Q_DECL_OVERRIDE;
|
|
|
|
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
|
|
|
|
void paintGL() Q_DECL_OVERRIDE;
|
|
|
|
|
2016-12-24 16:03:37 +01:00
|
|
|
void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
2016-12-27 14:05:39 +01:00
|
|
|
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
2016-12-30 13:28:07 +01:00
|
|
|
void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
|
2017-01-28 16:54:36 +01:00
|
|
|
|
2016-12-27 14:05:39 +01:00
|
|
|
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
|
2017-02-05 12:34:24 +01:00
|
|
|
void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
|
2016-12-24 16:03:37 +01:00
|
|
|
|
2017-01-28 16:54:36 +01:00
|
|
|
void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
|
|
|
|
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
|
2017-01-05 16:04:51 +01:00
|
|
|
|
2017-01-28 16:54:36 +01:00
|
|
|
// slots
|
2017-01-05 16:04:51 +01:00
|
|
|
public slots:
|
2017-01-30 11:31:37 +01:00
|
|
|
void loadFile(QString name);
|
2017-02-02 18:01:08 +01:00
|
|
|
void useFreeCamera();
|
|
|
|
void useOrbitCamera();
|
|
|
|
void useMoveCamera();
|
2017-01-16 14:24:30 +01:00
|
|
|
void toggleWireframe();
|
2017-01-18 17:01:43 +01:00
|
|
|
void toggleLight();
|
2017-01-23 16:09:06 +01:00
|
|
|
void showSettings();
|
2017-02-02 18:01:08 +01:00
|
|
|
|
2017-01-24 17:09:51 +01:00
|
|
|
void setBGColorOff(QVector3D value);
|
|
|
|
void setBGColorOn(QVector3D value);
|
|
|
|
void setLightColor(QVector3D value);
|
|
|
|
void setAttFac(double value);
|
|
|
|
void setAmbCoef(double value);
|
2017-01-30 11:31:37 +01:00
|
|
|
void setHeadlight(bool value);
|
2017-01-29 23:47:14 +01:00
|
|
|
void setBackfaceCulling(bool value);
|
2017-01-21 15:22:43 +01:00
|
|
|
|
2017-02-08 14:29:22 +01:00
|
|
|
// signals
|
|
|
|
signals:
|
|
|
|
void lightChanged(bool value);
|
|
|
|
|
|
|
|
|
2016-12-24 16:03:37 +01:00
|
|
|
};
|
|
|
|
|