SWBF2-Classic-Msh-Viewer/QtMeshViewer/Header/OglViewerWidget.h

99 lines
2.2 KiB
C++

#pragma once
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QMatrix4x4>
#include "GeometryEngine.h"
#include "SettingsWindow.h"
class GeometryEngine;
class OglViewerWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
explicit OglViewerWidget(QWidget *parent = 0);
~OglViewerWidget();
// attributes
private:
QOpenGLShaderProgram m_program;
GeometryEngine *m_dataEngine;
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;
bool m_backfaceCulling = false;
struct {
QVector4D position = { 1,1,1,0 };
QVector3D intensities = { 1.0,1.0,1.0 };
float attenuationFactor = 0.0f;
float ambientCoefficient = 0.005f;
bool headlight = false;
} m_light;
SettingsWindow* m_settings;
struct {
bool left = false;
bool right = false;
QVector2D position;
} m_mouse;
struct {
bool x = true;
bool y = true;
bool z = true;
} m_rotDirections;
QMatrix4x4 m_projection;
QVector3D m_translation;
QQuaternion m_rotation;
double m_zSpeed = 1.0;
// functions
private:
void initShaders();
void resetView();
void updateLightPosition();
protected:
void initializeGL() Q_DECL_OVERRIDE;
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
void paintGL() Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
// slots
public slots:
void loadFile(QString name);
void toggleAxis(int axis);
void toggleWireframe();
void toggleLight();
void showSettings();
void setBGColorOff(QVector3D value);
void setBGColorOn(QVector3D value);
void setLightColor(QVector3D value);
void setAttFac(double value);
void setAmbCoef(double value);
void setHeadlight(bool value);
void setBackfaceCulling(bool value);
void setZoomSpeed(int percent);
};