Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt3D & QSlider
Qt 6.11 is out! See what's new in the release blog

Qt3D & QSlider

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 4 Posters 1.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Silenzio76
    wrote on last edited by
    #1

    Greetings,

    I wrote this piece of code to render my Obj file:

    Qt3DCore::QEntity * add3dElements(Qt3DExtras::Qt3DWindow *view){
        Qt3DCore::QEntity *eRoot = new Qt3DCore::QEntity;
    
        Qt3DRender::QCamera *cCam = view->camera();
        /*cCam->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
        cCam->setPosition(QVector3D(0, 0, 8.0f));
        cCam->setUpVector(QVector3D(0, 1, 0));
        cCam->setViewCenter(QVector3D(0, 0, 0));*/
        cCam->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
        cCam->setProjectionType(Qt3DRender::QCameraLens::PerspectiveProjection);
        cCam->setAspectRatio(view->width() / view->height());
        cCam->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
        //cCam->setViewCenter(QVector3D(0.04f, 1.0f, 0.0f));
        cCam->setViewCenter(QVector3D(0, 0, 0));
        //cCam->setPosition(QVector3D(0.0f, 2.5f, 2.1f));
        cCam->setPosition(QVector3D(0, 0, 8.0f));
        cCam->setNearPlane(0.001f);
        cCam->setFarPlane(100.0f);
    
        Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController();
        camController->setCamera(cCam);
    
    
        Qt3DCore::QEntity *eLight = new Qt3DCore::QEntity(eRoot);
    
        Qt3DRender::QPointLight *plPoint = new Qt3DRender::QPointLight(eLight);
        plPoint->setColor("silver");
        plPoint->setIntensity(2);
        eLight->addComponent(plPoint);
    
        Qt3DCore::QTransform *tLightMng = new Qt3DCore::QTransform(eLight);
        tLightMng->setTranslation(cCam->position());
        eLight->addComponent(tLightMng);
    
        Qt3DCore::QEntity *eModel = new Qt3DCore::QEntity(eRoot);
        Qt3DRender::QMesh *mModel = new Qt3DRender::QMesh();
        mModel->setSource(QUrl("qrc:/truck"));
    
        Qt3DExtras::QPhongMaterial *pmModel = new Qt3DExtras::QPhongMaterial();
        pmModel->setDiffuse(QColor(Qt::lightGray));
    
    
    
        Qt3DCore::QTransform *tModelMng = new Qt3DCore::QTransform();
        tModelMng->setScale(0.45f);
        tModelMng->setRotation(QQuaternion::fromEulerAngles(0.0, 0.0, 0.0));
    
        eModel->addComponent(mModel);
        eModel->addComponent(tModelMng);
        eModel->addComponent(pmModel);
    
    
        view->setRootEntity(eRoot);
        return eRoot;
    };
    

    It's possible link c++ via 3 QSlider to the QCamera or the QTransform component to manage Pitch, Yaw and Zoom?
    Did code's samples exist to do that?

    Thank you in advance

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      This example shows how to use QCheckBoxes but you'll get the idea on how to mix controls and a Qt3D scene.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Silenzio76
        wrote on last edited by Silenzio76
        #3

        the problem is to link the "tModelMng->setRotation(QQuaternion::fromEulerAngles(0.0, 0.0, 0.0));"

        to the QSlider/QDial to set the rotation and zoom, like Qt 3D: Scene2D QML Example, but in c++ code, not to retrieve the "Enabled" property.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Don't link them directly, link your sliders to a slot where you call tModelMng->setRotation(QQuaternion::fromEulerAngles(pitchSlider->value(), yawSlider->value(), rollSlider->value()));.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • S Offline
            S Offline
            Silenzio76
            wrote on last edited by Silenzio76
            #5

            Already tryed, not works!
            How can retrieve the QTransform Obj?
            I had tryed iteration, dynamic casting, but nothing seems to work

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you provide a minimal compilable example that shows what you are trying to achieve ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              0
              • SGaistS SGaist

                Can you provide a minimal compilable example that shows what you are trying to achieve ?

                S Offline
                S Offline
                Silenzio76
                wrote on last edited by Silenzio76
                #7

                @SGaist to the function above add:

                int main(int argc, char **argv)
                {
                    QApplication app(argc, argv);
                    //keypad global management
                    
                
                    QWidget *widget = new QWidget;
                     QVBoxLayout *vSceneLayout = new QVBoxLayout();
                    QWidget *wSpacer = new QWidget();
                   wSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
                    QLabel *lbPitch = new QLabel("Pitch rot.");
                    QDial *dPicth = new QDial();
                    dPicth->setMaximum(36000);
                    dPicth->setValue(0);
                    QLabel *lbYaw = new QLabel("Yaw rot.");
                    QDial *dYaw = new QDial();
                    dYaw->setMaximum(36000);
                    dYaw->setValue(0);
                    QLabel *lbZoom = new QLabel("Zoom");
                    QSlider *sZoom = new QSlider(Qt::Horizontal);
                    sZoom->setTickInterval(10);
                    sZoom->setValue(45);
                    sZoom->setMinimum(0);
                    sZoom->setMaximum(10000);
                    setSliderStyle(sZoom);
                    QHBoxLayout *hlCmd = new QHBoxLayout();
                    hlCmd->addWidget(wSpacer);
                    hlCmd->addWidget(lbPitch);
                    hlCmd->addWidget(dPicth);
                    hlCmd->addWidget(lbYaw);
                    hlCmd->addWidget(dYaw);
                    hlCmd->addWidget(lbZoom);
                    hlCmd->addWidget(sZoom);
                
                    Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
                    view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
                    Qt3DCore::QEntity *scene = add3dElements(view);
                
                Qt3DCore::QTransform *meshTrans = new Qt3DCore::QTransform(scene);
                    QObject::connect(dPitch, &QDial::valueChanged, [=] (float) {
                        meshTrans->setRotationX(dPitch->value()/100);
                        scene->addComponent(meshTrans);
                    });
                
                    QObject::connect(dYaw, &QDial::valueChanged, [=] (float) {
                        meshTrans->setRotationY(dYaw->value()/100);
                        scene->addComponent(meshTrans);
                    });
                       
                    view->setRootEntity(scene);
                    QWidget *container = QWidget::createWindowContainer(view);
                
                    vSceneLayout->addWidget(container, 1);
                    vSceneLayout->addLayout(hlCmd);
                    hLayout->addLayout(vSceneLayout, 1);
                
                    widget->setWindowState(Qt::WindowMaximized);
                    widget->setGeometry(QGuiApplication::screens().at(0)->availableGeometry());
                
                    widget->show();
                
                
                
                
                    return app.exec();
                }
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Can you also share the obj file you load ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Silenzio76
                    wrote on last edited by
                    #9

                    You can get any object around
                    https://www.turbosquid.com/Search/3D-Models/free/obj

                    I'm working on the zoom slider not on the model

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Would it be possible to have complete working minimal buildable sample code ?
                      The two put together don't build out of the box and I'm currently getting only a grey zone.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      S 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Would it be possible to have complete working minimal buildable sample code ?
                        The two put together don't build out of the box and I'm currently getting only a grey zone.

                        S Offline
                        S Offline
                        Silenzio76
                        wrote on last edited by Silenzio76
                        #11

                        @SGaist
                        play/change this line to a value lesser of 1(ex.0.45f)

                         Qt3DCore::QTransform *tModelMng = new Qt3DCore::QTransform();
                        **==>> tModelMng->setScale(0.45f);**
                         tModelMng->setRotation(QQuaternion::fromEulerAngles(45.0f,30.0f, 0.0f));
                        

                        [0_1559129464565_build-CargoAssistant-Desktop_Qt_5_12_0_MinGW_64_bit-Debug.7z.001](Uploading 100%) [0_1559129533552_build-CargoAssistant-Desktop_Qt_5_12_0_MinGW_64_bit-Debug.7z.002](Uploading 100%)

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          I meant just the code so I can build it here.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          S 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            I meant just the code so I can build it here.

                            S Offline
                            S Offline
                            Silenzio76
                            wrote on last edited by Silenzio76
                            #13

                            @SGaist [0_1559220017289_CargoAssistant.7z](Uploading 100%)
                            the system not permits me to upload !
                            tryed today and yesterday(not enough priviledge)!

                            A 1 Reply Last reply
                            0
                            • S Silenzio76

                              @SGaist [0_1559220017289_CargoAssistant.7z](Uploading 100%)
                              the system not permits me to upload !
                              tryed today and yesterday(not enough priviledge)!

                              A Offline
                              A Offline
                              arsinte_andrei
                              wrote on last edited by
                              #14

                              @Silenzio76 have you ever hear of git? try it.. is for your own good

                              S 1 Reply Last reply
                              1
                              • A arsinte_andrei

                                @Silenzio76 have you ever hear of git? try it.. is for your own good

                                S Offline
                                S Offline
                                Silenzio76
                                wrote on last edited by
                                #15

                                @arsinte_andrei never used mais voilĂ  https://github.com/silenzio76/cargo

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  Silenzio76
                                  wrote on last edited by
                                  #16

                                  can noone help me?

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • S Silenzio76

                                    can noone help me?

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @Silenzio76 You still did not upload code as @SGaist asked you.
                                    You should not try to upload it here as it does not work.
                                    Upload it to some file sharing service and put the link here.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      arsinte_andrei
                                      wrote on last edited by
                                      #18

                                      @Silenzio76 said in Qt3D & QSlider:

                                      https://github.com/silenzio76/cargo

                                      this is where hi post the code
                                      in the github

                                      1 Reply Last reply
                                      0

                                      • Login

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved