OglViewerWidget.h 2.08 KB
Newer Older
1
2
3
4
#pragma once
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
5
6
7
#include <QMatrix4x4>
#include "GeometryEngine.h"
#include "SettingsWindow.h"
Anakin's avatar
Anakin committed
8

9
10
11
12
13
14
15
16
17
18
19

class GeometryEngine;

class OglViewerWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
	Q_OBJECT

public:
	explicit OglViewerWidget(QWidget *parent = 0);
	~OglViewerWidget();

20
// attributes
Anakin's avatar
Anakin committed
21
private:
22
23
	QOpenGLShaderProgram m_program;
	GeometryEngine *m_dataEngine;
Anakin's avatar
Anakin committed
24

25
26
27
28
29
	QVector4D m_backgroundColorOn = { 0.02f, 0.02f, 0.02f, 1.0f };
	QVector4D m_backgroundColorOff = { 0.5f, 0.8f, 1.0f, 1.0f };

	bool m_wireframe = false;
	bool m_lightOn = false;
Anakin's avatar
Anakin committed
30

Anakin's avatar
Anakin committed
31
	struct {
Anakin's avatar
Anakin committed
32
		QVector4D position = { 1,1,1,0 };
Anakin's avatar
Anakin committed
33
		QVector3D intensities = { 1.0,1.0,1.0 };
Anakin's avatar
Anakin committed
34
		float attenuationFactor = 0.0f;
Anakin's avatar
Anakin committed
35
		float ambientCoefficient = 0.005f;
Anakin's avatar
Anakin committed
36
37
	} m_light;

Anakin's avatar
Anakin committed
38
39
	SettingsWindow* m_settings;

40
41
42
43
44
	struct {
		bool left = false;
		bool right = false;
		QVector2D position;
	} m_mouse;
45

46
47
48
49
50
	struct {
		bool x = true;
		bool y = true;
		bool z = true;
	} m_rotDirections;
Anakin's avatar
Anakin committed
51
52

	QMatrix4x4 m_projection;
Anakin's avatar
Anakin committed
53
	QVector3D m_translation;
Anakin's avatar
Anakin committed
54
55
	QQuaternion m_rotation;

Anakin's avatar
Anakin committed
56
57
	double m_zSpeed = 1.0;

58
59
60
61
62
63
64
// functions
private:
	void initShaders();
	void setConnections();
	void resetView();
	void updateLightPosition();

65
protected:
66
67
68
69
	void initializeGL() Q_DECL_OVERRIDE;
	void resizeGL(int w, int h) Q_DECL_OVERRIDE;
	void paintGL() Q_DECL_OVERRIDE;

70
71
	void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
	void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
72
	void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
Anakin's avatar
Anakin committed
73
	void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
74
	
75
	void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
76

77
78
	void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
	void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
Anakin's avatar
Anakin committed
79

80
// slots
Anakin's avatar
Anakin committed
81
public slots:
82
	void toggleAxis(int axis);
Anakin's avatar
Anakin committed
83
	void toggleWireframe();
Anakin's avatar
Anakin committed
84
	void toggleLight();
Anakin's avatar
Anakin committed
85
	void showSettings();
86
87
88
89
90
	void setBGColorOff(QVector3D value);
	void setBGColorOn(QVector3D value);
	void setLightColor(QVector3D value);
	void setAttFac(double value);
	void setAmbCoef(double value);
Anakin's avatar
Anakin committed
91

92
// signals
Anakin's avatar
Anakin committed
93
94
signals:
	void sendMessage(QString message, int severity);
95
	void loadFile(QString);
96
97
};