OglViewerWidget.h 2.06 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
#include "CameraInterface.h"
Anakin's avatar
Anakin committed
9

10
11
12
13
14
15
16
17
18
19
20

class GeometryEngine;

class OglViewerWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
	Q_OBJECT

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

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

26
27
28
29
30
	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
31
	bool m_backfaceCulling = false;
Anakin's avatar
Anakin committed
32

Anakin's avatar
Anakin committed
33
	struct {
Anakin's avatar
Anakin committed
34
		QVector4D position = { 1,1,1,0 };
Anakin's avatar
Anakin committed
35
		QVector3D intensities = { 1.0,1.0,1.0 };
Anakin's avatar
Anakin committed
36
		float attenuationFactor = 0.0f;
Anakin's avatar
Anakin committed
37
		float ambientCoefficient = 0.005f;
Anakin's avatar
Anakin committed
38
		bool headlight = false;
Anakin's avatar
Anakin committed
39
40
	} m_light;

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

Anakin's avatar
Anakin committed
47
	QMatrix4x4 m_projection;
Anakin's avatar
Anakin committed
48
	CameraInterface* m_camera;
Anakin's avatar
Anakin committed
49

Anakin's avatar
Anakin committed
50
	SettingsWindow* m_settings;
Anakin's avatar
Anakin committed
51

52
53
54
55
56
57
// functions
private:
	void initShaders();
	void resetView();
	void updateLightPosition();

58
protected:
59
60
61
62
	void initializeGL() Q_DECL_OVERRIDE;
	void resizeGL(int w, int h) Q_DECL_OVERRIDE;
	void paintGL() Q_DECL_OVERRIDE;

63
64
	void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
	void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
65
	void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
Anakin's avatar
Anakin committed
66
	void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
67
	
68
	void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
69

70
71
	void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
	void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
Anakin's avatar
Anakin committed
72

73
// slots
Anakin's avatar
Anakin committed
74
public slots:
Anakin's avatar
Anakin committed
75
	void loadFile(QString name);
Anakin's avatar
Anakin committed
76
77
78
	void useFreeCamera();
	void useOrbitCamera();
	void useMoveCamera();
Anakin's avatar
Anakin committed
79
	void toggleWireframe();
Anakin's avatar
Anakin committed
80
	void toggleLight();
Anakin's avatar
Anakin committed
81
	void showSettings();
Anakin's avatar
Anakin committed
82

83
84
85
86
87
	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
88
	void setHeadlight(bool value);
Anakin's avatar
Anakin committed
89
	void setBackfaceCulling(bool value);
Anakin's avatar
Anakin committed
90

91
92
};