2021-11-18 14:58:01 +00:00
|
|
|
#ifndef DUST3D_APPLICATION_MODEL_WIDGET_H_
|
|
|
|
#define DUST3D_APPLICATION_MODEL_WIDGET_H_
|
|
|
|
|
2022-09-23 15:54:49 +00:00
|
|
|
#include "model_mesh.h"
|
2022-09-19 13:30:03 +00:00
|
|
|
#include "model_opengl_object.h"
|
2022-10-18 09:35:04 +00:00
|
|
|
#include "model_opengl_program.h"
|
2022-09-23 15:54:49 +00:00
|
|
|
#include "monochrome_mesh.h"
|
|
|
|
#include "monochrome_opengl_object.h"
|
2022-10-18 09:35:04 +00:00
|
|
|
#include "monochrome_opengl_program.h"
|
|
|
|
#include <QMatrix4x4>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QOpenGLBuffer>
|
|
|
|
#include <QOpenGLTexture>
|
|
|
|
#include <QOpenGLWidget>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QVector2D>
|
|
|
|
#include <memory>
|
2018-03-30 07:41:29 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
class ModelWidget : public QOpenGLWidget {
|
2018-03-10 06:57:14 +00:00
|
|
|
Q_OBJECT
|
2019-08-08 11:24:33 +00:00
|
|
|
signals:
|
2022-10-18 09:35:04 +00:00
|
|
|
void mouseRayChanged(const QVector3D& near, const QVector3D& far);
|
2019-08-17 10:13:11 +00:00
|
|
|
void mousePressed();
|
|
|
|
void mouseReleased();
|
|
|
|
void addMouseRadius(float radius);
|
2020-04-02 10:39:57 +00:00
|
|
|
void renderParametersChanged();
|
2020-04-15 14:05:04 +00:00
|
|
|
void xRotationChanged(int angle);
|
|
|
|
void yRotationChanged(int angle);
|
|
|
|
void zRotationChanged(int angle);
|
2022-10-18 09:35:04 +00:00
|
|
|
void eyePositionChanged(const QVector3D& eyePosition);
|
|
|
|
void moveToPositionChanged(const QVector3D& moveToPosition);
|
|
|
|
|
2018-03-10 06:57:14 +00:00
|
|
|
public:
|
2022-10-18 09:35:04 +00:00
|
|
|
ModelWidget(QWidget* parent = 0);
|
2018-03-20 07:56:49 +00:00
|
|
|
~ModelWidget();
|
2022-10-18 09:35:04 +00:00
|
|
|
void updateMesh(ModelMesh* mesh);
|
|
|
|
void updateWireframeMesh(MonochromeMesh* mesh);
|
2018-04-15 12:48:54 +00:00
|
|
|
void toggleWireframe();
|
2020-04-15 14:05:04 +00:00
|
|
|
bool isWireframeVisible();
|
2020-01-04 22:38:16 +00:00
|
|
|
void toggleRotation();
|
2018-09-18 06:22:29 +00:00
|
|
|
void enableMove(bool enabled);
|
|
|
|
void enableZoom(bool enabled);
|
2019-08-08 11:24:33 +00:00
|
|
|
void enableMousePicking(bool enabled);
|
2020-04-15 14:05:04 +00:00
|
|
|
void setMoveAndZoomByWindow(bool byWindow);
|
|
|
|
void disableCullFace();
|
2022-10-18 09:35:04 +00:00
|
|
|
void setMoveToPosition(const QVector3D& moveToPosition);
|
|
|
|
bool inputMousePressEventFromOtherWidget(QMouseEvent* event, bool notGraphics = false);
|
|
|
|
bool inputMouseMoveEventFromOtherWidget(QMouseEvent* event);
|
|
|
|
bool inputWheelEventFromOtherWidget(QWheelEvent* event);
|
|
|
|
bool inputMouseReleaseEventFromOtherWidget(QMouseEvent* event);
|
|
|
|
QPoint convertInputPosFromOtherWidget(QMouseEvent* event);
|
2020-04-02 10:39:57 +00:00
|
|
|
int widthInPixels();
|
|
|
|
int heightInPixels();
|
2020-11-09 10:46:06 +00:00
|
|
|
void setNotGraphics(bool notGraphics);
|
2021-11-18 14:58:01 +00:00
|
|
|
int xRot();
|
|
|
|
int yRot();
|
|
|
|
int zRot();
|
2022-10-18 09:35:04 +00:00
|
|
|
const QVector3D& eyePosition();
|
|
|
|
const QVector3D& moveToPosition();
|
|
|
|
const QString& openGLVersion();
|
2018-03-10 06:57:14 +00:00
|
|
|
public slots:
|
|
|
|
void setXRotation(int angle);
|
|
|
|
void setYRotation(int angle);
|
|
|
|
void setZRotation(int angle);
|
2022-10-18 09:35:04 +00:00
|
|
|
void setEyePosition(const QVector3D& eyePosition);
|
2018-03-10 06:57:14 +00:00
|
|
|
void cleanup();
|
2018-05-24 07:08:57 +00:00
|
|
|
void zoom(float delta);
|
2019-08-08 11:24:33 +00:00
|
|
|
void setMousePickTargetPositionInModelSpace(QVector3D position);
|
2019-08-17 10:13:11 +00:00
|
|
|
void setMousePickRadius(float radius);
|
2020-03-29 10:06:45 +00:00
|
|
|
void reRender();
|
2020-04-15 14:05:04 +00:00
|
|
|
void canvasResized();
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2018-03-10 06:57:14 +00:00
|
|
|
protected:
|
|
|
|
void initializeGL() override;
|
|
|
|
void paintGL() override;
|
|
|
|
void resizeGL(int width, int height) override;
|
2022-10-18 09:35:04 +00:00
|
|
|
void mousePressEvent(QMouseEvent* event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent* event) override;
|
|
|
|
void wheelEvent(QWheelEvent* event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
|
|
|
|
2018-03-10 06:57:14 +00:00
|
|
|
private:
|
2020-12-19 08:12:50 +00:00
|
|
|
int m_xRot = m_defaultXRotation;
|
|
|
|
int m_yRot = m_defaultYRotation;
|
|
|
|
int m_zRot = m_defaultZRotation;
|
2022-08-28 05:10:01 +00:00
|
|
|
int m_directionOnMoveStart = 0;
|
2022-09-23 15:54:49 +00:00
|
|
|
std::unique_ptr<ModelOpenGLProgram> m_modelOpenGLProgram;
|
|
|
|
std::unique_ptr<ModelOpenGLObject> m_modelOpenGLObject;
|
|
|
|
std::unique_ptr<MonochromeOpenGLProgram> m_monochromeOpenGLProgram;
|
|
|
|
std::unique_ptr<MonochromeOpenGLObject> m_wireframeOpenGLObject;
|
2020-12-19 08:12:50 +00:00
|
|
|
bool m_moveStarted = false;
|
|
|
|
bool m_moveEnabled = true;
|
|
|
|
bool m_zoomEnabled = true;
|
|
|
|
bool m_mousePickingEnabled = false;
|
2019-08-08 11:24:33 +00:00
|
|
|
QVector3D m_mousePickTargetPositionInModelSpace;
|
2018-03-10 06:57:14 +00:00
|
|
|
QPoint m_lastPos;
|
2018-10-05 07:37:01 +00:00
|
|
|
QMatrix4x4 m_projection;
|
2018-03-10 06:57:14 +00:00
|
|
|
QMatrix4x4 m_camera;
|
|
|
|
QMatrix4x4 m_world;
|
2019-08-17 10:13:11 +00:00
|
|
|
float m_mousePickRadius = 0.0;
|
2020-04-13 13:25:04 +00:00
|
|
|
QVector3D m_eyePosition = m_defaultEyePosition;
|
2019-08-20 22:59:50 +00:00
|
|
|
static float m_minZoomRatio;
|
|
|
|
static float m_maxZoomRatio;
|
2018-03-29 23:32:30 +00:00
|
|
|
QPoint m_moveStartPos;
|
|
|
|
QRect m_moveStartGeometry;
|
2019-08-20 22:59:50 +00:00
|
|
|
int m_modelInitialHeight = 0;
|
2022-10-18 09:35:04 +00:00
|
|
|
QTimer* m_rotationTimer = nullptr;
|
2020-04-02 10:39:57 +00:00
|
|
|
int m_widthInPixels = 0;
|
|
|
|
int m_heightInPixels = 0;
|
2020-04-15 14:05:04 +00:00
|
|
|
QVector3D m_moveToPosition;
|
|
|
|
bool m_moveAndZoomByWindow = true;
|
|
|
|
bool m_enableCullFace = true;
|
2020-11-09 10:46:06 +00:00
|
|
|
bool m_notGraphics = false;
|
2022-09-23 15:54:49 +00:00
|
|
|
bool m_isWireframeVisible = false;
|
2022-10-18 09:35:04 +00:00
|
|
|
std::pair<QVector3D, QVector3D> screenPositionToMouseRay(const QPoint& screenPosition);
|
2020-04-15 14:05:04 +00:00
|
|
|
void updateProjectionMatrix();
|
2022-10-18 09:35:04 +00:00
|
|
|
void normalizeAngle(int& angle);
|
2022-09-23 15:54:49 +00:00
|
|
|
void drawModel();
|
|
|
|
void drawWireframe();
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2020-03-25 11:40:44 +00:00
|
|
|
public:
|
|
|
|
static int m_defaultXRotation;
|
|
|
|
static int m_defaultYRotation;
|
|
|
|
static int m_defaultZRotation;
|
2020-04-13 13:25:04 +00:00
|
|
|
static QVector3D m_defaultEyePosition;
|
2022-09-20 12:48:22 +00:00
|
|
|
static QString m_openGLVersion;
|
|
|
|
static QString m_openGLShadingLanguageVersion;
|
|
|
|
static bool m_openGLIsCoreProfile;
|
2018-03-10 06:57:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|