OglViewerWidget.h 1.9 KB
Newer Older
1 2 3
#pragma once

#include "geometryengine.h"
Anakin's avatar
Anakin committed
4
#include "..\Header\SettingsWindow.h"
5 6 7 8 9 10 11
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QVector2D>
#include <QBasicTimer>
#include <QOpenGLShaderProgram>
Anakin's avatar
Anakin committed
12

13 14 15 16 17 18 19 20 21 22 23

class GeometryEngine;

class OglViewerWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
	Q_OBJECT

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

Anakin's avatar
Anakin committed
24
signals:
Anakin's avatar
Anakin committed
25
	void loadFile(QString);
Anakin's avatar
Anakin committed
26

Anakin's avatar
Anakin committed
27 28 29 30 31 32 33
private:
	struct {
		bool left = false;
		bool right = false;
		QVector2D position;
	} m_mouse;

Anakin's avatar
Anakin committed
34 35 36 37 38 39
	struct {
		bool x = true;
		bool y = true;
		bool z = true;
	} m_rotDirections;

Anakin's avatar
Anakin committed
40
	struct {
Anakin's avatar
Anakin committed
41
		QVector4D position = { 1,1,1,0 };
Anakin's avatar
Anakin committed
42
		QVector3D intensities = { 1.0,1.0,1.0 };
Anakin's avatar
Anakin committed
43
		float attenuationFactor = 0.0f;
Anakin's avatar
Anakin committed
44
		float ambientCoefficient = 0.005f;
Anakin's avatar
Anakin committed
45 46
	} m_light;

Anakin's avatar
Anakin committed
47 48
	SettingsWindow* m_settings;

49 50
	QVector4D m_backgroundColor = {0.5f, 0.8f, 1.0f, 1.0f};

Anakin's avatar
Anakin committed
51 52 53 54
	QOpenGLShaderProgram m_program;
	GeometryEngine *m_dataEngine;

	QMatrix4x4 m_projection;
Anakin's avatar
Anakin committed
55
	QVector3D m_translation;
Anakin's avatar
Anakin committed
56 57
	QQuaternion m_rotation;

Anakin's avatar
Anakin committed
58
	bool m_wireframe = false;
Anakin's avatar
Anakin committed
59
	bool m_lightOn = false;
Anakin's avatar
Anakin committed
60

Anakin's avatar
Anakin committed
61 62
	double m_zSpeed = 1.0;

63 64 65
protected:
	void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
	void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
66
	void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
Anakin's avatar
Anakin committed
67
	void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
Anakin's avatar
Anakin committed
68
	void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
Anakin's avatar
Anakin committed
69
	void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
70
	void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
71 72 73 74 75

	void initializeGL() Q_DECL_OVERRIDE;
	void resizeGL(int w, int h) Q_DECL_OVERRIDE;
	void paintGL() Q_DECL_OVERRIDE;

Anakin's avatar
Anakin committed
76
private:
77
	void initShaders();
78
	void setConnections();
Anakin's avatar
Anakin committed
79
	void updateLightPosition();
80

Anakin's avatar
Anakin committed
81 82
private slots:
	void resetView();
Anakin's avatar
Anakin committed
83 84 85

public slots:
	void changeDirection(int direction);
Anakin's avatar
Anakin committed
86
	void toggleWireframe();
Anakin's avatar
Anakin committed
87
	void toggleLight();
Anakin's avatar
Anakin committed
88
	void showSettings();
Anakin's avatar
Anakin committed
89 90 91

signals:
	void sendMessage(QString message, int severity);
92 93
};