初步实现2轴的3D模型联动
This commit is contained in:
74
HPPA/View3D.h
Normal file
74
HPPA/View3D.h
Normal file
@ -0,0 +1,74 @@
|
||||
#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>
|
||||
|
||||
class View3D : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit View3D(const QString& baseModelPath,
|
||||
const QString& armModelPath,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
private:
|
||||
void initScene();
|
||||
void initCamera();
|
||||
void updateCameraPosition();
|
||||
void createAxes();
|
||||
|
||||
private:
|
||||
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;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setLoc(std::vector<double> loc);
|
||||
};
|
||||
|
||||
#endif // VIEW3D_H
|
||||
Reference in New Issue
Block a user