zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    游标cursor
    SQL: EXISTS
    LeetCode Reverse Integer
    LeetCode Same Tree
    LeetCode Maximum Depth of Binary Tree
    LeetCode 3Sum Closest
    LeetCode Linked List Cycle
    LeetCode Best Time to Buy and Sell Stock II
    LeetCode Balanced Binary Tree
    LeetCode Validate Binary Search Tree
  • 原文地址:https://www.cnblogs.com/k5bg/p/15601477.html
Copyright © 2011-2022 走看看