OglViewerWidget.h 2.07 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 38
	} m_light;

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

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

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

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

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

59 60 61 62 63 64
// functions
private:
	void initShaders();
	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
	void setBackfaceCulling(bool value);
	void setZoomSpeed(int percent);
Anakin's avatar
Anakin committed
93

94 95
};