dust3d/application/sources/model_widget.h

133 lines
4.4 KiB
C
Raw Normal View History

#ifndef DUST3D_APPLICATION_MODEL_WIDGET_H_
#define DUST3D_APPLICATION_MODEL_WIDGET_H_
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QMatrix4x4>
#include <QMutex>
#include <QRubberBand>
2019-07-07 06:27:58 +00:00
#include <QVector2D>
#include <QTimer>
#include "model.h"
#include "model_shader_program.h"
#include "model_mesh_binder.h"
2018-03-20 07:56:49 +00:00
class ModelWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
2019-08-08 11:24:33 +00:00
signals:
void mouseRayChanged(const QVector3D &near, const QVector3D &far);
void mousePressed();
void mouseReleased();
void addMouseRadius(float radius);
void renderParametersChanged();
void xRotationChanged(int angle);
void yRotationChanged(int angle);
void zRotationChanged(int angle);
void eyePositionChanged(const QVector3D &eyePosition);
void moveToPositionChanged(const QVector3D &moveToPosition);
public:
2018-03-20 07:56:49 +00:00
ModelWidget(QWidget *parent = 0);
~ModelWidget();
static bool isTransparent()
{
return m_transparent;
}
static void setTransparent(bool t)
{
m_transparent = t;
}
Model *fetchCurrentMesh();
void updateMesh(Model *mesh);
2020-11-17 14:31:51 +00:00
void updateColorTexture(QImage *colorTextureImage);
void toggleWireframe();
bool isWireframeVisible();
void toggleRotation();
2019-08-09 22:27:26 +00:00
void toggleUvCheck();
void enableEnvironmentLight();
bool isEnvironmentLightEnabled();
void enableMove(bool enabled);
void enableZoom(bool enabled);
2019-08-08 11:24:33 +00:00
void enableMousePicking(bool enabled);
void setMoveAndZoomByWindow(bool byWindow);
void disableCullFace();
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);
void fetchCurrentToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap);
void updateToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap);
int widthInPixels();
int heightInPixels();
void setNotGraphics(bool notGraphics);
int xRot();
int yRot();
int zRot();
const QVector3D &eyePosition();
const QVector3D &moveToPosition();
public slots:
void setXRotation(int angle);
void setYRotation(int angle);
void setZRotation(int angle);
void setEyePosition(const QVector3D &eyePosition);
void cleanup();
void zoom(float delta);
2019-08-08 11:24:33 +00:00
void setMousePickTargetPositionInModelSpace(QVector3D position);
void setMousePickRadius(float radius);
2020-03-29 10:06:45 +00:00
void reRender();
void canvasResized();
protected:
void initializeGL() override;
void paintGL() override;
void resizeGL(int width, int height) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
int m_xRot = m_defaultXRotation;
int m_yRot = m_defaultYRotation;
int m_zRot = m_defaultZRotation;
ModelShaderProgram *m_program = nullptr;
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;
QPoint m_lastPos;
ModelMeshBinder m_meshBinder;
QMatrix4x4 m_projection;
QMatrix4x4 m_camera;
QMatrix4x4 m_world;
float m_mousePickRadius = 0.0;
2020-04-13 13:25:04 +00:00
QVector3D m_eyePosition = m_defaultEyePosition;
static bool m_transparent;
static float m_minZoomRatio;
static float m_maxZoomRatio;
QPoint m_moveStartPos;
QRect m_moveStartGeometry;
int m_modelInitialHeight = 0;
QTimer *m_rotationTimer = nullptr;
int m_widthInPixels = 0;
int m_heightInPixels = 0;
QVector3D m_moveToPosition;
bool m_moveAndZoomByWindow = true;
bool m_enableCullFace = true;
bool m_notGraphics = false;
2019-08-08 11:24:33 +00:00
std::pair<QVector3D, QVector3D> screenPositionToMouseRay(const QPoint &screenPosition);
private:
void updateProjectionMatrix();
void normalizeAngle(int &angle);
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;
};
#endif