OglViewerWidget.h 2.15 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
	bool m_backfaceCulling = false;
Anakin's avatar
Anakin committed
31

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

Anakin's avatar
Anakin committed
40 41
	SettingsWindow* m_settings;

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

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

	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 59
	double m_zSpeed = 1.0;

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

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

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

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

81
// slots
Anakin's avatar
Anakin committed
82
public slots:
Anakin's avatar
Anakin committed
83
	void loadFile(QString name);
84
	void toggleAxis(int axis);
Anakin's avatar
Anakin committed
85
	void toggleWireframe();
Anakin's avatar
Anakin committed
86
	void toggleLight();
Anakin's avatar
Anakin committed
87
	void showSettings();
88 89 90 91 92
	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
93
	void setHeadlight(bool value);
Anakin's avatar
Anakin committed
94 95
	void setBackfaceCulling(bool value);
	void setZoomSpeed(int percent);
Anakin's avatar
Anakin committed
96

97 98
};