113 lines
2.5 KiB
C++
113 lines
2.5 KiB
C++
#ifndef VIEW3D_H
|
|
#define VIEW3D_H
|
|
|
|
#include <QWidget>
|
|
#include <QTimer>
|
|
#include <QPoint>
|
|
#include <QString>
|
|
#include <QQuaternion>
|
|
#include <QColor>
|
|
|
|
#include <Qt3DCore/QEntity>
|
|
#include <Qt3DCore/QTransform>
|
|
#include <Qt3DExtras/Qt3DWindow>
|
|
#include <Qt3DRender/QCamera>
|
|
#include <Qt3DExtras/QOrbitCameraController>
|
|
#include <Qt3DExtras/QPhongMaterial>
|
|
#include <Qt3DRender/QSceneLoader>
|
|
#include <Qt3DExtras/QCylinderMesh>
|
|
#include <QPointLight>
|
|
|
|
class View3DBase : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit View3DBase(const QString& baseModelPath,
|
|
const QString& armModelPath,
|
|
QWidget* parent = nullptr);
|
|
void setViewCenter(float x, float y, float z);
|
|
void setDistance(float distance);
|
|
|
|
protected:
|
|
void showEvent(QShowEvent* event) override;
|
|
bool eventFilter(QObject* obj, QEvent* event) override;
|
|
|
|
void initScene();
|
|
void initCamera();
|
|
void updateCameraPosition();
|
|
void createAxes();
|
|
|
|
QString m_baseModelPath;
|
|
QString m_armModelPath;
|
|
|
|
Qt3DExtras::Qt3DWindow* m_view;
|
|
QWidget* m_container;
|
|
Qt3DCore::QEntity* m_rootEntity;
|
|
|
|
Qt3DCore::QEntity* m_baseEntity;
|
|
Qt3DCore::QEntity* m_armEntity;
|
|
Qt3DCore::QTransform* m_armTransform;
|
|
Qt3DCore::QTransform* m_baseTransform;
|
|
|
|
QTimer m_timer;
|
|
float m_angle = 0; // arm auto rotation
|
|
float m_t = 0;
|
|
|
|
// ----- Camera control -----
|
|
Qt3DRender::QCamera* m_camera = nullptr;
|
|
float m_distance = 5000.0f;
|
|
float m_yawDeg = 0.0f;
|
|
float m_pitchDeg = 0.0f;
|
|
QVector3D m_viewCenter = QVector3D(1000, 1000, -1000);
|
|
|
|
// Mouse state
|
|
bool m_mouseDragging = false; // left button: orbit
|
|
bool m_middleDragging = false; // middle button: pan
|
|
QPoint m_lastMousePos;
|
|
|
|
Qt3DCore::QTransform* m_baseRootTransform = nullptr;
|
|
Qt3DCore::QTransform* m_armRootTransform = nullptr;
|
|
|
|
void applyWhiteMaterialRecursive(Qt3DCore::QEntity* entity);
|
|
|
|
public Q_SLOTS:
|
|
virtual void setLoc(std::vector<double> loc) = 0;
|
|
};
|
|
|
|
class View3DPlantPhenotype : public View3DBase
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
View3DPlantPhenotype(const QString& baseModelPath,
|
|
const QString& armModelPath,
|
|
QWidget* parent = nullptr);
|
|
|
|
protected:
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
public Q_SLOTS:
|
|
void setLoc(std::vector<double> loc);
|
|
};
|
|
|
|
class View3DLinearStage : public View3DBase
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
View3DLinearStage(const QString& baseModelPath,
|
|
const QString& armModelPath,
|
|
QWidget* parent = nullptr);
|
|
|
|
protected:
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
public Q_SLOTS:
|
|
void setLoc(std::vector<double> loc);
|
|
};
|
|
#endif // VIEW3D_H
|