QT5:3D
在QT上绘制3D总共有三种方法:
用QT 3D模块进行支持3D
引用OpenGL库来支持3D
引用VTK OSG等库来支持3D
一.QT 3D
1.头文件模块支持
//QT 3D C++ aplication: qmake .pro file这个配置文件中添加 QT += 3dcore 3drender 3dinput 3dlogic 3dextras 3danimation Qt Quick applicaton: QT += 3dcore 3drender 3dinput 3dlogic 3dextras qml quick 3dquick 3danimation 在引用头文件中包含 #include <Qt3DCore> #include <Qt3DRender> #include <Qt3DInput> #include <Qt3DLogic> #include <Qt3DExtras> #include <Qt3DAnimation>
#include <Qt3DExtras> #include <Qt3DCore> int main(int argc, char* argv) { QGuiApplication a(argc, argv); QUrl data = QUrl::fromLocalFile("1.stl"); Qt3DExtras::Qt3DWindow view; Qt3DCore::QEntity* rootEntity = new Qt3DCore::QEntity; Qt3DCore::QEntity* flyingwedge = new Qt3DCore::QEntity; Qt3DExtras::QPhongMaterial* material = new Qt3DExtras::QPhongMaterial(); material->setDiffuse(QColor(254, 254, 254)); Qt3DRender::QMesh* flyingwedgeMesh = new Qt3DRender::QMesh; flyingwedgeMesh->setMeshName("FlyingWedge"); flyingwedgeMesh->setSource(data); flyingwedge->addComponent(flyingwedgeMesh); flyingwedge->addComponent(material); Qt3DRender::QCamera* camera = view.camera(); camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); camera->setPosition(QVector3D(0, 0, 40.0f)); camera->setUpVector(QVector3D(0, 1, 0)); camera->setViewCenter(QVector3D(0, 0, 0)); Qt3DCore::QEntity* lightEntity = new Qt3DCore::QEntity(rootEntity); Qt3DRender::QPointLight* light = new Qt3DRender::QPointLight(lightEntity); light->setColor("white"); light->setIntensity(0.8f); light->addComponent(light); Qt3DCore::QTransform* lightTransform = new Qt3DCore::QTransform(lightEntity); lightTransform->setTranslation(camera->position()); lightEntity->addComponent(lightTransform); Qt3DExtras::QOrbitCameraController* camController = new Qt3DExtras::QOrbitCameraController(rootEntity); camController->setLinearSpeed(50.0f); camController->setLookSpeed(180.0f); camController->setCamera(camera); view.setRootEntity(rootEntity); view.show(); return a.exec(); }
二.QT OpenGL
1.头文件模块支持
//QT OpenGL #include <QtOpenGL> QT += opengl
Qt中提供了QtOpenGL模块来显示3D图形 Qt提供了QGLWidget类来渲染OpenGL图形 继承的虚函数: 1.initializeGL():设置OpenGL渲染环境,定义显示列表等,该函数只在第一次调用resizeGL()或paintGL()前调用一次 2.resizeGL():设置OpenGL的视口、投影等,每次部件改变大小时都会调用该函数 3.paintGL():渲染OpenGL场景,每当部件需要更新时都会调用该函数
三.QT VTK
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)